Skip to content

Commit 4805be7

Browse files
reconnect not yet work
1 parent a31a89d commit 4805be7

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

connection.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,12 @@ func Connect(addr string, opts Opts) (conn *Connection, err error) {
453453
}
454454

455455
func (conn *Connection) shutdownOnServerEvent() {
456+
conn.mutex.Lock()
457+
defer conn.mutex.Unlock()
458+
456459
fmt.Printf("starting shutdown...\n")
457460
conn.shutdownOn.Store(true)
461+
defer conn.shutdownOn.Store(false)
458462

459463
fmt.Printf("wait for futures to finish...\n")
460464
conn.shutdownWg.Wait()
@@ -463,11 +467,12 @@ func (conn *Connection) shutdownOnServerEvent() {
463467
// defer conn.shutdownWatcher.Unregister()
464468

465469
fmt.Printf("close the connection...\n")
466-
conn.mutex.Lock()
467-
conn.closeConnection(ClientError{ErrConnectionClosed, "connection closed after server shutdown"}, true)
468-
conn.mutex.Unlock()
470+
conn.closeConnection(
471+
ClientError{
472+
ErrConnectionClosed,
473+
"connection closed after server shutdown",
474+
}, false)
469475

470-
conn.shutdownOn.Store(false)
471476
fmt.Printf("finish shutdown...\n")
472477
}
473478

graceful_shutdown/tarantool_test.go

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,22 @@ var opts = tarantool.Opts{
2727
func TestGracefulShutdown(t *testing.T) {
2828
test_helpers.SkipIfWatchersUnsupported(t)
2929

30-
inst, err := test_helpers.StartTarantool(test_helpers.StartOpts{
30+
instOpts := test_helpers.StartOpts{
3131
InitScript: "testdata/config.lua",
3232
Listen: server,
3333
User: opts.User,
3434
Pass: opts.Pass,
3535
WaitStart: 100 * time.Millisecond,
3636
ConnectRetry: 3,
3737
RetryTimeout: 500 * time.Millisecond,
38-
})
38+
}
39+
40+
retries := uint(10)
41+
timeout := 200 * time.Millisecond
42+
opts.Reconnect = timeout
43+
opts.MaxReconnects = retries
44+
45+
inst, err := test_helpers.StartTarantool(instOpts)
3946
require.Nil(t, err)
4047

4148
conn := test_helpers.ConnectWithValidation(t, server, opts)
@@ -81,5 +88,42 @@ func TestGracefulShutdown(t *testing.T) {
8188

8289
// time.Sleep(2 * time.Second)
8390

91+
require.Equal(t, false, conn.ConnectedNow())
92+
93+
err = test_helpers.RestartTarantool(&inst)
94+
require.Nilf(t, err, "Failed to restart tarantool")
95+
96+
connected := test_helpers.WaitUntilReconnected(conn, retries, timeout)
97+
require.True(t, connected, "Reconnect success")
98+
99+
fut = conn.Do(req)
100+
fmt.Printf("test future is %v\n", fut)
101+
102+
require.Nil(t, inst.Cmd.Process.Signal(syscall.SIGTERM))
103+
104+
retrerr = test_helpers.Retry(func(interface{}) error {
105+
_, err = conn.Do(tarantool.NewPingRequest()).Get()
106+
if err == nil {
107+
return fmt.Errorf("expected error for requests sent on shutdown")
108+
}
109+
110+
if err.Error() != "instance shutdown in process" {
111+
return err
112+
}
113+
114+
return nil
115+
}, nil, 5, 100*time.Millisecond)
116+
require.Nil(t, retrerr)
117+
118+
resp, rerr = fut.Get()
119+
require.Nil(t, rerr)
120+
require.NotNil(t, resp)
121+
require.Equal(t, resp.Data, []interface{}{"nice sleep"})
122+
123+
_, err = inst.Cmd.Process.Wait()
124+
require.Nil(t, err)
125+
126+
// time.Sleep(2 * time.Second)
127+
84128
require.Equal(t, true, conn.ClosedNow())
85129
}

0 commit comments

Comments
 (0)