Files
traefik-selectel/internal/reconciler/loop_test.go
T
vasyanskandClaude Sonnet 5 273cd54415
Build / Tests (push) Successful in 13s
Build / Build image (push) Failing after 15s
Build / Notify on failure (push) Failing after 0s
feat: traefik-selectel-dns — A-записи Selectel по роутам Traefik + CI сборка образа
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-21 21:50:07 +07:00

41 lines
1.0 KiB
Go

package reconciler
import (
"context"
"sync/atomic"
"testing"
"time"
"github.com/realmanual/traefik-selectel/internal/traefik"
)
func TestRunTicksAndTriggers(t *testing.T) {
e := newEnv(nil)
e.src.routers = []traefik.Router{router("a", "Host(`app.example.com`)", "enabled")}
trigger := make(chan struct{}, 1)
var cycles int32
ctx, cancel := context.WithCancel(context.Background())
done := make(chan struct{})
go func() {
e.rec.Run(ctx, time.Hour, 5*time.Millisecond, trigger, func(Result, error) { atomic.AddInt32(&cycles, 1) })
close(done)
}()
waitCycles := func(n int32) {
deadline := time.Now().Add(3 * time.Second)
for atomic.LoadInt32(&cycles) < n {
if time.Now().After(deadline) {
t.Fatalf("ожидали %d циклов, было %d", n, atomic.LoadInt32(&cycles))
}
time.Sleep(5 * time.Millisecond)
}
}
waitCycles(1) // стартовый
trigger <- struct{}{}
waitCycles(2)
cancel()
<-done
if len(e.dns.created) != 1 {
t.Fatalf("created = %v", e.dns.created)
}
}