Fix goroutine leak in pluginmanager test

Use a buffered channel for the operation start signal to prevent
goroutines from blocking indefinitely. When the test receiver times
out before all goroutines send their signal, an unbuffered channel
causes those goroutines to block forever on the send operation.
The buffer size is computed dynamically using max() to ensure it
always accommodates the maximum number of concurrent operations
any test may spawn.
This commit is contained in:
Karan
2025-12-15 03:15:08 +05:30
parent c180d6762d
commit 330dcb43d7

View File

@@ -34,6 +34,10 @@ import (
const (
numPluginsToRegister = 2
numPluginsToUnregister = 2
// maxConcurrentOperations is the buffer size for the ch channel.
// Must be >= max number of goroutines any test spawns to prevent
// goroutine leaks when timeout fires before all sends complete.
maxConcurrentOperations = max(numPluginsToRegister, numPluginsToUnregister)
)
var _ OperationGenerator = &fakeOperationGenerator{}
@@ -178,7 +182,7 @@ loop:
func setup(t *testing.T) (context.Context, chan interface{}, chan interface{}, OperationExecutor) {
tCtx := ktesting.Init(t)
ch, quit := make(chan interface{}), make(chan interface{})
ch, quit := make(chan interface{}, maxConcurrentOperations), make(chan interface{})
return tCtx, ch, quit, NewOperationExecutor(newFakeOperationGenerator(ch, quit))
}