fix random failure in test cases

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2025-10-10 20:15:24 +02:00
parent f21c3d2af2
commit 90685d8ef2

View File

@@ -8405,6 +8405,8 @@ func TestRetentionAPI(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
err = client.Chtimes(uploadPath, time.Now().Add(-48*time.Hour), time.Now().Add(-48*time.Hour)) err = client.Chtimes(uploadPath, time.Now().Add(-48*time.Hour), time.Now().Add(-48*time.Hour))
assert.NoError(t, err) assert.NoError(t, err)
conn.Close()
client.Close()
} }
// remove delete permissions to the user, it will be automatically granted // remove delete permissions to the user, it will be automatically granted
@@ -8415,9 +8417,6 @@ func TestRetentionAPI(t *testing.T) {
conn, client, err = getSftpClient(user) conn, client, err = getSftpClient(user)
if assert.NoError(t, err) { if assert.NoError(t, err) {
defer conn.Close()
defer client.Close()
innerUploadFilePath := path.Join("/"+testDir, testDir, testFileName) innerUploadFilePath := path.Join("/"+testDir, testDir, testFileName)
err = client.Mkdir(path.Join(testDir, testDir)) err = client.Mkdir(path.Join(testDir, testDir))
assert.NoError(t, err) assert.NoError(t, err)
@@ -8482,6 +8481,8 @@ func TestRetentionAPI(t *testing.T) {
_, err = client.Stat(innerUploadFilePath) _, err = client.Stat(innerUploadFilePath)
assert.ErrorIs(t, err, os.ErrNotExist) assert.ErrorIs(t, err, os.ErrNotExist)
conn.Close()
client.Close()
} }
// finally test some errors removing files or folders // finally test some errors removing files or folders
if runtime.GOOS != osWindows { if runtime.GOOS != osWindows {
@@ -8553,6 +8554,10 @@ func TestRetentionAPI(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
err = os.RemoveAll(user.GetHomeDir()) err = os.RemoveAll(user.GetHomeDir())
assert.NoError(t, err) assert.NoError(t, err)
assert.Eventually(t, func() bool {
return common.Connections.GetClientConnections() == 0
}, 1*time.Second, 50*time.Millisecond)
} }
func TestPerUserTransferLimits(t *testing.T) { func TestPerUserTransferLimits(t *testing.T) {