Fix tests

This commit is contained in:
9seconds
2026-02-24 13:58:16 +01:00
parent 8b34c1b104
commit 5b91edf5c4
6 changed files with 95 additions and 109 deletions
+29 -21
View File
@@ -2,38 +2,46 @@ package dc
import (
"context"
"sync"
"time"
)
type updater struct {
wg sync.WaitGroup
logger Logger
period time.Duration
}
func (u updater) run(ctx context.Context, callback func() error) {
ticker := time.NewTicker(u.period)
func (u *updater) Wait() {
u.wg.Wait()
}
defer func() {
ticker.Stop()
func (u *updater) run(ctx context.Context, callback func() error) {
u.wg.Go(func() {
ticker := time.NewTicker(u.period)
select {
case <-ticker.C:
default:
}
}()
defer func() {
ticker.Stop()
select {
case <-ticker.C:
default:
}
}()
for {
u.logger.Info("start update")
if err := callback(); err != nil {
u.logger.WarningError("cannot update: %w", err)
}
u.logger.Info("updated")
for {
u.logger.Info("start update")
if err := callback(); err != nil {
u.logger.WarningError("cannot update: %w", err)
}
u.logger.Info("updated")
select {
case <-ctx.Done():
u.logger.Info("stop updating")
return
case <-ticker.C:
select {
case <-ctx.Done():
u.logger.Info("stop updating")
return
case <-ticker.C:
}
}
}
})
}