Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/cache
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-06-28 23:44:37 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2017-06-28 23:44:37 +0300
commitb3c8056de24f6090d1fdf41707bc39cc57a9416a (patch)
tree371656c9e216d48562d7549abe710eded34db63f /cache
parentfe132e1c3e883f0100824eafa097cdd28d0fc441 (diff)
cache: Add concurrent cache test
Diffstat (limited to 'cache')
-rw-r--r--cache/partitioned_lazy_cache_test.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/cache/partitioned_lazy_cache_test.go b/cache/partitioned_lazy_cache_test.go
index 73f75fe17..97c8e09da 100644
--- a/cache/partitioned_lazy_cache_test.go
+++ b/cache/partitioned_lazy_cache_test.go
@@ -15,6 +15,7 @@ package cache
import (
"errors"
+ "sync"
"testing"
"github.com/stretchr/testify/require"
@@ -90,3 +91,46 @@ func TestNewPartitionedLazyCache(t *testing.T) {
assert.Error(err)
}
+
+func TestConcurrentPartitionedLazyCache(t *testing.T) {
+ t.Parallel()
+
+ assert := require.New(t)
+
+ var wg sync.WaitGroup
+
+ p1 := Partition{
+ Key: "p1",
+ Load: func() (map[string]interface{}, error) {
+ return map[string]interface{}{
+ "p1_1": "p1v1",
+ "p1_2": "p1v2",
+ "p1_nil": nil,
+ }, nil
+ },
+ }
+
+ p2 := Partition{
+ Key: "p2",
+ Load: func() (map[string]interface{}, error) {
+ return map[string]interface{}{
+ "p2_1": "p2v1",
+ "p2_2": "p2v2",
+ "p2_3": "p2v3",
+ }, nil
+ },
+ }
+
+ cache := NewPartitionedLazyCache(p1, p2)
+
+ for j := 0; j < 100; j++ {
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ v, err := cache.Get("p1", "p1_1")
+ assert.NoError(err)
+ assert.Equal("p1v1", v)
+ }()
+ }
+ wg.Wait()
+}