forked from myzhan/boomer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
legacy_test.go
56 lines (49 loc) · 1.69 KB
/
legacy_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
package boomer
import (
"testing"
)
func TestConvertResponseTime(t *testing.T) {
convertedFloat := convertResponseTime(float64(1.234))
convertedInt64 := convertResponseTime(int64(2))
if convertedFloat != 1 {
t.Error("Failed to convert responseTime from float64")
}
if convertedInt64 != 2 {
t.Error("Failed to convert responseTime from int64")
}
defer func() {
if r := recover(); r == nil {
t.Error("It should panic")
}
}()
// It should panic
convertResponseTime(1)
}
func TestInitEvents(t *testing.T) {
initLegacyEventHandlers()
defer Events.Unsubscribe("request_success", legacySuccessHandler)
defer Events.Unsubscribe("request_failure", legacyFailureHandler)
masterHost := "127.0.0.1"
masterPort := 5557
defaultBoomer = NewBoomer(masterHost, masterPort)
defaultBoomer.slaveRunner = newSlaveRunner(masterHost, masterPort, nil, nil)
Events.Publish("request_success", "http", "foo", int64(1), int64(10))
Events.Publish("request_failure", "udp", "bar", int64(2), "udp error")
requestSuccessMsg := <-defaultBoomer.slaveRunner.stats.requestSuccessChan
if requestSuccessMsg.requestType != "http" {
t.Error("Expected: http, got:", requestSuccessMsg.requestType)
}
if requestSuccessMsg.responseTime != int64(1) {
t.Error("Expected: 1, got:", requestSuccessMsg.responseTime)
}
requestFailureMsg := <-defaultBoomer.slaveRunner.stats.requestFailureChan
if requestFailureMsg.requestType != "udp" {
t.Error("Expected: udp, got:", requestFailureMsg.requestType)
}
if requestFailureMsg.responseTime != int64(2) {
t.Error("Expected: 2, got:", requestFailureMsg.responseTime)
}
if requestFailureMsg.error != "udp error" {
t.Error("Expected: udp error, got:", requestFailureMsg.error)
}
}