func TestGrammar(t *testing.T) { bnf0 := GenerateBnf0Grammar() g := GetIndexedGrammar(bnf0) idxIf, err := g.GetIndex(GrammarIndexTypeTerm) if err != nil { t.Error(err) return } termIndex := idxIf.(TermGrammarIndex) for _, ntn := range termIndex.GetNonterminalNames() { nt, _ := termIndex.GetNonterminal(ntn) fmt.Printf("%d: <%s>\n", nt.Id(), nt.Name()) } for _, tn := range termIndex.GetTerminalNames() { t, _ := termIndex.GetTerminal(tn) fmt.Printf("%d: %s\n", t.Id(), t.Name()) } }
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) }) }) }