forked from adjust/rmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats_test.go
67 lines (56 loc) · 2.55 KB
/
stats_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
package rmq
import (
"testing"
"time"
. "github.com/adjust/gocheck"
)
func TestStatsSuite(t *testing.T) {
TestingSuiteT(&StatsSuite{}, t)
}
type StatsSuite struct{}
func (suite *StatsSuite) TestStats(c *C) {
connection := OpenConnection("stats-conn", "tcp", "localhost:6379", 1, false)
c.Assert(NewCleaner(connection).Clean(), IsNil)
conn1 := OpenConnection("stats-conn1", "tcp", "localhost:6379", 1, false)
conn2 := OpenConnection("stats-conn2", "tcp", "localhost:6379", 1, false)
q1 := conn2.OpenQueue("stats-q1").(*redisQueue)
q1.PurgeReady()
q1.Publish("stats-d1", 0)
q2 := conn2.OpenQueue("stats-q2").(*redisQueue)
q2.PurgeReady()
consumer := NewTestConsumer("hand-A")
consumer.AutoAck = false
q2.StartConsuming(10, time.Millisecond)
q2.AddConsumer("stats-cons1", consumer)
q2.Publish("stats-d2", 0)
q2.Publish("stats-d3", 0)
q2.Publish("stats-d4", 0)
time.Sleep(50 * time.Millisecond)
consumer.LastDeliveries[0].Ack()
consumer.LastDeliveries[1].Reject()
q2.AddConsumer("stats-cons2", NewTestConsumer("hand-B"))
stats := CollectStats(connection.GetOpenQueues(), connection)
// log.Printf("stats\n%s", stats)
html := stats.GetHtml("", "")
c.Check(html, Matches, ".*queue.*ready.*connection.*unacked.*consumers.*q1.*1.*0.*0.*")
c.Check(html, Matches, ".*queue.*ready.*connection.*unacked.*consumers.*q2.*0.*1.*1.*2.*conn2.*1.*2.*")
stats = CollectStats([]string{"stats-q1", "stats-q2"}, connection)
for key, _ := range stats.QueueStats {
c.Check(key, Matches, "stats.*")
}
/*
<html><body><table style="font-family:monospace">
<tr><td>queue</td><td></td><td>ready</td><td></td><td>rejected</td><td></td><td style="color:lightgrey">connection</td><td></td><td>unacked</td><td></td><td>consumers</td><td></td></tr>
<tr><td>stats-q2</td><td></td><td>0</td><td></td><td>1</td><td></td><td></td><td></td><td>1</td><td></td><td>2</td><td></td></tr>
<tr style="color:lightgrey"><td></td><td></td><td></td><td></td><td></td><td></td><td>stats-conn2-vY5ZPz</td><td></td><td>1</td><td></td><td>2</td><td></td></tr>
<tr><td>stats-q1</td><td></td><td>1</td><td></td><td>0</td><td></td><td></td><td></td><td>0</td><td></td><td>0</td><td></td></tr>
<tr><td>q2</td><td></td><td>0</td><td></td><td>0</td><td></td><td></td><td></td><td>0</td><td></td><td>0</td><td></td></tr>
<tr><td>q1</td><td></td><td>0</td><td></td><td>0</td><td></td><td></td><td></td><td>0</td><td></td><td>0</td><td></td></tr>
</table></body></html>
*/
q2.StopConsuming()
connection.StopHeartbeat()
conn1.StopHeartbeat()
conn2.StopHeartbeat()
time.Sleep(1000 * time.Millisecond)
}