forked from toorop/go-bittrex
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathws_test.go
85 lines (75 loc) · 1.4 KB
/
ws_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package bittrex
import (
"errors"
"testing"
"time"
)
const (
API_KEY = ""
API_SECRET = ""
MSG_COUNT = 10
TIMEOUT = 10 //seconds
)
var markets = []string{"USDT-BTC", "USDT-ETH", "BTC-ETH", "BTC-ETC"}
func TestBittrexSubscribeMarkets(t *testing.T) {
bt := New(API_KEY, API_SECRET)
ch := make(chan ExchangeState, 16)
errCh := make(chan error)
go func() {
var msgNum, initCount int
for st := range ch {
if st.Initial {
initCount++
}
msgNum++
if msgNum >= 7 && initCount == len(markets) {
break
}
}
if initCount == len(markets) {
errCh <- nil
} else {
errCh <- errors.New("no initial message")
}
}()
go func() {
errCh <- bt.SubscribeMarkets(ch, nil, markets...)
}()
select {
case <-time.After(time.Second * TIMEOUT):
t.Error("timeout")
case err := <-errCh:
if err != nil {
t.Error(err)
}
}
}
func TestBittrexSubscribeSummaries(t *testing.T) {
bt := New(API_KEY, API_SECRET)
ch := make(chan SummaryState, 16)
errCh := make(chan error)
stopCh := make(chan bool)
go func() {
var msgNum int
for range ch {
msgNum++
if msgNum >= MSG_COUNT {
t.Log("MSG limit reached..")
stopCh <- true
break
}
}
}()
go func() {
errCh <- bt.SubscribeSummaryUpdate(ch, stopCh, markets...)
}()
select {
case <-time.After(time.Minute * 1):
stopCh <- true
t.Error("timeout")
case err := <-errCh:
if err != nil {
t.Error(err)
}
}
}