Skip to content

Commit bbb572d

Browse files
authored
[EBPF-1034] stabilize TestDeviceCacheRefresh_Concurrent initialization (#49936)
### What does this PR do? Pre-initializes the device cache before starting the concurrent reader/updater goroutines in `TestDeviceCacheRefresh_Concurrent`. ### Motivation The test can observe an inconsistent mocked device snapshot during lazy initialization (`.Count()` can trigger `Refresh()`) and intermittently fail with `count is 5`. ### Describe how you validated your changes Ran the targeted unit test with: - `dda inv test --targets=./pkg/gpu/safenvml --extra-args='-run TestDeviceCacheRefresh_Concurrent -count=1' -v` We will monitor the test in CI to see if it's triggered again ### Additional Notes Co-authored-by: guillermo.julian <guillermo.julian@datadoghq.com>
1 parent bcafe99 commit bbb572d

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

pkg/gpu/safenvml/cache_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@ func TestDeviceCacheRefresh_Concurrent(t *testing.T) {
303303
WithMockNVML(t, mockNvml)
304304
cache := NewDeviceCache()
305305
require.NotNil(t, cache)
306+
// Pre-initialize the cache so the reader goroutine's Count() never triggers
307+
// ensureInit() → Refresh(). Without this, the reader's first Refresh() can
308+
// observe an inconsistent device count: DeviceGetCount() and
309+
// DeviceGetHandleByIndex() each read numDevicesAvailable independently, and
310+
// the updater's Store() can land between those reads.
311+
require.NoError(t, cache.Refresh())
306312

307313
// launch two workers, one refreshing the cache and one reading from it
308314
var wg sync.WaitGroup

0 commit comments

Comments
 (0)