-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommunication_test.go
More file actions
49 lines (43 loc) · 876 Bytes
/
communication_test.go
File metadata and controls
49 lines (43 loc) · 876 Bytes
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
package communication
import (
"testing"
"time"
"github.com/satori/go.uuid"
)
func TestSend(t *testing.T) {
sendCh := make(chan CommData)
receiveCh, connStatus := Run(sendCh)
go RunPrintConn(connStatus)
go RunPrintMsg(receiveCh)
time.Sleep(1 * time.Second)
count := 0
for{
msgID := uuid.NewV4()
msg := ResolveMsg("10.20.78.108", msgID.String(), "Test", count)
sendCh <- *msg
time.Sleep(10 * time.Second)
count += 1
}
}
func TestListen(t *testing.T) {
sendCh := make(chan CommData)
receiveCh, connStatus := Run(sendCh)
go RunPrintConn(connStatus)
go RunPrintMsg(receiveCh)
time.Sleep(1 * time.Second)
count := 0
for{
time.Sleep(10 * time.Second)
count += 1
}
}
func RunPrintMsg(receiveCh <-chan CommData) {
for{
PrintMessage(<- receiveCh)
}
}
func RunPrintConn(connStatus <-chan ConnData) {
for{
PrintConnData(<- connStatus)
}
}