Skip to content

Commit 1c55c11

Browse files
committed
test: Support concurrent map access on custom cache test
1 parent 748dcdf commit 1c55c11

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

clientprovider_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package g8
22

33
import (
4+
"sync"
45
"testing"
56
"time"
67

@@ -75,18 +76,23 @@ func TestClientProvider_WithCacheAndExpiration(t *testing.T) {
7576

7677
type customCache struct {
7778
entries map[string]any
79+
sync.Mutex
7880
}
7981

8082
func (c *customCache) Get(key string) (value any, exists bool) {
83+
c.Lock()
8184
v, exists := c.entries[key]
85+
c.Unlock()
8286
return v, exists
8387
}
8488

8589
func (c *customCache) Set(key string, value any) {
90+
c.Lock()
8691
if c.entries == nil {
8792
c.entries = make(map[string]any)
8893
}
8994
c.entries[key] = value
95+
c.Unlock()
9096
}
9197

9298
var _ Cache = (*customCache)(nil)

0 commit comments

Comments
 (0)