A new template version is created with a preset with prebuilds configured; while a prebuild is provisioning up or down, the calculated actions should indicate the state correctly.
(t *testing.T)
| 307 | // A new template version is created with a preset with prebuilds configured; while a prebuild is provisioning up or down, |
| 308 | // the calculated actions should indicate the state correctly. |
| 309 | func TestInProgressActions(t *testing.T) { |
| 310 | t.Parallel() |
| 311 | current := opts[optionSet0] |
| 312 | clock := quartz.NewMock(t) |
| 313 | |
| 314 | cases := []struct { |
| 315 | name string |
| 316 | transition database.WorkspaceTransition |
| 317 | desired int32 |
| 318 | running int32 |
| 319 | inProgress int32 |
| 320 | checkFn func(state prebuilds.ReconciliationState, actions []*prebuilds.ReconciliationActions) |
| 321 | }{ |
| 322 | // With no running prebuilds and one starting, no creations/deletions should take place. |
| 323 | { |
| 324 | name: fmt.Sprintf("%s-short", database.WorkspaceTransitionStart), |
| 325 | transition: database.WorkspaceTransitionStart, |
| 326 | desired: 1, |
| 327 | running: 0, |
| 328 | inProgress: 1, |
| 329 | checkFn: func(state prebuilds.ReconciliationState, actions []*prebuilds.ReconciliationActions) { |
| 330 | validateState(t, prebuilds.ReconciliationState{Desired: 1, Starting: 1}, state) |
| 331 | validateActions(t, nil, actions) |
| 332 | }, |
| 333 | }, |
| 334 | // With one running prebuild and one starting, no creations/deletions should occur since we're approaching the correct state. |
| 335 | { |
| 336 | name: fmt.Sprintf("%s-balanced", database.WorkspaceTransitionStart), |
| 337 | transition: database.WorkspaceTransitionStart, |
| 338 | desired: 2, |
| 339 | running: 1, |
| 340 | inProgress: 1, |
| 341 | checkFn: func(state prebuilds.ReconciliationState, actions []*prebuilds.ReconciliationActions) { |
| 342 | validateState(t, prebuilds.ReconciliationState{Actual: 1, Desired: 2, Starting: 1}, state) |
| 343 | validateActions(t, nil, actions) |
| 344 | }, |
| 345 | }, |
| 346 | // With one running prebuild and one starting, no creations/deletions should occur |
| 347 | // SIDE-NOTE: once the starting prebuild completes, the older of the two will be considered extraneous since we only desire 2. |
| 348 | { |
| 349 | name: fmt.Sprintf("%s-extraneous", database.WorkspaceTransitionStart), |
| 350 | transition: database.WorkspaceTransitionStart, |
| 351 | desired: 2, |
| 352 | running: 2, |
| 353 | inProgress: 1, |
| 354 | checkFn: func(state prebuilds.ReconciliationState, actions []*prebuilds.ReconciliationActions) { |
| 355 | validateState(t, prebuilds.ReconciliationState{Actual: 2, Desired: 2, Starting: 1}, state) |
| 356 | validateActions(t, nil, actions) |
| 357 | }, |
| 358 | }, |
| 359 | // With one prebuild desired and one stopping, a new prebuild will be created. |
| 360 | { |
| 361 | name: fmt.Sprintf("%s-short", database.WorkspaceTransitionStop), |
| 362 | transition: database.WorkspaceTransitionStop, |
| 363 | desired: 1, |
| 364 | running: 0, |
| 365 | inProgress: 1, |
| 366 | checkFn: func(state prebuilds.ReconciliationState, actions []*prebuilds.ReconciliationActions) { |
nothing calls this directly
no test coverage detected