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.
This commit is contained in:
Deluan 2025-07-20 10:43:04 -04:00
parent d5fa46e948
commit 9fcc996336
2 changed files with 16 additions and 0 deletions

View File

@ -26,6 +26,12 @@ var _ = Describe("Adapter Media Agent", func() {
mgr = createManager(nil, metrics.NewNoopInstance())
mgr.ScanPlugins()
// Wait for all plugins to compile to avoid race conditions
err := mgr.EnsureCompiled("multi_plugin")
Expect(err).NotTo(HaveOccurred(), "multi_plugin should compile successfully")
err = mgr.EnsureCompiled("fake_album_agent")
Expect(err).NotTo(HaveOccurred(), "fake_album_agent should compile successfully")
})
Describe("AgentName and PluginName", func() {

View File

@ -31,6 +31,16 @@ var _ = Describe("Plugin Manager", func() {
ctx = GinkgoT().Context()
mgr = createManager(nil, metrics.NewNoopInstance())
mgr.ScanPlugins()
// Wait for all plugins to compile to avoid race conditions
err := mgr.EnsureCompiled("fake_artist_agent")
Expect(err).NotTo(HaveOccurred(), "fake_artist_agent should compile successfully")
err = mgr.EnsureCompiled("fake_album_agent")
Expect(err).NotTo(HaveOccurred(), "fake_album_agent should compile successfully")
err = mgr.EnsureCompiled("multi_plugin")
Expect(err).NotTo(HaveOccurred(), "multi_plugin should compile successfully")
err = mgr.EnsureCompiled("unauthorized_plugin")
Expect(err).NotTo(HaveOccurred(), "unauthorized_plugin should compile successfully")
})
It("should scan and discover plugins from the testdata folder", func() {