78 lines
2.3 KiB
Go
78 lines
2.3 KiB
Go
package check
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"sync"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/delivery"
|
|
)
|
|
|
|
// countingAsks puts asks through inner, and answers no wait until want asks are put (or a bound passes, when it says
|
|
// how many were): a group whose asks are put one after another, each waited for, never gets past its first.
|
|
type countingAsks struct {
|
|
inner Asks
|
|
want int
|
|
mu sync.Mutex
|
|
puts int
|
|
all chan struct{}
|
|
}
|
|
|
|
func (c *countingAsks) Put(ctx context.Context, a delivery.StepAsk) error {
|
|
if err := c.inner.Put(ctx, a); err != nil {
|
|
return err
|
|
}
|
|
c.mu.Lock()
|
|
c.puts++
|
|
if c.puts == c.want {
|
|
close(c.all)
|
|
}
|
|
c.mu.Unlock()
|
|
return nil
|
|
}
|
|
|
|
func (c *countingAsks) Wait(ctx context.Context, a delivery.StepAsk) (delivery.Step, error) {
|
|
select {
|
|
case <-c.all:
|
|
case <-time.After(time.Second):
|
|
c.mu.Lock()
|
|
defer c.mu.Unlock()
|
|
return delivery.Step{}, fmt.Errorf("%d of %d asks were put before the first was waited for", c.puts, c.want)
|
|
}
|
|
return c.inner.Wait(ctx, a)
|
|
}
|
|
|
|
// 1921/S8: a group's asks are all put before any is waited for, so its members run side by side on the build nodes;
|
|
// the verdict is judged in member order as before.
|
|
func TestAGroupPutsEveryMembersAskBeforeTheFirstAnswer(t *testing.T) {
|
|
b := newBench(t)
|
|
counting := &countingAsks{inner: b.ex.Asks, want: 3, all: make(chan struct{})}
|
|
b.ex.Asks = counting
|
|
cs := caseOf(t, pullOf(repoA, 7, head1), pullOf(repoSDK, 12, head2), pullOf("novox/mesh-controller", 3, head1))
|
|
v := b.judge(t, cs).Verdict
|
|
if v.State != delivery.VerdictPass {
|
|
t.Fatalf("verdict = %+v", v)
|
|
}
|
|
if counting.puts != 3 {
|
|
t.Errorf("%d asks were put, want 3", counting.puts)
|
|
}
|
|
}
|
|
|
|
// 1921/S10: the levels of an ask run side by side, so what of the ask's time is its fetch (Took.Clone) is the ask's time
|
|
// less its longest level, not less the sum of its levels.
|
|
func TestTheCloneTimeTakesTheLongestLevelOffNotTheSum(t *testing.T) {
|
|
b := newBench(t)
|
|
b.test = func(c stepCall) (any, error) {
|
|
r := captured[Tested](t, "go-test-slow")
|
|
r.Level, _ = c.args["level"].(string)
|
|
r.Elapsed, r.Setup, r.Lint = 1.5, 0, 0 // the ask's step takes 2 s (bench.answer)
|
|
return r, nil
|
|
}
|
|
v := b.judge(t, caseOf(t, pullOf(repoA, 7, head1))).Verdict
|
|
if v.State != delivery.VerdictPass || v.Took.Clone != 500 {
|
|
t.Errorf("clone = %d ms, want 500 (2 s less the longest level's 1.5 s): %+v", v.Took.Clone, v)
|
|
}
|
|
}
|