| index be70abdde..a1eaa3479 100644 |
| --- a/internal/console/fleetrelabel_test.go |
| +++ b/internal/console/fleetrelabel_test.go |
| @@ -362,7 +362,7 @@ func TestDrainDoneNeedsAPostDrainHeartbeat(t *testing.T) { |
| if drainDone(empty, since) { |
| t.Fatal("an empty heartbeat composed before the drain is done") |
| } |
| - empty.GeneratedAt = since.Add(time.Second) |
| + empty.GeneratedAt = since.Add(3 * time.Minute) |
| if !drainDone(empty, since) { |
| t.Fatal("an empty heartbeat composed after the drain is not done") |
| } |
| @@ -392,9 +392,24 @@ func TestDrainDoneNeedsAPostDrainHeartbeat(t *testing.T) { |
| } |
| } |
| |
| +// Controller ruling (concern 5): boxes run NTP, but a box clock running |
| +// ahead must not pass a heartbeat composed before the drain, so the |
| +// heartbeat must be composed drainSkewMargin after the drain began. |
| +func TestDrainDoneAllowsForClockSkew(t *testing.T) { |
| + since := time.Now() |
| + hb := status.Box{GeneratedAt: since.Add(time.Minute), Metrics: &status.BoxMetrics{Release: release.FleetBoxLabelFloor}} |
| + if drainDone(hb, since) { |
| + t.Fatal("an empty heartbeat composed 1 minute after the drain is done") |
| + } |
| + hb.GeneratedAt = since.Add(3 * time.Minute) |
| + if !drainDone(hb, since) { |
| + t.Fatal("an empty heartbeat composed 3 minutes after the drain is not done") |
| + } |
| +} |
| + |
| func TestDrainDoneNeedsNoLeases(t *testing.T) { |
| since := time.Now() |
| - hb := status.Box{GeneratedAt: since.Add(time.Minute), LeasesHeld: 1, Metrics: &status.BoxMetrics{Release: release.FleetBoxLabelFloor}} |
| + hb := status.Box{GeneratedAt: since.Add(3 * time.Minute), LeasesHeld: 1, Metrics: &status.BoxMetrics{Release: release.FleetBoxLabelFloor}} |
| if drainDone(hb, since) { |
| t.Fatal("no routes but one lease held is done") |
| } |
| @@ -446,12 +461,12 @@ func TestDrainDoneNeedsNoFailedReplication(t *testing.T) { |
| // The box stopped a.example.com and released its lease, but the final |
| // sync failed (the box half: TestFailedFinalSyncIsReportedUntilReplicated, |
| // internal/activator): it reports 1. |
| - beat(t, fx, "pi-1", time.Now().Add(time.Second), func(b *status.Box) { b.ReplicationFailures = 1 }) |
| + beat(t, fx, "pi-1", time.Now().Add(3*time.Minute), func(b *status.Box) { b.ReplicationFailures = 1 }) |
| if code, raw := detachAPI(t, fx, token, "pi-1"); code != http.StatusConflict || errorOf(t, raw) != msgDetachNotDrained("pi", "pi-1") { |
| t.Fatalf("detach with a failed final sync = %d %s; want 409", code, raw) |
| } |
| // A later replication landed and cleared it. |
| - beat(t, fx, "pi-1", time.Now().Add(2*time.Second), nil) |
| + beat(t, fx, "pi-1", time.Now().Add(4*time.Minute), nil) |
| if code, raw := detachAPI(t, fx, token, "pi-1"); code != http.StatusOK { |
| t.Fatalf("detach of a drained box = %d %s", code, raw) |
| } |
| @@ -501,14 +516,14 @@ func TestBothDetachDoorsUseDrainDone(t *testing.T) { |
| return strings.Contains(body, "Detached pi/pi-1."), body |
| } |
| // A post-drain heartbeat that still holds a lease. |
| - beat(t, fx, "pi-1", time.Now().Add(time.Second), func(b *status.Box) { b.LeasesHeld = 1 }) |
| + beat(t, fx, "pi-1", time.Now().Add(3*time.Minute), func(b *status.Box) { b.LeasesHeld = 1 }) |
| if ok, said := detach(); ok || !strings.Contains(said, msgDetachNotDrained("pi", "pi-1")) { |
| t.Fatalf("detach while a lease is held: ok %v\n%s", ok, said) |
| } |
| if b := boxRow(t, reg, "pi-1"); b.Status != "active" { |
| t.Fatal("a refused detach detached the box") |
| } |
| - beat(t, fx, "pi-1", time.Now().Add(2*time.Second), nil) |
| + beat(t, fx, "pi-1", time.Now().Add(4*time.Minute), nil) |
| if ok, said := detach(); !ok { |
| t.Fatalf("detach of a drained box refused:\n%s", said) |
| } |