From ddee54b8a6d23874a66cc8779d5e53b68e0912ea Mon Sep 17 00:00:00 2001 From: Alexey Kostin Date: Fri, 29 Dec 2023 18:49:35 +0300 Subject: [PATCH] Change time.Sleep to ctx select with time.After for support ctx.Done via api Change test waiting value due new watch logic --- pkg/backup/watch.go | 6 +++++- test/integration/integration_test.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/backup/watch.go b/pkg/backup/watch.go index d616af86..d1bc9b19 100644 --- a/pkg/backup/watch.go +++ b/pkg/backup/watch.go @@ -115,7 +115,11 @@ func (b *Backuper) Watch(watchInterval, fullInterval, watchBackupNameTemplate, t b.log.Infof("Time before do full backup %v", timeBeforeDoFullBackup) if timeBeforeDoBackup > 0 && timeBeforeDoFullBackup > 0 { b.log.Infof("Waiting %d seconds until continue doing backups due watch interval", timeBeforeDoBackup) - time.Sleep(b.cfg.General.WatchDuration - now.Sub(lastBackup)) + select { + case <-ctx.Done(): + return ctx.Err() + case <-time.After(b.cfg.General.WatchDuration - now.Sub(lastBackup)): + } } now = time.Now() lastBackup = now diff --git a/test/integration/integration_test.go b/test/integration/integration_test.go index d8baa094..78e5f54a 100644 --- a/test/integration/integration_test.go +++ b/test/integration/integration_test.go @@ -785,7 +785,7 @@ func testAPIWatchAndKill(r *require.Assertions, ch *TestClickHouse) { r.NoError(err) time.Sleep(7 * time.Second) - checkWatchBackup(2) + checkWatchBackup(1) runKillCommand("watch") checkCanceledCommand(2) }