Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions components/receivers/k8sevents/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ func TestK8sevents_Lifecycle_ConcurrentAddDuringShutdown_NoPanic(t *testing.T) {
}

release := make(chan struct{})
shutdownGate := make(chan struct{})
var launched sync.WaitGroup
launched.Add(adders + 1)

Expand All @@ -305,13 +306,30 @@ func TestK8sevents_Lifecycle_ConcurrentAddDuringShutdown_NoPanic(t *testing.T) {
go func() {
launched.Done()
<-release
// Wait for shutdownGate to open before calling Shutdown. The
// gate fires AFTER the adders have been released for a brief
// scheduling window, which guarantees the race window straddles
// adders-in-flight + Shutdown rather than letting the
// shutdowner trivially win and force every Add into the
// closed-guard no-op branch. (Without this, on fast machines
// every adder consistently no-ops, defeating the test's
// TOCTOU-coverage purpose. Ported from containerstdout's
// hardened equivalent to deflake CI on fast schedulers.)
<-shutdownGate
runtime.Gosched()
shutdownErr = lc.Shutdown(context.Background())
close(shutdownDone)
}()

launched.Wait()
close(release)
// Give the adders a short scheduling window to land their Add()
// calls. The window is intentionally tiny — the race detector +
// the scheduler still interleave so SOME adders will no-op (which
// is also a tested outcome) — but it prevents the trivial
// shutdowner-wins-everything degenerate.
time.Sleep(50 * time.Microsecond)
close(shutdownGate)

select {
case <-shutdownDone:
Expand Down
18 changes: 18 additions & 0 deletions components/receivers/kernelevents/lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ func TestKernelevents_Lifecycle_ConcurrentAddDuringShutdown_NoPanic(t *testing.T
// Gate: all adders + the shutdowner block until release fires, so
// the race window opens at roughly the same wall-clock moment.
release := make(chan struct{})
shutdownGate := make(chan struct{})
var launched sync.WaitGroup
launched.Add(adders + 1)

Expand All @@ -315,13 +316,30 @@ func TestKernelevents_Lifecycle_ConcurrentAddDuringShutdown_NoPanic(t *testing.T
go func() {
launched.Done()
<-release
// Wait for shutdownGate to open before calling Shutdown. The
// gate fires AFTER the adders have been released for a brief
// scheduling window, which guarantees the race window straddles
// adders-in-flight + Shutdown rather than letting the
// shutdowner trivially win and force every Add into the
// closed-guard no-op branch. (Without this, on fast machines
// every adder consistently no-ops, defeating the test's
// TOCTOU-coverage purpose. Ported from containerstdout's
// hardened equivalent to deflake CI on fast schedulers.)
<-shutdownGate
runtime.Gosched()
shutdownErr = lc.Shutdown(context.Background())
close(shutdownDone)
}()

launched.Wait()
close(release)
// Give the adders a short scheduling window to land their Add()
// calls. The window is intentionally tiny — the race detector +
// the scheduler still interleave so SOME adders will no-op (which
// is also a tested outcome) — but it prevents the trivial
// shutdowner-wins-everything degenerate.
time.Sleep(50 * time.Microsecond)
close(shutdownGate)

select {
case <-shutdownDone:
Expand Down
Loading