Skip to content

Commit

Permalink
Change time.Sleep to ctx select with time.After for support ctx.Done …
Browse files Browse the repository at this point in the history
…via api

Change test waiting value due new watch logic
  • Loading branch information
Alexey Kostin committed Dec 29, 2023
1 parent 1189360 commit ddee54b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion pkg/backup/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit ddee54b

Please sign in to comment.