MCPcopy Create free account
hub / github.com/coder/coder / TestLatestBuildFailed

Function TestLatestBuildFailed

coderd/prebuilds/preset_snapshot_test.go:878–960  ·  view source on GitHub ↗

If the latest build failed, backoff exponentially with the given interval.

(t *testing.T)

Source from the content-addressed store, hash-verified

876
877// If the latest build failed, backoff exponentially with the given interval.
878func TestLatestBuildFailed(t *testing.T) {
879 t.Parallel()
880 current := opts[optionSet0]
881 other := opts[optionSet1]
882 clock := quartz.NewMock(t)
883
884 // GIVEN: two presets.
885 presets := []database.GetTemplatePresetsWithPrebuildsRow{
886 preset(true, 1, current),
887 preset(true, 1, other),
888 }
889
890 // GIVEN: running prebuilds only for one preset (the other will be failing, as evidenced by the backoffs below).
891 running := []database.GetRunningPrebuiltWorkspacesRow{
892 prebuiltWorkspace(other, clock),
893 }
894
895 // GIVEN: NO prebuilds in progress.
896 var inProgress []database.CountInProgressPrebuildsRow
897
898 // GIVEN: a backoff entry.
899 lastBuildTime := clock.Now()
900 numFailed := 1
901 backoffs := []database.GetPresetsBackoffRow{
902 {
903 TemplateVersionID: current.templateVersionID,
904 PresetID: current.presetID,
905 NumFailed: int32(numFailed),
906 LastBuildAt: lastBuildTime,
907 },
908 }
909
910 // WHEN: calculating the current preset's state.
911 snapshot := prebuilds.NewGlobalSnapshot(presets, nil, running, inProgress, nil, backoffs, nil, clock, testutil.Logger(t))
912 psCurrent, err := snapshot.FilterByPreset(current.presetID)
913 require.NoError(t, err)
914
915 // THEN: reconciliation should backoff.
916 state := psCurrent.CalculateState()
917 actions, err := psCurrent.CalculateActions(backoffInterval)
918 require.NoError(t, err)
919 validateState(t, prebuilds.ReconciliationState{
920 Actual: 0, Desired: 1,
921 }, *state)
922 validateActions(t, []*prebuilds.ReconciliationActions{
923 {
924 ActionType: prebuilds.ActionTypeBackoff,
925 BackoffUntil: lastBuildTime.Add(time.Duration(numFailed) * backoffInterval),
926 },
927 }, actions)
928
929 // WHEN: calculating the other preset's state.
930 psOther, err := snapshot.FilterByPreset(other.presetID)
931 require.NoError(t, err)
932
933 // THEN: it should NOT be in backoff because all is OK.
934 state = psOther.CalculateState()
935 actions, err = psOther.CalculateActions(backoffInterval)

Callers

nothing calls this directly

Calls 11

FilterByPresetMethod · 0.95
NewGlobalSnapshotFunction · 0.92
LoggerFunction · 0.92
presetFunction · 0.85
prebuiltWorkspaceFunction · 0.85
validateStateFunction · 0.85
validateActionsFunction · 0.85
CalculateStateMethod · 0.80
DurationMethod · 0.80
AddMethod · 0.65
CalculateActionsMethod · 0.45

Tested by

no test coverage detected