| index a7275ea85..9c80eb595 100644 |
| --- a/internal/activator/wakecheck_test.go |
| +++ b/internal/activator/wakecheck_test.go |
| @@ -33,6 +33,16 @@ func shrinkWakeWait(t *testing.T, d time.Duration) { |
| t.Cleanup(func() { wakeWaitBound = old }) |
| } |
| |
| +// shrinkHeldPoll sets how often a held wake polls while it waits, for one |
| +// test. It asks for the answer again every heldReask polls, so a test that |
| +// waits for a re-ask waits heldReask*d. |
| +func shrinkHeldPoll(t *testing.T, d time.Duration) { |
| + t.Helper() |
| + old := heldPoll |
| + heldPoll = d |
| + t.Cleanup(func() { heldPoll = old }) |
| +} |
| + |
| // asks records RequestStage calls as host@build. |
| type asks struct { |
| mu sync.Mutex |
| @@ -486,6 +496,7 @@ func TestAHeldWakeEndsItsWaitWhenTheAnswerChanges(t *testing.T) { |
| for _, c := range cases { |
| t.Run(c.name, func(t *testing.T) { |
| shrinkWakeWait(t, 20*time.Second) |
| + shrinkHeldPoll(t, 25*time.Millisecond) // the re-ask comes 8 polls in |
| a, b := identityActivator(t, "v3") |
| var asked atomic.Int32 |
| a.HeldTarget = func(string) HeldWake { |
| @@ -563,7 +574,10 @@ func TestAHeldUnitRowRefusesALinkThatMovedAfterTheWait(t *testing.T) { |
| // to come back (the agent's refresh reads the bucket, up to its own 5 s |
| // budget) never holds the wake past wakeWaitBound. |
| func TestAHeldWakesReaskNeverOutlastsTheWait(t *testing.T) { |
| - shrinkWakeWait(t, 1900*time.Millisecond) |
| + // The re-ask comes 8 polls (175 ms) into a 400 ms wait, and its answer |
| + // takes 5 s: the wait must end at its own bound. |
| + shrinkHeldPoll(t, 25*time.Millisecond) |
| + shrinkWakeWait(t, 400*time.Millisecond) |
| a, b := identityActivator(t, "v3") |
| var asked atomic.Int32 |
| a.HeldTarget = func(string) HeldWake { |
| @@ -586,7 +600,7 @@ func TestAHeldWakesReaskNeverOutlastsTheWait(t *testing.T) { |
| t.Fatalf("asked %d times: the wait never asked again", asked.Load()) |
| } |
| if took >= 3*time.Second { |
| - t.Fatalf("the wait ran %v, past its 1.9 s bound: the re-ask outlasted it", took) |
| + t.Fatalf("the wait ran %v, past its 0.4 s bound: the re-ask outlasted it", took) |
| } |
| if b.startCount() != 0 { |
| t.Fatal("a wake that never saw its target ran something") |
| @@ -643,7 +657,10 @@ func TestAWakeRootHasNotDecidedForWaitsForRoot(t *testing.T) { |
| } |
| for _, c := range cases { |
| t.Run(c.name, func(t *testing.T) { |
| - shrinkWakeWait(t, 3*time.Second) |
| + // Root's answer is asked again 8 polls (200 ms) in; a wake root |
| + // never decides for fails at the bound. |
| + shrinkHeldPoll(t, 25*time.Millisecond) |
| + shrinkWakeWait(t, time.Second) |
| a, b := identityActivator(t, "v3") |
| var asked atomic.Bool |
| a.HeldTarget = func(string) HeldWake { |