Skip to content

Commit 90685d8

Browse files
committed
fix random failure in test cases
Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
1 parent f21c3d2 commit 90685d8

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

internal/common/protocol_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8405,6 +8405,8 @@ func TestRetentionAPI(t *testing.T) {
84058405
assert.NoError(t, err)
84068406
err = client.Chtimes(uploadPath, time.Now().Add(-48*time.Hour), time.Now().Add(-48*time.Hour))
84078407
assert.NoError(t, err)
8408+
conn.Close()
8409+
client.Close()
84088410
}
84098411

84108412
// remove delete permissions to the user, it will be automatically granted
@@ -8415,9 +8417,6 @@ func TestRetentionAPI(t *testing.T) {
84158417

84168418
conn, client, err = getSftpClient(user)
84178419
if assert.NoError(t, err) {
8418-
defer conn.Close()
8419-
defer client.Close()
8420-
84218420
innerUploadFilePath := path.Join("/"+testDir, testDir, testFileName)
84228421
err = client.Mkdir(path.Join(testDir, testDir))
84238422
assert.NoError(t, err)
@@ -8482,6 +8481,8 @@ func TestRetentionAPI(t *testing.T) {
84828481

84838482
_, err = client.Stat(innerUploadFilePath)
84848483
assert.ErrorIs(t, err, os.ErrNotExist)
8484+
conn.Close()
8485+
client.Close()
84858486
}
84868487
// finally test some errors removing files or folders
84878488
if runtime.GOOS != osWindows {
@@ -8553,6 +8554,10 @@ func TestRetentionAPI(t *testing.T) {
85538554
assert.NoError(t, err)
85548555
err = os.RemoveAll(user.GetHomeDir())
85558556
assert.NoError(t, err)
8557+
8558+
assert.Eventually(t, func() bool {
8559+
return common.Connections.GetClientConnections() == 0
8560+
}, 1*time.Second, 50*time.Millisecond)
85568561
}
85578562

85588563
func TestPerUserTransferLimits(t *testing.T) {

0 commit comments

Comments
 (0)