mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Race test for pkg/pubsub package
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
parent
e5da4d62ef
commit
8aa7ba731a
1 changed files with 20 additions and 0 deletions
|
@ -96,6 +96,26 @@ func newTestSubscriber(p *Publisher) *testSubscriber {
|
||||||
return ts
|
return ts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// for testing with -race
|
||||||
|
func TestPubSubRace(t *testing.T) {
|
||||||
|
p := NewPublisher(0, 1024)
|
||||||
|
var subs [](*testSubscriber)
|
||||||
|
for j := 0; j < 50; j++ {
|
||||||
|
subs = append(subs, newTestSubscriber(p))
|
||||||
|
}
|
||||||
|
for j := 0; j < 1000; j++ {
|
||||||
|
p.Publish(sampleText)
|
||||||
|
}
|
||||||
|
time.AfterFunc(1*time.Second, func() {
|
||||||
|
for _, s := range subs {
|
||||||
|
p.Evict(s.dataCh)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
for _, s := range subs {
|
||||||
|
s.Wait()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkPubSub(b *testing.B) {
|
func BenchmarkPubSub(b *testing.B) {
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
|
|
Loading…
Reference in a new issue