-
Notifications
You must be signed in to change notification settings - Fork 9
/
benchmarks_test.go
71 lines (61 loc) · 1.56 KB
/
benchmarks_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright 2016 Canonical Ltd.
// Licensed under the LGPLv3, see LICENCE file for details.
package pubsub_test
import (
"time"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/pubsub/v2"
)
type BenchmarkSuite struct{}
var _ = gc.Suite(&BenchmarkSuite{})
func (*BenchmarkSuite) BenchmarkStructuredNoConversions(c *gc.C) {
hub := pubsub.NewStructuredHub(nil)
topic := "benchmarking"
counter := 0
unsub, err := hub.SubscribeMatch(pubsub.MatchAll, func(topic string, data map[string]interface{}) {
counter++
})
c.Assert(err, jc.ErrorIsNil)
defer unsub()
failedCount := 0
for i := 0; i < c.N; i++ {
done, err := hub.Publish(topic, nil)
c.Assert(err, jc.ErrorIsNil)
select {
case <-pubsub.Wait(done):
case <-time.After(time.Second):
failedCount++
}
}
c.Check(failedCount, gc.Equals, 0)
c.Check(counter, jc.GreaterThan, 0)
}
func (*BenchmarkSuite) BenchmarkStructuredSerialize(c *gc.C) {
hub := pubsub.NewStructuredHub(nil)
topic := "benchmarking"
counter := 0
unsub, err := hub.SubscribeMatch(pubsub.MatchAll, func(topic string, data Emission, err error) {
c.Assert(err, jc.ErrorIsNil)
counter++
})
c.Assert(err, jc.ErrorIsNil)
defer unsub()
failedCount := 0
data := Emission{
Origin: "master",
Message: "hello world",
ID: 42,
}
for i := 0; i < c.N; i++ {
done, err := hub.Publish(topic, data)
c.Assert(err, jc.ErrorIsNil)
select {
case <-pubsub.Wait(done):
case <-time.After(time.Second):
failedCount++
}
}
c.Check(failedCount, gc.Equals, 0)
c.Check(counter, jc.GreaterThan, 0)
}