-
Notifications
You must be signed in to change notification settings - Fork 5
/
grpc_test.go
50 lines (39 loc) · 1.05 KB
/
grpc_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
package sqsd
import (
"context"
"fmt"
"net"
"strconv"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)
func TestGRPC(t *testing.T) {
l, err := net.Listen("tcp4", ":0")
assert.NoError(t, err)
assert.NotNil(t, l)
port, err := strconv.Atoi(strings.Split(l.Addr().String(), ":")[1])
assert.NoError(t, err)
l.Close()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
msgsCh := make(chan Message, 1)
worker := startWorker(ctx, nil, msgsCh, nil)
monitor := NewMonitoringService(worker)
grpcServer, err := newGRPCServer(monitor, port)
assert.NoError(t, err)
grpcServer.Start()
defer grpcServer.Stop()
conn, err := grpc.Dial(
fmt.Sprintf("localhost:%d", port),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock(),
)
assert.NoError(t, err)
client := NewMonitoringServiceClient(conn)
resp, err := client.CurrentWorkings(context.Background(), &CurrentWorkingsRequest{})
assert.NoError(t, err)
assert.NotNil(t, resp)
}