@@ -20,6 +20,7 @@ import (
20
20
"context"
21
21
"testing"
22
22
23
+ "github.com/stretchr/testify/require"
23
24
"github.com/z-division/go-zookeeper/zk"
24
25
25
26
"vitess.io/vitess/go/testfiles"
@@ -31,6 +32,8 @@ func TestZkConnClosedOnDisconnect(t *testing.T) {
31
32
defer zkd .Teardown ()
32
33
33
34
conn := Connect (serverAddr )
35
+ defer conn .Close ()
36
+
34
37
_ , _ , err := conn .Get (context .Background (), "/" )
35
38
if err != nil {
36
39
t .Fatalf ("Get() failed: %v" , err )
@@ -42,7 +45,7 @@ func TestZkConnClosedOnDisconnect(t *testing.T) {
42
45
43
46
oldConn := conn .conn
44
47
45
- // simulate a disconnect
48
+ // force a disconnect
46
49
zkd .Shutdown ()
47
50
zkd .Start ()
48
51
@@ -54,11 +57,9 @@ func TestZkConnClosedOnDisconnect(t *testing.T) {
54
57
55
58
// Check that old connection is closed
56
59
_ , _ , err = oldConn .Get ("/" )
57
- if err == nil {
58
- t .Fatalf ("Get() should have failed: %v" , err )
59
- }
60
+ require .ErrorContains (t , err , "zookeeper is closing" )
60
61
61
62
if oldConn .State () != zk .StateDisconnected {
62
- t .Fatalf ("Connection not closed : %v" , oldConn .State ())
63
+ t .Fatalf ("Connection is not in disconnected state : %v" , oldConn .State ())
63
64
}
64
65
}
0 commit comments