package host import ( "context" "testing" "time" "github.com/carlosframework/platform/internal/hostactors" "github.com/carlosframework/platform/internal/hostbox" "github.com/carlosframework/platform/internal/hostops" "github.com/carlosframework/platform/internal/release" ) type plan9ResetListingStore struct { release.Store calls chan time.Time } func (s *plan9ResetListingStore) List(ctx context.Context, prefix string) ([]string, error) { select { case s.calls <- time.Now(): default: } return nil, ctx.Err() } func TestPlan9Fix1ResetWorkerAppliesBackoff(t *testing.T) { t.Parallel() store := &plan9ResetListingStore{Store: release.NewDirStore(t.TempDir()), calls: make(chan time.Time, 4)} identity := handoverRecoveryIdentity(t, hostbox.Actor{Box: "box-1", Enrollment: "enrollment-1", Revision: 1, Binding: "1", Region: "ie"}) a := &ClaimAssembly{Mode: "agent", Identity: identity, Claims: store, RetirementAuthority: &hostops.ProductionAuthority{Directory: hostactors.Directory{Store: store}}, Wake: &ClaimWakeAssembly{}, Launches: &hostbox.LaunchJournal{}, Close: func(context.Context) error { return nil }} if err := a.startWakeResetWorker(t.Context()); err != nil { t.Fatal(err) } defer a.Close(context.Background()) var first time.Time select { case first = <-store.calls: case <-time.After(3 * time.Second): t.Fatal("worker never listed resets") } select { case second := <-store.calls: if elapsed := second.Sub(first); elapsed < 1500*time.Millisecond { t.Fatalf("idle worker still lists every second: interval=%s", elapsed) } case <-time.After(4 * time.Second): t.Fatal("worker stopped polling instead of backing off") } }