Skip to content

Commit 92e9d99

Browse files
committed
fix: ratelimit probe contamination + parallel-safe panic count assertions
1 parent 82a12ce commit 92e9d99

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

pkg/coreapi/zz_recover_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (b *fakeBus) latest() []string {
4343
// 4. the onPanic callback fires with the panic value
4444
func TestL11PluginPanicSurvival(t *testing.T) {
4545
t.Parallel()
46-
ResetPluginRecoveredPanicCountForTest()
46+
before := PluginRecoveredPanicCount()
4747
bus := &fakeBus{}
4848

4949
var (
@@ -65,7 +65,7 @@ func TestL11PluginPanicSurvival(t *testing.T) {
6565
}()
6666
wg.Wait()
6767

68-
if PluginRecoveredPanicCount() == 0 {
68+
if PluginRecoveredPanicCount() <= before {
6969
t.Fatal("L11 boundary did not record the panic")
7070
}
7171

@@ -95,7 +95,7 @@ func TestL11PluginPanicSurvival(t *testing.T) {
9595
// bus is provided (e.g., the standalone nameserver binary).
9696
func TestL11PluginPanicNilBus(t *testing.T) {
9797
t.Parallel()
98-
ResetPluginRecoveredPanicCountForTest()
98+
before := PluginRecoveredPanicCount()
9999
var wg sync.WaitGroup
100100
wg.Add(1)
101101
go func() {
@@ -104,7 +104,7 @@ func TestL11PluginPanicNilBus(t *testing.T) {
104104
panic("nil-bus panic")
105105
}()
106106
wg.Wait()
107-
if PluginRecoveredPanicCount() == 0 {
107+
if PluginRecoveredPanicCount() <= before {
108108
t.Fatal("L11 boundary did not record nil-bus panic")
109109
}
110110
}
@@ -113,7 +113,7 @@ func TestL11PluginPanicNilBus(t *testing.T) {
113113
// against a panicking onPanic callback.
114114
func TestL11PluginPanicCallbackPanicSwallowed(t *testing.T) {
115115
t.Parallel()
116-
ResetPluginRecoveredPanicCountForTest()
116+
before := PluginRecoveredPanicCount()
117117
var wg sync.WaitGroup
118118
wg.Add(1)
119119
go func() {
@@ -124,7 +124,7 @@ func TestL11PluginPanicCallbackPanicSwallowed(t *testing.T) {
124124
panic("primary panic")
125125
}()
126126
wg.Wait()
127-
if PluginRecoveredPanicCount() == 0 {
127+
if PluginRecoveredPanicCount() <= before {
128128
t.Fatal("L11 boundary did not record the primary panic")
129129
}
130130
}

tests/zz_eventstream_broker_parity_test.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ func TestBrokerParityRateLimit(t *testing.T) {
207207
// isters the recv channel without closing it); only env.Close()
208208
// during t.Cleanup eventually drains it. Tests don't wait.
209209
var got atomic.Int64
210+
var probeReceived atomic.Bool // set when the "init" liveness probe lands
210211
go func() {
211212
for {
212213
evt, err := sub.Recv()
@@ -215,16 +216,23 @@ func TestBrokerParityRateLimit(t *testing.T) {
215216
}
216217
if evt.Topic == "parity.ratelimit" {
217218
p := string(evt.Payload)
218-
if len(p) >= 3 && p[:3] == "rl-" {
219+
if p == "init" {
220+
probeReceived.Store(true)
221+
} else if len(p) >= 3 && p[:3] == "rl-" {
219222
got.Add(1)
220223
}
221224
}
222225
}
223226
}()
224227
defer sub.Close()
225228

226-
// Wait for subscription to be live by re-publishing rl-0 until
227-
// it's seen. (Once the first lands, the broker has registered.)
229+
// Wait for subscription to be live by publishing "init" probes until
230+
// one arrives. Uses probeReceived (not got) so that probe events don't
231+
// contaminate the rl-* counter used in the flood assertions below.
232+
// (Commit 82a12ce changed the probe payload from "rl-init" to "init"
233+
// to stop probe events from counting as rl-* hits, but forgot to update
234+
// the liveness check from got.Load() > 0 to probeReceived — so the
235+
// loop always timed out on loaded CI runners.)
228236
{
229237
deadline := time.After(5 * time.Second)
230238
tick := time.NewTicker(50 * time.Millisecond)
@@ -235,15 +243,12 @@ func TestBrokerParityRateLimit(t *testing.T) {
235243
t.Fatal("subscription never became live")
236244
case <-tick.C:
237245
_ = pub.Publish("parity.ratelimit", []byte("init"))
238-
if got.Load() > 0 {
246+
if probeReceived.Load() {
239247
tick.Stop()
240248
break probeLoop
241249
}
242250
}
243251
}
244-
// Reset counter after probes. We don't know exactly how many
245-
// probes landed; record current count and treat it as the
246-
// pre-flood baseline.
247252
}
248253
baseline := got.Load()
249254

0 commit comments

Comments
 (0)