|
|
@ -11,7 +11,7 @@ type TestMsg struct {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type testConnection struct {
|
|
|
|
type testConnection struct {
|
|
|
|
server *MsgConn
|
|
|
|
server *MsgServer
|
|
|
|
client *MsgConn
|
|
|
|
client *MsgConn
|
|
|
|
wg sync.WaitGroup
|
|
|
|
wg sync.WaitGroup
|
|
|
|
called bool
|
|
|
|
called bool
|
|
|
@ -27,27 +27,23 @@ const testSocket = "@test"
|
|
|
|
var testFactory = NewMsgFactory(new(TestMsg))
|
|
|
|
var testFactory = NewMsgFactory(new(TestMsg))
|
|
|
|
|
|
|
|
|
|
|
|
func testConnect(handler func(*TestMsg, *Message) error) (*testConnection, error) {
|
|
|
|
func testConnect(handler func(*TestMsg, *Message) error) (*testConnection, error) {
|
|
|
|
s := NewMsgConn(testFactory, testSocket)
|
|
|
|
tc := &testConnection{}
|
|
|
|
c := NewMsgConn(testFactory, testSocket)
|
|
|
|
|
|
|
|
tc := &testConnection{
|
|
|
|
|
|
|
|
server: s,
|
|
|
|
|
|
|
|
client: c,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
wrapper := func(tm *TestMsg, msg *Message) error {
|
|
|
|
wrapper := func(tm *TestMsg, msg *Message) error {
|
|
|
|
err := handler(tm, msg)
|
|
|
|
err := handler(tm, msg)
|
|
|
|
tc.called = true
|
|
|
|
tc.called = true
|
|
|
|
tc.wg.Done()
|
|
|
|
tc.wg.Done()
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := s.AddHandlers(wrapper); err != nil {
|
|
|
|
s,err := NewServer(testSocket, testFactory, nil, wrapper)
|
|
|
|
return nil, err
|
|
|
|
if err != nil {
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := s.Listen(); err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := c.Connect(); err != nil {
|
|
|
|
c,err := Connect(testSocket, testFactory, nil)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tc.server = s
|
|
|
|
|
|
|
|
tc.client = c
|
|
|
|
tc.wg.Add(1)
|
|
|
|
tc.wg.Add(1)
|
|
|
|
go tc.server.Run()
|
|
|
|
go tc.server.Run()
|
|
|
|
return tc, nil
|
|
|
|
return tc, nil
|
|
|
|