mirror of
https://github.com/ceph/go-ceph
synced 2024-12-24 07:03:00 +00:00
callbacks: add a benchmark test case
Signed-off-by: Sven Anderson <sven@redhat.com>
This commit is contained in:
parent
e3c0d271dd
commit
beb3351f24
@ -1,6 +1,7 @@
|
||||
package callbacks
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@ -108,3 +109,42 @@ func TestCallbacksData(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCallbacks(t *testing.B) {
|
||||
cbks := New()
|
||||
workers := 1000
|
||||
var wg sync.WaitGroup
|
||||
f := func() {
|
||||
defer wg.Done()
|
||||
var x interface{}
|
||||
var i1, i2, i3 uintptr
|
||||
for i := 0; i < t.N/workers; i++ {
|
||||
i1 = cbks.Add("foo")
|
||||
i2 = cbks.Add("bar")
|
||||
i3 = cbks.Add("baz")
|
||||
x = cbks.Lookup(i1)
|
||||
assert.NotNil(t, x)
|
||||
if s, ok := x.(string); ok {
|
||||
assert.Equal(t, "foo", s)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
x = cbks.Lookup(i3)
|
||||
assert.NotNil(t, x)
|
||||
if s, ok := x.(string); ok {
|
||||
assert.Equal(t, "baz", s)
|
||||
} else {
|
||||
t.Fail()
|
||||
}
|
||||
cbks.Remove(i3)
|
||||
cbks.Remove(i2)
|
||||
cbks.Remove(i1)
|
||||
}
|
||||
}
|
||||
for i := 0; i < workers; i++ {
|
||||
wg.Add(1)
|
||||
go f()
|
||||
}
|
||||
wg.Wait()
|
||||
assert.Len(t, cbks.cmap, 0)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user