func TestReachedFailureLimit(t *testing.T) { Convey("With 3 failed task and relevant project variants", t, func() { db.Clear(task.Collection) db.Clear(model.ProjectRefCollection) db.Clear(version.Collection) t := task.Task{ Id: "t1", Revision: "aaa", Project: "testProject", BuildVariant: "bv1", FinishTime: time.Now().Add(-time.Hour), } So(t.Insert(), ShouldBeNil) t.Id = "t2" t.BuildVariant = "bv2" So(t.Insert(), ShouldBeNil) t.Id = "t3" t.BuildVariant = "bv3" So(t.Insert(), ShouldBeNil) So(testProject.Insert(), ShouldBeNil) So(testVersion.Insert(), ShouldBeNil) Convey("a variant with batchtime of 60 should not hit the limit", func() { out, err := reachedFailureLimit("t1") So(err, ShouldBeNil) So(out, ShouldBeFalse) }) Convey("a variant with batchtime of 1 should hit the limit", func() { out, err := reachedFailureLimit("t2") So(err, ShouldBeNil) So(out, ShouldBeTrue) }) Convey("a fallback batchtime of 5 should hit the limit", func() { out, err := reachedFailureLimit("t3") So(err, ShouldBeNil) So(out, ShouldBeTrue) }) }) }