Skip to content

Commit

Permalink
test: Support concurrent map access on custom cache test
Browse files Browse the repository at this point in the history
  • Loading branch information
TwiN committed Apr 11, 2023
1 parent 748dcdf commit 1c55c11
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clientprovider_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package g8

import (
"sync"
"testing"
"time"

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

type customCache struct {
entries map[string]any
sync.Mutex
}

func (c *customCache) Get(key string) (value any, exists bool) {
c.Lock()
v, exists := c.entries[key]
c.Unlock()
return v, exists
}

func (c *customCache) Set(key string, value any) {
c.Lock()
if c.entries == nil {
c.entries = make(map[string]any)
}
c.entries[key] = value
c.Unlock()
}

var _ Cache = (*customCache)(nil)
Expand Down

0 comments on commit 1c55c11

Please sign in to comment.