mirror of
https://github.com/hslam/msg.git
synced 2025-04-25 13:48:50 +08:00
add msg test
This commit is contained in:
parent
a9484d77e7
commit
fa1fbfb3c1
49
msg_test.go
Normal file
49
msg_test.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package msg
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/hslam/ftok"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestMsg(t *testing.T) {
|
||||||
|
context := strings.Repeat("1", maxText+1)
|
||||||
|
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)
|
||||||
|
m := &Msg{Type: 1, Text: []byte(context)}
|
||||||
|
err = Snd(msgid, m, 0600)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
time.Sleep(time.Second * 2)
|
||||||
|
close(done)
|
||||||
|
}()
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
key, err := ftok.Ftok("/tmp", 0x22)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
msgid, err := Get(key, 0600)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
m := &Msg{Type: 1}
|
||||||
|
err = Rcv(msgid, m, 0600)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if context != string(m.Text) {
|
||||||
|
t.Error(context, string(m.Text))
|
||||||
|
}
|
||||||
|
<-done
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user