Skip to content

Commit 542db76

Browse files
authored
test: do not wait afterRestartDelay in TestCleanup (#5446)
delay after agent restart is performed to allow agent to tear down all the processes important mainly for windows, as it prevents removing files which are in use. In TestCleanup there are no processes and we don't need to wait. Update Cleanup method to accept delay as an arg and defaulting to afterRestartDelay in prod TestCleanup speed improves depending on the os: linux: 8s -> 0.2s darwin 8s -> 0.2s windows: 60s -> 0.2s
1 parent 0d121d5 commit 542db76

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

internal/pkg/agent/application/upgrade/rollback.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,12 @@ func Rollback(ctx context.Context, log *logger.Logger, c client.Client, topDirPa
6868

6969
// Cleanup removes all artifacts and files related to a specified version.
7070
func Cleanup(log *logger.Logger, topDirPath, currentVersionedHome, currentHash string, removeMarker, keepLogs bool) error {
71+
return cleanup(log, topDirPath, currentVersionedHome, currentHash, removeMarker, keepLogs, afterRestartDelay)
72+
}
73+
74+
func cleanup(log *logger.Logger, topDirPath, currentVersionedHome, currentHash string, removeMarker, keepLogs bool, delay time.Duration) error {
7175
log.Infow("Cleaning up upgrade", "hash", currentHash, "remove_marker", removeMarker)
72-
<-time.After(afterRestartDelay)
76+
<-time.After(delay)
7377

7478
// data directory path
7579
dataDirPath := paths.DataFrom(topDirPath)

internal/pkg/agent/application/upgrade/rollback_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func TestCleanup(t *testing.T) {
215215
require.NoError(t, err, "error loading update marker")
216216
require.NotNil(t, marker, "loaded marker must not be nil")
217217
t.Logf("Loaded update marker %+v", marker)
218-
tt.wantErr(t, Cleanup(testLogger, testTop, marker.VersionedHome, marker.Hash, tt.args.removeMarker, tt.args.keepLogs), fmt.Sprintf("Cleanup(%v, %v, %v, %v)", marker.VersionedHome, marker.Hash, tt.args.removeMarker, tt.args.keepLogs))
218+
tt.wantErr(t, cleanup(testLogger, testTop, marker.VersionedHome, marker.Hash, tt.args.removeMarker, tt.args.keepLogs, 0), fmt.Sprintf("Cleanup(%v, %v, %v, %v)", marker.VersionedHome, marker.Hash, tt.args.removeMarker, tt.args.keepLogs))
219219
tt.checkAfterCleanup(t, testTop)
220220
})
221221
}

0 commit comments

Comments
 (0)