-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlong_running_test.go
61 lines (54 loc) · 1.49 KB
/
long_running_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//go:build long
package goomerang_test
import (
"context"
"sync"
"testing"
"time"
"go.eloylp.dev/kit/exec"
"go.eloylp.dev/goomerang/client"
"go.eloylp.dev/goomerang/example/protos"
"go.eloylp.dev/goomerang/internal/test"
"go.eloylp.dev/goomerang/message"
"go.eloylp.dev/goomerang/server"
)
func TestNoErrorsTransferringMessages(t *testing.T) {
t.Parallel()
// Server
serverArbiter := test.NewArbiter(t)
s, run := Server(t, server.WithOnErrorHook(noErrorHook(serverArbiter)))
s.Handle(defaultMsg().Payload, message.HandlerFunc(func(sender message.Sender, msg *message.Message) {
reply := &protos.ReplyV1{
Message: "return back !",
}
if _, err := sender.Send(message.New().SetPayload(reply)); err != nil {
serverArbiter.ErrorHappened(err)
}
}))
run()
defer s.Shutdown(defaultCtx)
// Client
clientArbiter := test.NewArbiter(t)
c, connect := Client(t,
client.WithServerAddr(s.Addr()),
client.WithOnErrorHook(noErrorHook(clientArbiter)),
)
c.Handle(&protos.ReplyV1{}, nilHandler)
connect()
defer c.Close(defaultCtx)
// Start sending messages
ctx, cancel := context.WithTimeout(defaultCtx, 10*time.Second)
defer cancel()
wg := &sync.WaitGroup{}
exec.Parallelize(ctx, wg, 10, func() {
if _, err := c.Send(message.New().SetPayload(&protos.MessageV1{
Message: "a message !",
})); err != nil {
serverArbiter.ErrorHappened(err)
}
})
wg.Wait()
// Ensure no errors took place in the entire execution.
serverArbiter.RequireNoErrors()
clientArbiter.RequireNoErrors()
}