watchtower: replace defer cleanup with t.Cleanup

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun
2022-08-27 15:07:59 +08:00
parent 22cd790586
commit 228f1e36c4
2 changed files with 7 additions and 6 deletions

View File

@ -1528,8 +1528,10 @@ func TestClient(t *testing.T) {
t.Parallel() t.Parallel()
h := newHarness(t, tc.cfg) h := newHarness(t, tc.cfg)
defer h.server.Stop() t.Cleanup(func() {
defer h.client.ForceQuit() require.NoError(t, h.server.Stop())
h.client.ForceQuit()
})
tc.fn(h) tc.fn(h)
}) })

View File

@ -68,6 +68,9 @@ func initServer(t *testing.T, db wtserver.DB,
if err = s.Start(); err != nil { if err = s.Start(); err != nil {
t.Fatalf("unable to start server: %v", err) t.Fatalf("unable to start server: %v", err)
} }
t.Cleanup(func() {
require.NoError(t, s.Stop())
})
return s return s
} }
@ -83,7 +86,6 @@ func TestServerOnlyAcceptOnePeer(t *testing.T) {
const timeoutDuration = 500 * time.Millisecond const timeoutDuration = 500 * time.Millisecond
s := initServer(t, nil, timeoutDuration) s := initServer(t, nil, timeoutDuration)
defer s.Stop()
localPub := randPubKey(t) localPub := randPubKey(t)
@ -284,7 +286,6 @@ func testServerCreateSession(t *testing.T, i int, test createSessionTestCase) {
const timeoutDuration = 500 * time.Millisecond const timeoutDuration = 500 * time.Millisecond
s := initServer(t, nil, timeoutDuration) s := initServer(t, nil, timeoutDuration)
defer s.Stop()
localPub := randPubKey(t) localPub := randPubKey(t)
@ -639,7 +640,6 @@ func testServerStateUpdates(t *testing.T, test stateUpdateTestCase) {
const timeoutDuration = 100 * time.Millisecond const timeoutDuration = 100 * time.Millisecond
s := initServer(t, nil, timeoutDuration) s := initServer(t, nil, timeoutDuration)
defer s.Stop()
localPub := randPubKey(t) localPub := randPubKey(t)
@ -747,7 +747,6 @@ func TestServerDeleteSession(t *testing.T) {
const timeoutDuration = 100 * time.Millisecond const timeoutDuration = 100 * time.Millisecond
s := initServer(t, db, timeoutDuration) s := initServer(t, db, timeoutDuration)
defer s.Stop()
// Create a session for peer2 so that the server's db isn't completely // Create a session for peer2 so that the server's db isn't completely
// empty. // empty.