41 lines
1.0 KiB
Go
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)
|
|
}
|
|
}
|