From 9fcc996336f96092407981d791bdc62a210327f8 Mon Sep 17 00:00:00 2001 From: Deluan Date: Sun, 20 Jul 2025 10:43:04 -0400 Subject: [PATCH] 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. --- plugins/adapter_media_agent_test.go | 6 ++++++ plugins/manager_test.go | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/plugins/adapter_media_agent_test.go b/plugins/adapter_media_agent_test.go index f8b61ea5..70b5d275 100644 --- a/plugins/adapter_media_agent_test.go +++ b/plugins/adapter_media_agent_test.go @@ -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() { diff --git a/plugins/manager_test.go b/plugins/manager_test.go index 9445979c..2a6ad575 100644 --- a/plugins/manager_test.go +++ b/plugins/manager_test.go @@ -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() {