A prebuild is considered Expired when it has exceeded their time-to-live (TTL) specified in the preset's cache invalidation invalidate_after_secs parameter.
(t *testing.T)
| 591 | // A prebuild is considered Expired when it has exceeded their time-to-live (TTL) |
| 592 | // specified in the preset's cache invalidation invalidate_after_secs parameter. |
| 593 | func TestExpiredPrebuilds(t *testing.T) { |
| 594 | t.Parallel() |
| 595 | current := opts[optionSet3] |
| 596 | clock := quartz.NewMock(t) |
| 597 | |
| 598 | cases := []struct { |
| 599 | name string |
| 600 | running int32 |
| 601 | desired int32 |
| 602 | expired int32 |
| 603 | |
| 604 | invalidated int32 |
| 605 | |
| 606 | checkFn func(runningPrebuilds []database.GetRunningPrebuiltWorkspacesRow, state prebuilds.ReconciliationState, actions []*prebuilds.ReconciliationActions) |
| 607 | }{ |
| 608 | // With 2 running prebuilds, none of which are expired, and the desired count is met, |
| 609 | // no deletions or creations should occur. |
| 610 | { |
| 611 | name: "no expired prebuilds - no actions taken", |
| 612 | running: 2, |
| 613 | desired: 2, |
| 614 | expired: 0, |
| 615 | checkFn: func(runningPrebuilds []database.GetRunningPrebuiltWorkspacesRow, state prebuilds.ReconciliationState, actions []*prebuilds.ReconciliationActions) { |
| 616 | validateState(t, prebuilds.ReconciliationState{Actual: 2, Desired: 2, Expired: 0}, state) |
| 617 | validateActions(t, nil, actions) |
| 618 | }, |
| 619 | }, |
| 620 | // With 2 running prebuilds, 1 of which is expired, the expired prebuild should be deleted, |
| 621 | // and one new prebuild should be created to maintain the desired count. |
| 622 | { |
| 623 | name: "one expired prebuild – deleted and replaced", |
| 624 | running: 2, |
| 625 | desired: 2, |
| 626 | expired: 1, |
| 627 | checkFn: func(runningPrebuilds []database.GetRunningPrebuiltWorkspacesRow, state prebuilds.ReconciliationState, actions []*prebuilds.ReconciliationActions) { |
| 628 | expectedState := prebuilds.ReconciliationState{Actual: 2, Desired: 2, Expired: 1} |
| 629 | expectedActions := []*prebuilds.ReconciliationActions{ |
| 630 | { |
| 631 | ActionType: prebuilds.ActionTypeDelete, |
| 632 | DeleteIDs: []uuid.UUID{runningPrebuilds[0].ID}, |
| 633 | }, |
| 634 | { |
| 635 | ActionType: prebuilds.ActionTypeCreate, |
| 636 | Create: 1, |
| 637 | }, |
| 638 | } |
| 639 | |
| 640 | validateState(t, expectedState, state) |
| 641 | validateActions(t, expectedActions, actions) |
| 642 | }, |
| 643 | }, |
| 644 | // With 2 running prebuilds, both expired, both should be deleted, |
| 645 | // and 2 new prebuilds created to match the desired count. |
| 646 | { |
| 647 | name: "all prebuilds expired – all deleted and recreated", |
| 648 | running: 2, |
| 649 | desired: 2, |
| 650 | expired: 2, |
nothing calls this directly
no test coverage detected