Skip to content

Commit 9fcc996

Browse files
committed
fix(plugins): prevent race condition in plugin tests
Add EnsureCompiled calls in plugin test BeforeEach blocks to wait for WebAssembly compilation before loading plugins. This prevents race conditions where tests would attempt to load plugins before compilation completed, causing flaky test failures in CI environments. The race condition occurred because ScanPlugins() registers plugins synchronously but compiles them asynchronously in background goroutines with a concurrency limit of 2. Tests that immediately called LoadPlugin() or LoadMediaAgent() after ScanPlugins() could fail if compilation wasn't finished yet. Fixed in both adapter_media_agent_test.go and manager_test.go which had multiple tests vulnerable to this timing issue.
1 parent d5fa46e commit 9fcc996

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

plugins/adapter_media_agent_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ var _ = Describe("Adapter Media Agent", func() {
2626

2727
mgr = createManager(nil, metrics.NewNoopInstance())
2828
mgr.ScanPlugins()
29+
30+
// Wait for all plugins to compile to avoid race conditions
31+
err := mgr.EnsureCompiled("multi_plugin")
32+
Expect(err).NotTo(HaveOccurred(), "multi_plugin should compile successfully")
33+
err = mgr.EnsureCompiled("fake_album_agent")
34+
Expect(err).NotTo(HaveOccurred(), "fake_album_agent should compile successfully")
2935
})
3036

3137
Describe("AgentName and PluginName", func() {

plugins/manager_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ var _ = Describe("Plugin Manager", func() {
3131
ctx = GinkgoT().Context()
3232
mgr = createManager(nil, metrics.NewNoopInstance())
3333
mgr.ScanPlugins()
34+
35+
// Wait for all plugins to compile to avoid race conditions
36+
err := mgr.EnsureCompiled("fake_artist_agent")
37+
Expect(err).NotTo(HaveOccurred(), "fake_artist_agent should compile successfully")
38+
err = mgr.EnsureCompiled("fake_album_agent")
39+
Expect(err).NotTo(HaveOccurred(), "fake_album_agent should compile successfully")
40+
err = mgr.EnsureCompiled("multi_plugin")
41+
Expect(err).NotTo(HaveOccurred(), "multi_plugin should compile successfully")
42+
err = mgr.EnsureCompiled("unauthorized_plugin")
43+
Expect(err).NotTo(HaveOccurred(), "unauthorized_plugin should compile successfully")
3444
})
3545

3646
It("should scan and discover plugins from the testdata folder", func() {

0 commit comments

Comments
 (0)