48 lines
1.5 KiB
Go
48 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// Issue 1965 (shanks 2026-11-05 22:22): the marks of the haves never hold the composition pass. A mark that stalls on the
|
|
// bus is cut at markWithin, a mark set while one runs replaces the pending one of its name, and set itself never waits.
|
|
func marksOfTheHavesNeverHoldThePass(t *testing.T) {
|
|
// The bound is the test's own: the stalled mark is released by a channel, never by a real wait.
|
|
setMarkWithin(t, time.Hour)
|
|
m := newMarker(context.Background())
|
|
release := make(chan struct{})
|
|
var ran []string
|
|
stalled := make(chan struct{})
|
|
m.set("refused", func(ctx context.Context) { // a have write that stalls until the test lets it go
|
|
close(stalled)
|
|
<-release
|
|
ran = append(ran, "refused-stalled")
|
|
})
|
|
<-stalled
|
|
// Set while the first runs: only the newest of a name is kept.
|
|
m.set("kept", func(context.Context) { ran = append(ran, "kept-old") })
|
|
m.set("kept", func(context.Context) { ran = append(ran, "kept-new") })
|
|
m.set("refused", func(context.Context) { ran = append(ran, "refused-new") })
|
|
// All four sets above returned while the first mark still stalled: set never waits on it.
|
|
close(release)
|
|
m.wait()
|
|
want := []string{"refused-stalled", "kept-new", "refused-new"}
|
|
if len(ran) != len(want) {
|
|
t.Fatalf("ran %v; want %v", ran, want)
|
|
}
|
|
for i := range want {
|
|
if ran[i] != want[i] {
|
|
t.Fatalf("ran %v; want %v", ran, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func setMarkWithin(t *testing.T, d time.Duration) {
|
|
t.Helper()
|
|
old := markWithin
|
|
markWithin = d
|
|
t.Cleanup(func() { markWithin = old })
|
|
}
|