-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsync_test.go
40 lines (31 loc) · 1 KB
/
sync_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
//go:build integration
package goomerang_test
import (
"testing"
"github.com/stretchr/testify/require"
"go.eloylp.dev/goomerang/client"
"go.eloylp.dev/goomerang/example/protos"
"go.eloylp.dev/goomerang/internal/test"
"go.eloylp.dev/goomerang/message"
)
func TestSendSync(t *testing.T) {
arbiter := test.NewArbiter(t)
s, run := Server(t)
defer s.Shutdown(defaultCtx)
s.Handle(defaultMsg().Payload, message.HandlerFunc(func(s message.Sender, msg *message.Message) {
m := message.New().SetPayload(&protos.ReplyV1{Message: "pong !"})
if _, err := s.Send(m); err != nil {
arbiter.ErrorHappened(err)
}
}))
run()
c, connect := Client(t, client.WithServerAddr(s.Addr()))
connect()
defer c.Close(defaultCtx)
c.RegisterMessage(&protos.ReplyV1{})
msg := message.New().SetPayload(&protos.MessageV1{Message: "ping"})
payloadSize, reply, err := c.SendSync(defaultCtx, msg)
require.NoError(t, err)
require.NotEmpty(t, payloadSize)
require.Equal(t, "pong !", reply.Payload.(*protos.ReplyV1).Message)
}