61 lines
1.9 KiB
Go
61 lines
1.9 KiB
Go
package check
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/delivery"
|
|
)
|
|
|
|
func TestADeliveryThatBuildsHoldsTheChecksAndTheEndOfTheLastPlanSaysSo(t *testing.T) { // N8/AC1
|
|
var h PlanHold
|
|
if h.Held() {
|
|
t.Fatal("an empty bucket holds")
|
|
}
|
|
if !h.Put("plan-1", false) || !h.Held() {
|
|
t.Error("a first plan did not hold")
|
|
}
|
|
if h.Put("plan-2", false) {
|
|
t.Error("a second plan changed whether a delivery builds")
|
|
}
|
|
if h.Put("plan-1", true) || !h.Held() {
|
|
t.Error("one of two plans ending released the hold")
|
|
}
|
|
if !h.Put("plan-2", true) || h.Held() {
|
|
t.Error("the last plan ending did not release the hold")
|
|
}
|
|
if h.Put("plan-3", true) {
|
|
t.Error("the delete of a plan never put changed the hold")
|
|
}
|
|
}
|
|
|
|
func TestARunningCheckIsNotStoppedWhenADeliveryStartsToBuild(t *testing.T) { // ADR 0484 clause 12, ADR 0483 clause 4
|
|
ctx := context.Background()
|
|
var h PlanHold
|
|
j := &judgeFunc{f: func(_ context.Context, _ *Case, call int) (Outcome, error) {
|
|
if call == 1 {
|
|
h.Put("plan-1", false) // a delivery starts while this check runs
|
|
}
|
|
return Outcome{Verdict: passing()}, nil
|
|
}}
|
|
r := newRig(t, j)
|
|
r.ch.Hold = h.Held
|
|
r.ch.Candidate(ctx, "feat/x", candidateOf(t, "feat/x", pullOf(repoA, 7, head1)))
|
|
r.ch.Wait()
|
|
if v := r.verdict(t, keyOf(t, "feat/x", candidateOf(t, "feat/x", pullOf(repoA, 7, head1)))); v.State != delivery.VerdictPass {
|
|
t.Errorf("verdict = %+v, want the running check to end as it was", v)
|
|
}
|
|
// A new candidate waits while the plan builds.
|
|
r.ch.Candidate(ctx, "feat/y", candidateOf(t, "feat/y", pullOf(repoA, 8, head2)))
|
|
r.ch.Wait()
|
|
if j.count() != 1 {
|
|
t.Errorf("judged %d times while a delivery builds, want only the one already running", j.count())
|
|
}
|
|
h.Put("plan-1", true)
|
|
r.ch.Reconsider(ctx)
|
|
r.ch.Wait()
|
|
if j.count() != 2 {
|
|
t.Errorf("judged %d times after the delivery ended, want the waiting candidate too", j.count())
|
|
}
|
|
}
|