Skip to content

Commit 9419b85

Browse files
authored
chore: remove job status: finished (#844)
* chore: remove job status: finished * chore: fix status ring test
1 parent 9c9108c commit 9419b85

File tree

4 files changed

+14
-20
lines changed

4 files changed

+14
-20
lines changed

job/job_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ func TestStatusRing(t *testing.T) {
2222
{Success: 3, Failed: 3},
2323
}
2424
var total int
25-
var expected = 2000 - (5 * 6 * 2)
25+
loops := 100
26+
var expected = (len(cases) * loops * 3) - (3 * 3 * len(cases))
2627

2728
eg, _ := errgroup.WithContext(context.TODO())
2829
eg.Go(func() error {
@@ -40,10 +41,8 @@ func TestStatusRing(t *testing.T) {
4041
td := cases[i]
4142
eg.Go(func() error {
4243
sr := newStatusRing(td, false, ch)
43-
for i := 0; i < 100; i++ {
44+
for i := 0; i < loops; i++ {
4445
sr.Add(&models.JobHistory{ID: uuid.New(), Status: string(models.StatusSuccess)})
45-
sr.Add(&models.JobHistory{ID: uuid.New(), Status: string(models.StatusFinished)})
46-
4746
sr.Add(&models.JobHistory{ID: uuid.New(), Status: string(models.StatusFailed)})
4847
sr.Add(&models.JobHistory{ID: uuid.New(), Status: string(models.StatusWarning)})
4948
}
@@ -54,8 +53,8 @@ func TestStatusRing(t *testing.T) {
5453
_ = eg.Wait()
5554
total += len(ch)
5655

57-
// we have added 2000 job history to the status rings
58-
// based on retention, 5*6*2 jobs remain in the status rings
56+
// we have added 1500 job history to the status rings
57+
// based on retention, 5*3*3 (cases * uniq status * retention for uniq status) jobs remain in the status rings
5958
// while the rest of them should have been moved to the evicted channel
6059
if total != expected {
6160
t.Fatalf("Expected %d job ids in the channel. Got %d", expected, total)

models/job_history.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,12 @@ func (h *JobHistory) evaluateStatus() {
141141
if h.Status != StatusRunning {
142142
return
143143
}
144-
if h.SuccessCount == 0 {
145-
if h.ErrorCount > 0 {
146-
h.Status = StatusFailed
147-
} else {
148-
h.Status = StatusFinished
149-
}
144+
145+
if h.ErrorCount > 0 && h.SuccessCount > 0 {
146+
h.Status = StatusWarning
147+
} else if h.ErrorCount > 0 && h.SuccessCount == 0 {
148+
h.Status = StatusFailed
150149
} else {
151-
if h.ErrorCount == 0 {
152-
h.Status = StatusSuccess
153-
} else {
154-
h.Status = StatusWarning
155-
}
150+
h.Status = StatusSuccess
156151
}
157152
}

tests/job_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ var _ = Describe("Job", Ordered, func() {
5353
counts := lo.CountValuesBy(items, func(j models.JobHistory) string { return j.Status })
5454

5555
Expect(len(items)).To(BeNumerically("==", 4))
56-
Expect(counts[models.StatusFinished]).To(Equal(2))
56+
Expect(counts[models.StatusSuccess]).To(Equal(2))
5757
Expect(counts[models.StatusSkipped]).To(Equal(2))
58-
for _, item := range groups[models.StatusFinished] {
58+
for _, item := range groups[models.StatusSuccess] {
5959
Expect(item.TimeEnd).ToNot(BeNil())
6060
Expect(item.TimeEnd.Sub(item.TimeStart).Milliseconds()).To(BeNumerically("~", 50, 10))
6161
}

tests/setup/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func ExpectJobToPass(j *job.Job) {
226226
history, err := j.FindHistory()
227227
Expect(err).To(BeNil())
228228
Expect(len(history)).To(BeNumerically(">=", 1))
229-
Expect(history[0].Status).To(BeElementOf(models.StatusFinished, models.StatusSuccess))
229+
Expect(history[0].Status).To(BeElementOf(models.StatusSuccess))
230230
}
231231

232232
func DumpEventQueue(ctx context.Context) {

0 commit comments

Comments
 (0)