Gate overlap test fetches on a barrier instead of a 50ms window
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful

This commit is contained in:
2026-10-25 13:33:22 +11:00
parent c454e44730
commit 1228a1d473
+13 -6
View File
@@ -492,9 +492,10 @@ func TestFetchFilesErrorCancelsRest(t *testing.T) {
}
}
// overlapEngine serves fixed member index paths, holding each index file fetch
// until all are in flight or a short wait expires, and records the peak.
func overlapEngine(index map[string][]byte, indexFiles int, peak *atomic.Int32) *Engine {
// overlapEngine serves fixed member index paths and records the peak number of
// index file fetches in flight. Each fetch blocks until want are in flight (or
// fails after 5s); with want 1 it also holds briefly so a stray overlap shows.
func overlapEngine(index map[string][]byte, want int32, peak *atomic.Int32) *Engine {
e := fakeEngine(nil)
var inFlight atomic.Int32
e.memberPath = func(_ context.Context, _ models.Remote, path string) ([]byte, error) {
@@ -509,9 +510,15 @@ func overlapEngine(index map[string][]byte, indexFiles int, peak *atomic.Int32)
defer inFlight.Add(-1)
for p := peak.Load(); n > p && !peak.CompareAndSwap(p, n); p = peak.Load() {
}
for deadline := time.Now().Add(50 * time.Millisecond); peak.Load() < int32(indexFiles) && time.Now().Before(deadline); {
for deadline := time.Now().Add(5 * time.Second); peak.Load() < want; {
if time.Now().After(deadline) {
return nil, fmt.Errorf("%s: only %d of %d fetches in flight", path, peak.Load(), want)
}
time.Sleep(time.Millisecond)
}
if want == 1 {
time.Sleep(10 * time.Millisecond)
}
return body, nil
}
return e
@@ -527,7 +534,7 @@ func TestFetchRPMMemberHonoursParallelFetch(t *testing.T) {
}
for parallel, want := range map[bool]int32{false: 1, true: 3} {
var peak atomic.Int32
m, err := overlapEngine(index, 3, &peak).fetchRPMMember(context.Background(), "a", parallel)
m, err := overlapEngine(index, want, &peak).fetchRPMMember(context.Background(), "a", parallel)
if err != nil {
t.Fatal(err)
}
@@ -552,7 +559,7 @@ func TestFetchDebMemberHonoursParallelFetch(t *testing.T) {
}
for parallel, want := range map[bool]int32{false: 1, true: 3} {
var peak atomic.Int32
m, err := overlapEngine(index, 3, &peak).fetchDebMember(context.Background(), "a", "dists/s/", parallel)
m, err := overlapEngine(index, want, &peak).fetchDebMember(context.Background(), "a", "dists/s/", parallel)
if err != nil {
t.Fatal(err)
}