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
No known key found for this signature in database
GPG Key ID: DAEBBD2E34C111E6
2 changed files with 7 additions and 6 deletions

View File

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

View File

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