The first-build test reads the asks its stub records under a lock: the merge path asks on its own goroutine (issue 1146)
This commit is contained in:
@@ -5,6 +5,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"slices"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -41,14 +43,19 @@ func TestAMergeOnTheApproveIntoANewRepositoryAsksTheFirstBuildAndItsOutcomeRegis
|
|||||||
inv := open.inventory
|
inv := open.inventory
|
||||||
// The real ask, guard and queue included: only its answers are kept, so the build's outcome can be matched.
|
// The real ask, guard and queue included: only its answers are kept, so the build's outcome can be matched.
|
||||||
aForgeAndABuildSeat(t, open)
|
aForgeAndABuildSeat(t, open)
|
||||||
asked := &[][3]string{}
|
// Written by the controller's merge path on its own goroutine, read by the test: under one lock.
|
||||||
|
var mu sync.Mutex
|
||||||
|
var asks [][3]string
|
||||||
var ids []string
|
var ids []string
|
||||||
|
asked := func() [][3]string { mu.Lock(); defer mu.Unlock(); return slices.Clone(asks) }
|
||||||
realAsk := askABuild
|
realAsk := askABuild
|
||||||
askABuild = func(c context.Context, source buildSource, path, ref string) (string, error) {
|
askABuild = func(c context.Context, source buildSource, path, ref string) (string, error) {
|
||||||
id, err := realAsk(c, source, path, ref)
|
id, err := realAsk(c, source, path, ref)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
*asked = append(*asked, [3]string{source.Repository, path, ref})
|
mu.Lock()
|
||||||
|
asks = append(asks, [3]string{source.Repository, path, ref})
|
||||||
ids = append(ids, id)
|
ids = append(ids, id)
|
||||||
|
mu.Unlock()
|
||||||
}
|
}
|
||||||
return id, err
|
return id, err
|
||||||
}
|
}
|
||||||
@@ -126,23 +133,26 @@ func TestAMergeOnTheApproveIntoANewRepositoryAsksTheFirstBuildAndItsOutcomeRegis
|
|||||||
forge()
|
forge()
|
||||||
} else {
|
} else {
|
||||||
forge()
|
forge()
|
||||||
if len(*asked) != 0 {
|
if len(asked()) != 0 {
|
||||||
t.Fatalf("1146/AC7: the merge asked %v before mesh-delivery's word was kept", *asked)
|
t.Fatalf("1146/AC7: the merge asked %v before mesh-delivery's word was kept", asked())
|
||||||
}
|
}
|
||||||
word()
|
word()
|
||||||
}
|
}
|
||||||
if !c.wantRegiter {
|
if !c.wantRegiter {
|
||||||
if len(*asked) != 0 {
|
if len(asked()) != 0 {
|
||||||
t.Fatalf("1146/AC7: a merge whose record holds no Approve asked %v", *asked)
|
t.Fatalf("1146/AC7: a merge whose record holds no Approve asked %v", asked())
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
want := [3]string{"novox/mesh-delivery", "", "main"}
|
want := [3]string{"novox/mesh-delivery", "", "main"}
|
||||||
becomes(t, 10*time.Second, "the first build asked", func() bool { return len(*asked) >= 1 })
|
becomes(t, 10*time.Second, "the first build asked", func() bool { return len(asked()) >= 1 })
|
||||||
if len(*asked) != 1 || (*asked)[0] != want {
|
if got := asked(); len(got) != 1 || got[0] != want {
|
||||||
t.Fatalf("1146/AC7: the merge asked %v, want %v once", *asked, want)
|
t.Fatalf("1146/AC7: the merge asked %v, want %v once", got, want)
|
||||||
}
|
}
|
||||||
build := onTrunk(ids[0], "novox/mesh-delivery", "git", "", map[string]any{"module": "mesh-delivery-view", "version": "1"})
|
mu.Lock()
|
||||||
|
first := ids[0]
|
||||||
|
mu.Unlock()
|
||||||
|
build := onTrunk(first, "novox/mesh-delivery", "git", "", map[string]any{"module": "mesh-delivery-view", "version": "1"})
|
||||||
build.Commit = commit
|
build.Commit = commit
|
||||||
if _, _, err := takeIn(ctx, inv, build); err != nil {
|
if _, _, err := takeIn(ctx, inv, build); err != nil {
|
||||||
t.Fatalf("1146/AC7: the outcome of the first build was refused: %v", err)
|
t.Fatalf("1146/AC7: the outcome of the first build was refused: %v", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user