test(plugins): speed up integration tests (~45% improvement) (#5137)
* test(plugins): speed up integration tests with shared wazero cache Reduce plugin test suite runtime from ~22s to ~12s by: - Creating a shared wazero compilation cache directory in TestPlugins() and setting conf.Server.CacheFolder globally so all test Manager instances reuse compiled WASM binaries from disk cache - Moving 6 createTestManager* calls from inside It blocks to BeforeAll blocks in scrobbler_adapter_test.go and manager_call_test.go - Replacing time.Sleep(2s) in KVStore TTL test with Eventually polling - Reducing WebSocket callback sleeps from 100ms to 10ms Signed-off-by: Deluan <deluan@navidrome.org> * test(plugins): enhance websocket tests by storing server messages for verification Signed-off-by: Deluan <deluan@navidrome.org> --------- Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
@@ -14,7 +14,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/navidrome/navidrome/conf"
|
||||
@@ -54,7 +53,6 @@ var _ = Describe("WebSocketService", Ordered, func() {
|
||||
conf.Server.Plugins.Enabled = true
|
||||
conf.Server.Plugins.Folder = tmpDir
|
||||
conf.Server.Plugins.AutoReload = false
|
||||
conf.Server.CacheFolder = filepath.Join(tmpDir, "cache")
|
||||
|
||||
// Setup mock DataStore with pre-enabled plugin
|
||||
mockPluginRepo := tests.CreateMockPluginRepo()
|
||||
@@ -295,10 +293,12 @@ var _ = Describe("WebSocketService", Ordered, func() {
|
||||
Describe("Plugin Callbacks", func() {
|
||||
var wsServer *httptest.Server
|
||||
var serverConn *websocket.Conn
|
||||
var serverMessages []string
|
||||
var serverMu sync.Mutex
|
||||
|
||||
BeforeEach(func() {
|
||||
serverConn = nil
|
||||
serverMessages = nil
|
||||
|
||||
upgrader := websocket.Upgrader{
|
||||
CheckOrigin: func(r *http.Request) bool { return true },
|
||||
@@ -312,12 +312,15 @@ var _ = Describe("WebSocketService", Ordered, func() {
|
||||
serverConn = conn
|
||||
serverMu.Unlock()
|
||||
|
||||
// Keep connection open
|
||||
// Read and store messages
|
||||
for {
|
||||
_, _, err := conn.ReadMessage()
|
||||
_, msg, err := conn.ReadMessage()
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
serverMu.Lock()
|
||||
serverMessages = append(serverMessages, string(msg))
|
||||
serverMu.Unlock()
|
||||
}
|
||||
}))
|
||||
|
||||
@@ -336,36 +339,10 @@ var _ = Describe("WebSocketService", Ordered, func() {
|
||||
}
|
||||
})
|
||||
|
||||
It("should invoke OnTextMessage callback when receiving text", func() {
|
||||
ctx := GinkgoT().Context()
|
||||
wsURL := "ws://" + strings.TrimPrefix(wsServer.URL, "http://")
|
||||
connID, err := testService.Connect(ctx, wsURL, nil, "text-cb-conn")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// Wait for server to have the connection
|
||||
Eventually(func() *websocket.Conn {
|
||||
serverMu.Lock()
|
||||
defer serverMu.Unlock()
|
||||
return serverConn
|
||||
}).ShouldNot(BeNil())
|
||||
|
||||
// Send message from server to plugin
|
||||
serverMu.Lock()
|
||||
err = serverConn.WriteMessage(websocket.TextMessage, []byte("test message"))
|
||||
serverMu.Unlock()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// The plugin should have received the callback
|
||||
// We can verify by checking the plugin's stored messages via vars
|
||||
// For now we just verify no errors occurred
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
_ = connID
|
||||
})
|
||||
|
||||
It("should invoke OnBinaryMessage callback when receiving binary", func() {
|
||||
ctx := GinkgoT().Context()
|
||||
wsURL := "ws://" + strings.TrimPrefix(wsServer.URL, "http://")
|
||||
connID, err := testService.Connect(ctx, wsURL, nil, "binary-cb-conn")
|
||||
_, err := testService.Connect(ctx, wsURL, nil, "binary-cb-conn")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// Wait for server to have the connection
|
||||
@@ -382,9 +359,13 @@ var _ = Describe("WebSocketService", Ordered, func() {
|
||||
serverMu.Unlock()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// Give time for callback to execute
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
_ = connID
|
||||
// Plugin echoes binary data back as text prefixed with "binary_echo:"
|
||||
expectedEcho := "binary_echo:" + base64.StdEncoding.EncodeToString(binaryData)
|
||||
Eventually(func() []string {
|
||||
serverMu.Lock()
|
||||
defer serverMu.Unlock()
|
||||
return serverMessages
|
||||
}).Should(ContainElement(expectedEcho))
|
||||
})
|
||||
|
||||
It("should invoke OnClose callback when server closes connection", func() {
|
||||
@@ -466,7 +447,7 @@ var _ = Describe("WebSocketService", Ordered, func() {
|
||||
It("should allow plugin to send messages via host function", func() {
|
||||
ctx := GinkgoT().Context()
|
||||
wsURL := "ws://" + strings.TrimPrefix(wsServer.URL, "http://")
|
||||
connID, err := testService.Connect(ctx, wsURL, nil, "host-send-conn")
|
||||
_, err := testService.Connect(ctx, wsURL, nil, "host-send-conn")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// Wait for server to have the connection
|
||||
@@ -488,7 +469,6 @@ var _ = Describe("WebSocketService", Ordered, func() {
|
||||
defer serverMu.Unlock()
|
||||
return serverMessages
|
||||
}).Should(ContainElement("echo:echo"))
|
||||
_ = connID
|
||||
})
|
||||
|
||||
It("should allow plugin to close connection via host function", func() {
|
||||
|
||||
Reference in New Issue
Block a user