-
Notifications
You must be signed in to change notification settings - Fork 54
/
server_test.go
67 lines (61 loc) · 1.35 KB
/
server_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
62
63
64
65
66
67
package ch
import (
"context"
"net"
"testing"
"github.com/go-faster/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
"github.com/ClickHouse/ch-go/cht"
"github.com/ClickHouse/ch-go/internal/ztest"
)
func TestServer_Serve(t *testing.T) {
t.Skip("Server is not implemented")
cht.Skip(t)
ln, err := net.Listen("tcp", "127.0.0.1:0")
require.NoError(t, err)
lg := ztest.NewLogger(t)
done := make(chan struct{})
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
g, ctx := errgroup.WithContext(ctx)
s := NewServer(ServerOptions{
Logger: lg.Named("srv"),
OnError: func(err error) {
assert.NoError(t, err, "server error")
cancel()
},
})
g.Go(func() error {
defer close(done)
c, err := Dial(ctx, Options{
Logger: lg.Named("usr"),
Address: ln.Addr().String(),
})
if err != nil {
return errors.Wrap(err, "dial")
}
if err := c.Ping(ctx); err != nil {
return errors.Wrap(err, "ping")
}
if err := c.Do(ctx, Query{Body: "HELLO"}); err != nil {
return errors.Wrap(err, "query")
}
return c.Close()
})
g.Go(func() error {
<-done
return ln.Close()
})
g.Go(func() error {
if err := s.Serve(ln); err != nil {
if errors.Is(err, net.ErrClosed) {
return nil
}
return err
}
return nil
})
require.NoError(t, g.Wait())
}