package host import ( "context" "errors" "testing" ) // The domains pass is a housekeeper duty since multi-region: N platform boxes // carry PLATFORM_APPS_DOMAIN, and only the lease holder may reconcile // deployment-wide domain state (agent.go, domainsDuty). func TestDomainsDutyRunsThePassAndPropagatesItsError(t *testing.T) { quietLog(t) ran := 0 boom := errors.New("reconcile failed") duty := domainsDuty(func(context.Context) error { ran++; return boom }) if err := duty.run(context.Background()); !errors.Is(err, boom) { t.Fatalf("duty error = %v, want the pass's error propagated to the housekeeper log", err) } if ran != 1 { t.Fatalf("pass ran %d times, want 1", ran) } if duty.name != "domains reconcile" { t.Fatalf("duty name = %q, want the housekeeper log label", duty.name) } } func TestDomainsDutyWithNoPassDeclines(t *testing.T) { quietLog(t) if err := domainsDuty(nil).run(context.Background()); err != nil { t.Fatalf("duty with a nil pass returned %v, want nil (and no panic)", err) } } // The gate pin: a box that does not hold the lease never runs the pass — // that is what makes PLATFORM_APPS_DOMAIN safe to set on every box. func TestDomainsDutyNeverRunsWhenLeaseNotHeld(t *testing.T) { quietLog(t) ran := 0 duty := domainsDuty(func(context.Context) error { ran++; return nil }) notHeld := func() (context.Context, bool) { return nil, false } held := func() (context.Context, bool) { return context.Background(), true } runHousekeeperDuties(notHeld, duty) if ran != 0 { t.Fatalf("pass ran %d times without the lease, want 0", ran) } runHousekeeperDuties(held, duty) if ran != 1 { t.Fatalf("pass ran %d times with the lease, want 1", ran) } }