package oltp
import "testing"
// #302: a run launched again for the same check-in and pipeline is a
// re-run of the one before it. The relation is read off the recorded
// runs, both ways, and never crosses a pipeline, a check-in or a pair.
func TestCIRunsCarryTheirRerunChain(t *testing.T) {
db := testDB(t)
add := func(id, checkin, pair, pipeline string) {
t.Helper()
if err := db.AddCIRun(CIRun{RunID: id, Repo: "r", Checkin: checkin, Pair: pair,
Workflow: "w", Pipeline: pipeline, Status: "running"}); err != nil {
t.Fatal(err)
}
}
add("a1", "c1", "", "ci/a.json")
add("b1", "c1", "", "ci/b.json")
add("a2", "c1", "", "ci/a.json")
add("x1", "c2", "", "ci/a.json")
add("a3", "c1", "", "ci/a.json")
add("p1", "pair:c1:t", "pair:c1:t", "ci/a.json")
want := map[string][2]string{ // run -> {rerun of, rerun as}
"a1": {"", "a2"}, "a2": {"a1", "a3"}, "a3": {"a2", ""},
"b1": {"", ""}, "x1": {"", ""}, "p1": {"", ""},
}
for id, w := range want {
r, ok, err := db.CIRunByID("r", id)
if err != nil || !ok {
t.Fatalf("FAIL: run %s: %v %v", id, ok, err)
}
if r.RerunOf != w[0] || r.RerunAs != w[1] {
t.Errorf("FAIL: run %s rerun of %q as %q, want of %q as %q", id, r.RerunOf, r.RerunAs, w[0], w[1])
}
}
rows, err := db.CIRuns("r", 10)
if err != nil {
t.Fatal(err)
}
for _, r := range rows {
if r.RunID == "a2" && (r.RerunOf != "a1" || r.RerunAs != "a3") {
t.Errorf("FAIL: a listed run lost its chain: %+v", r)
}
}
}