forked from porthos-rpc/porthos-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics_test.go
50 lines (39 loc) · 1.46 KB
/
metrics_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
package porthos
import (
"os"
"testing"
"time"
)
func TestMetricsShipperExtension(t *testing.T) {
b, _ := NewBroker(os.Getenv("AMQP_URL"))
ext, err := NewMetricsShipperExtension(b, MetricsShipperConfig{BufferSize: 2})
if err != nil {
t.Error(err)
}
ext.OutgoingResponse(&request{serviceName: "SampleService", methodName: "test1"}, &response{}, 4*time.Millisecond, 200)
ext.OutgoingResponse(&request{serviceName: "SampleService", methodName: "test2"}, &response{}, 5*time.Millisecond, 201)
ext.OutgoingResponse(&request{serviceName: "SampleService", methodName: "test2"}, &response{}, 6*time.Millisecond, 201)
ext.OutgoingResponse(&request{serviceName: "SampleService", methodName: "test3"}, &response{}, 7*time.Millisecond, 202)
ext.OutgoingResponse(&request{serviceName: "SampleService", methodName: "test4"}, &response{}, 8*time.Millisecond, 200)
ext.OutgoingResponse(&request{serviceName: "SampleService", methodName: "test4"}, &response{}, 9*time.Millisecond, 200)
ch, _ := b.openChannel()
dc, _ := ch.Consume(
"porthos.metrics", // queue
"", // consumer
true, // auto-ack
false, // exclusive
false, // no-local
false, // no-wait
nil, // args
)
shippedMetricsCount := 0
go func() {
for range dc {
shippedMetricsCount++
}
}()
<-time.After(2 * time.Second)
if shippedMetricsCount != 3 {
t.Errorf("Excepted 3 shipped metrics, got %d", shippedMetricsCount)
}
}