File tree 2 files changed +49
-4
lines changed
2 files changed +49
-4
lines changed Original file line number Diff line number Diff line change @@ -58,9 +58,8 @@ func (s *IprotoServer) WithOptions(opts *IprotoServerOptions) *IprotoServer {
58
58
opts = & IprotoServerOptions {}
59
59
}
60
60
s .perf = opts .Perf
61
- s .getPingStatus = opts .GetPingStatus
62
- if s .getPingStatus == nil {
63
- s .getPingStatus = func (* IprotoServer ) uint { return 0 }
61
+ if opts .GetPingStatus != nil {
62
+ s .getPingStatus = opts .GetPingStatus
64
63
}
65
64
return s
66
65
}
@@ -229,7 +228,9 @@ READER_LOOP:
229
228
code := packet .Cmd
230
229
if code == PingCommand {
231
230
pr := packetPool .GetWithID (packet .requestID )
232
- pr .packet .Cmd = s .getPingStatus (s )
231
+ if s .getPingStatus != nil {
232
+ pr .packet .Cmd = s .getPingStatus (s )
233
+ }
233
234
pr .packet .SchemaID = packet .SchemaID
234
235
235
236
select {
Original file line number Diff line number Diff line change
1
+ package tarantool
2
+
3
+ import (
4
+ "context"
5
+ "net"
6
+ "testing"
7
+
8
+ "github.com/stretchr/testify/assert"
9
+ "github.com/stretchr/testify/require"
10
+ )
11
+
12
+ func TestServerPing (t * testing.T ) {
13
+ handler := func (queryContext context.Context , query Query ) * Result {
14
+ return & Result {}
15
+ }
16
+
17
+ s := NewIprotoServer ("1" , handler , nil )
18
+
19
+ listenAddr := make (chan string )
20
+ go func () {
21
+ ln , err := net .Listen ("tcp" , "127.0.0.1:0" )
22
+ require .NoError (t , err )
23
+ defer ln .Close ()
24
+
25
+ listenAddr <- ln .Addr ().String ()
26
+ close (listenAddr )
27
+
28
+ conn , err := ln .Accept ()
29
+ require .NoError (t , err )
30
+
31
+ s .Accept (conn )
32
+ }()
33
+
34
+ addr := <- listenAddr
35
+ conn , err := Connect (addr , nil )
36
+ require .NoError (t , err )
37
+
38
+ res := conn .Exec (context .Background (), & Ping {})
39
+ assert .Equal (t , res .ErrorCode , OKCommand )
40
+ assert .NoError (t , res .Error )
41
+
42
+ conn .Close ()
43
+ s .Shutdown ()
44
+ }
You can’t perform that action at this time.
0 commit comments