-
Notifications
You must be signed in to change notification settings - Fork 3
/
msg_test.go
47 lines (45 loc) · 815 Bytes
/
msg_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
package msg
import (
"github.com/hslam/ftok"
"strings"
"testing"
"time"
)
func TestMsg(t *testing.T) {
context := strings.Repeat("1", 128)
done := make(chan struct{})
go func() {
key, err := ftok.Ftok("/tmp", 0x22)
if err != nil {
panic(err)
}
msgid, err := Get(key, IPC_CREAT|0600)
if err != nil {
panic(err)
}
defer Remove(msgid)
err = Send(msgid, 1, []byte(context), 0600)
if err != nil {
panic(err)
}
time.Sleep(time.Millisecond * 200)
close(done)
}()
time.Sleep(time.Millisecond * 100)
key, err := ftok.Ftok("/tmp", 0x22)
if err != nil {
panic(err)
}
msgid, err := Get(key, 0600)
if err != nil {
panic(err)
}
text, err := Receive(msgid, 1, 0600)
if err != nil {
panic(err)
}
if context != string(text) {
t.Error(context, string(text))
}
<-done
}