test: goroutine leak detector (#45)
- Add goroutine leak detector to help avoid Goroutine leaks by Uber: https://github.com/uber-go/goleak - By using this package, I found an issue in frecency: - Close global DB connection to fix goroutine leak in tests (https://github.com/versenilvis/IRIS/commit/831f86ffdf01124da537c149559fa41f37500e1e)
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package ai
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
goleak.VerifyTestMain(m)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
goleak.VerifyTestMain(m)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package logger
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
goleak.VerifyTestMain(m)
|
||||
}
|
||||
@@ -500,3 +500,15 @@ func GetFrecencyStore() (*FrecencyStore, error) {
|
||||
globalFrecencyStore = store
|
||||
return globalFrecencyStore, nil
|
||||
}
|
||||
|
||||
// CloseGlobalFrecencyStore safely closes the singleton database connection.
|
||||
// This is primarily used in testing to prevent goroutine leaks from the DB connectionOpener.
|
||||
func CloseGlobalFrecencyStore() {
|
||||
globalFrecencyMu.Lock()
|
||||
defer globalFrecencyMu.Unlock()
|
||||
|
||||
if globalFrecencyStore != nil {
|
||||
_ = globalFrecencyStore.Close()
|
||||
globalFrecencyStore = nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package scoring
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
goleak.VerifyTestMain(m)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package workspace
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"go.uber.org/goleak"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
goleak.VerifyTestMain(m)
|
||||
}
|
||||
Reference in New Issue
Block a user