From 84d15102ebc799edd0d56901b462534c3398d64a Mon Sep 17 00:00:00 2001 From: Patrick Mylund Nielsen Date: Tue, 21 Feb 2012 18:46:25 +0100 Subject: [PATCH] Add test for concurrent cache.Get --- cache_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/cache_test.go b/cache_test.go index 334c224..4330d56 100644 --- a/cache_test.go +++ b/cache_test.go @@ -3,6 +3,7 @@ package cache import ( "bytes" "io/ioutil" + "sync" "testing" "time" ) @@ -641,6 +642,20 @@ func BenchmarkCacheGet(b *testing.B) { } } +func BenchmarkCacheGetConcurrent(b *testing.B) { + tc := New(0, 0) + tc.Set("foo", "bar", 0) + wg := new(sync.WaitGroup) + wg.Add(b.N) + for i := 0; i < b.N; i++ { + go func() { + tc.Get("foo") + wg.Done() + }() + } + wg.Wait() +} + func BenchmarkMapGet(b *testing.B) { m := map[string]string{ "foo": "bar", @@ -650,6 +665,21 @@ func BenchmarkMapGet(b *testing.B) { } } +// func BenchmarkMapGetConcurrent(b *testing.B) { +// m := map[string]string{ +// "foo": "bar", +// } +// wg := new(sync.WaitGroup) +// wg.Add(b.N) +// for i := 0; i < b.N; i++ { +// go func() { +// _, _ = m["foo"] +// wg.Done() +// }() +// } +// wg.Wait() +// } + func BenchmarkCacheSet(b *testing.B) { tc := New(0, 0) for i := 0; i < b.N; i++ {