fix: resolve linter warning and cache race condition
- Suppress revive redundant-test-main-exit warning with //nolint - Fix data race in cache.Clear() by using Delete() instead of map replacement - Both changes maintain correct behavior while fixing CI failures
This commit is contained in:
parent
db57f4456a
commit
4bd0f29ee5
2 changed files with 14 additions and 13 deletions
24
store/cache/cache.go
vendored
24
store/cache/cache.go
vendored
|
|
@ -161,20 +161,20 @@ func (c *Cache) Delete(_ context.Context, key string) {
|
||||||
|
|
||||||
// Clear removes all values from the cache.
|
// Clear removes all values from the cache.
|
||||||
func (c *Cache) Clear(_ context.Context) {
|
func (c *Cache) Clear(_ context.Context) {
|
||||||
if c.config.OnEviction != nil {
|
count := 0
|
||||||
c.data.Range(func(key, value any) bool {
|
c.data.Range(func(key, value any) bool {
|
||||||
|
if c.config.OnEviction != nil {
|
||||||
itm, ok := value.(item)
|
itm, ok := value.(item)
|
||||||
if !ok {
|
if ok {
|
||||||
return true
|
if keyStr, ok := key.(string); ok {
|
||||||
|
c.config.OnEviction(keyStr, itm.value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if keyStr, ok := key.(string); ok {
|
}
|
||||||
c.config.OnEviction(keyStr, itm.value)
|
c.data.Delete(key)
|
||||||
}
|
count++
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
c.data = sync.Map{}
|
|
||||||
(&c.itemCount).Store(0)
|
(&c.itemCount).Store(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@ func TestMain(m *testing.M) {
|
||||||
// If DRIVER is set, run tests for that driver only
|
// If DRIVER is set, run tests for that driver only
|
||||||
if os.Getenv("DRIVER") != "" {
|
if os.Getenv("DRIVER") != "" {
|
||||||
defer TerminateContainers()
|
defer TerminateContainers()
|
||||||
os.Exit(m.Run())
|
m.Run() //nolint:revive // Exit code is handled by test runner
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// No DRIVER set - run tests for all drivers sequentially
|
// No DRIVER set - run tests for all drivers sequentially
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue