refactor: extract testMinDelayConfig helper in container service tests
- commit
- b89ced45e6017f63bcac64bfbdfd9e206de21cdc
- author
- brice · · 2026-03-04 09:02 UTC
- parent
- 8582c13
- signature
- unsigned
1 file · +20 -50
M internal/usecase/container/service_test.go +20 -50
| @@ -25,6 +25,16 @@ func testContext() context.Context { | |||
| 25 | 25 | return zerowrap.WithCtx(context.Background(), zerowrap.Default()) | |
| 26 | 26 | } | |
| 27 | 27 | ||
| 28 | + | // testMinDelayConfig returns a Config with all timing delays set to 1ms, | |
| 29 | + | // suitable for unit tests that don't want to wait for real timeouts. | |
| 30 | + | func testMinDelayConfig() Config { | |
| 31 | + | return Config{ | |
| 32 | + | ReadinessDelay: time.Millisecond, | |
| 33 | + | DrainDelay: time.Millisecond, | |
| 34 | + | StabilizationDelay: time.Millisecond, | |
| 35 | + | } | |
| 36 | + | } | |
| 37 | + | ||
| 28 | 38 | func setupMetricsTest(t *testing.T) (*telemetry.Metrics, *sdkmetric.ManualReader) { | |
| 29 | 39 | t.Helper() | |
| 30 | 40 | ||
| @@ -493,11 +503,7 @@ func TestService_Deploy_ResolvesExistingFromRuntime_WhenMemoryStale(t *testing.T | |||
| 493 | 503 | eventBus := mocks.NewMockEventPublisher(t) | |
| 494 | 504 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | |
| 495 | 505 | ||
| 496 | - | config := Config{ | |
| 497 | - | ReadinessDelay: time.Millisecond, | |
| 498 | - | DrainDelay: time.Millisecond, | |
| 499 | - | StabilizationDelay: time.Millisecond, | |
| 500 | - | } | |
| 506 | + | config := testMinDelayConfig() | |
| 501 | 507 | svc := NewService(runtime, envLoader, eventBus, nil, config) | |
| 502 | 508 | svc.SetProxyCacheInvalidator(cacheInvalidator) | |
| 503 | 509 | ctx := testContext() | |
| @@ -593,11 +599,7 @@ func TestService_Deploy_SkipRedundantDeploy_GetImageIDError(t *testing.T) { | |||
| 593 | 599 | envLoader := mocks.NewMockEnvLoader(t) | |
| 594 | 600 | eventBus := mocks.NewMockEventPublisher(t) | |
| 595 | 601 | ||
| 596 | - | config := Config{ | |
| 597 | - | ReadinessDelay: time.Millisecond, | |
| 598 | - | DrainDelay: time.Millisecond, | |
| 599 | - | StabilizationDelay: time.Millisecond, | |
| 600 | - | } | |
| 602 | + | config := testMinDelayConfig() | |
| 601 | 603 | svc := NewService(runtime, envLoader, eventBus, nil, config) | |
| 602 | 604 | ctx := testContext() | |
| 603 | 605 | ||
| @@ -1839,11 +1841,7 @@ func TestService_Deploy_OrphanCleanupRemovesStaleNewContainer(t *testing.T) { | |||
| 1839 | 1841 | eventBus := mocks.NewMockEventPublisher(t) | |
| 1840 | 1842 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | |
| 1841 | 1843 | ||
| 1842 | - | config := Config{ | |
| 1843 | - | ReadinessDelay: time.Millisecond, | |
| 1844 | - | DrainDelay: time.Millisecond, | |
| 1845 | - | StabilizationDelay: time.Millisecond, | |
| 1846 | - | } | |
| 1844 | + | config := testMinDelayConfig() | |
| 1847 | 1845 | svc := NewService(runtime, envLoader, eventBus, nil, config) | |
| 1848 | 1846 | svc.SetProxyCacheInvalidator(cacheInvalidator) | |
| 1849 | 1847 | ctx := testContext() | |
| @@ -1913,11 +1911,7 @@ func TestService_Deploy_TrackedTempContainerUsesAlternateTempName(t *testing.T) | |||
| 1913 | 1911 | eventBus := mocks.NewMockEventPublisher(t) | |
| 1914 | 1912 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | |
| 1915 | 1913 | ||
| 1916 | - | config := Config{ | |
| 1917 | - | ReadinessDelay: time.Millisecond, | |
| 1918 | - | DrainDelay: time.Millisecond, | |
| 1919 | - | StabilizationDelay: time.Millisecond, | |
| 1920 | - | } | |
| 1914 | + | config := testMinDelayConfig() | |
| 1921 | 1915 | svc := NewService(runtime, envLoader, eventBus, nil, config) | |
| 1922 | 1916 | svc.SetProxyCacheInvalidator(cacheInvalidator) | |
| 1923 | 1917 | ctx := testContext() | |
| @@ -2104,11 +2098,7 @@ func TestService_Deploy_ConcurrentSameDomain(t *testing.T) { | |||
| 2104 | 2098 | eventBus := mocks.NewMockEventPublisher(t) | |
| 2105 | 2099 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | |
| 2106 | 2100 | ||
| 2107 | - | config := Config{ | |
| 2108 | - | ReadinessDelay: time.Millisecond, | |
| 2109 | - | DrainDelay: time.Millisecond, | |
| 2110 | - | StabilizationDelay: time.Millisecond, | |
| 2111 | - | } | |
| 2101 | + | config := testMinDelayConfig() | |
| 2112 | 2102 | svc := NewService(runtime, envLoader, eventBus, nil, config) | |
| 2113 | 2103 | svc.SetProxyCacheInvalidator(cacheInvalidator) | |
| 2114 | 2104 | ctx := testContext() | |
| @@ -2244,11 +2234,7 @@ func TestService_Deploy_CacheInvalidationBeforeOldContainerStop(t *testing.T) { | |||
| 2244 | 2234 | eventBus := mocks.NewMockEventPublisher(t) | |
| 2245 | 2235 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | |
| 2246 | 2236 | ||
| 2247 | - | config := Config{ | |
| 2248 | - | ReadinessDelay: time.Millisecond, | |
| 2249 | - | DrainDelay: time.Millisecond, | |
| 2250 | - | StabilizationDelay: time.Millisecond, | |
| 2251 | - | } | |
| 2237 | + | config := testMinDelayConfig() | |
| 2252 | 2238 | svc := NewService(runtime, envLoader, eventBus, nil, config) | |
| 2253 | 2239 | svc.SetProxyCacheInvalidator(cacheInvalidator) | |
| 2254 | 2240 | ctx := testContext() | |
| @@ -2325,11 +2311,7 @@ func TestService_Deploy_NilCacheInvalidator(t *testing.T) { | |||
| 2325 | 2311 | envLoader := mocks.NewMockEnvLoader(t) | |
| 2326 | 2312 | eventBus := mocks.NewMockEventPublisher(t) | |
| 2327 | 2313 | ||
| 2328 | - | config := Config{ | |
| 2329 | - | ReadinessDelay: time.Millisecond, | |
| 2330 | - | DrainDelay: time.Millisecond, | |
| 2331 | - | StabilizationDelay: time.Millisecond, | |
| 2332 | - | } | |
| 2314 | + | config := testMinDelayConfig() | |
| 2333 | 2315 | // Intentionally NOT setting cache invalidator | |
| 2334 | 2316 | svc := NewService(runtime, envLoader, eventBus, nil, config) | |
| 2335 | 2317 | ctx := testContext() | |
| @@ -2484,11 +2466,7 @@ func TestService_Deploy_DoesNotSkipWhenImageIDDiffers(t *testing.T) { | |||
| 2484 | 2466 | eventBus := mocks.NewMockEventPublisher(t) | |
| 2485 | 2467 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | |
| 2486 | 2468 | ||
| 2487 | - | config := Config{ | |
| 2488 | - | ReadinessDelay: time.Millisecond, | |
| 2489 | - | DrainDelay: time.Millisecond, | |
| 2490 | - | StabilizationDelay: time.Millisecond, | |
| 2491 | - | } | |
| 2469 | + | config := testMinDelayConfig() | |
| 2492 | 2470 | svc := NewService(runtime, envLoader, eventBus, nil, config) | |
| 2493 | 2471 | svc.SetProxyCacheInvalidator(cacheInvalidator) | |
| 2494 | 2472 | ctx := testContext() | |
| @@ -2587,11 +2565,7 @@ func TestService_Deploy_SkipRedundantDeploy_ContainerNotRunning(t *testing.T) { | |||
| 2587 | 2565 | envLoader := mocks.NewMockEnvLoader(t) | |
| 2588 | 2566 | eventBus := mocks.NewMockEventPublisher(t) | |
| 2589 | 2567 | ||
| 2590 | - | config := Config{ | |
| 2591 | - | ReadinessDelay: time.Millisecond, | |
| 2592 | - | DrainDelay: time.Millisecond, | |
| 2593 | - | StabilizationDelay: time.Millisecond, | |
| 2594 | - | } | |
| 2568 | + | config := testMinDelayConfig() | |
| 2595 | 2569 | svc := NewService(runtime, envLoader, eventBus, nil, config) | |
| 2596 | 2570 | ctx := testContext() | |
| 2597 | 2571 | ||
| @@ -2654,11 +2628,7 @@ func TestService_Deploy_OrphanCleanup_NeverKillsRunningCanonical(t *testing.T) { | |||
| 2654 | 2628 | envLoader := mocks.NewMockEnvLoader(t) | |
| 2655 | 2629 | eventBus := mocks.NewMockEventPublisher(t) | |
| 2656 | 2630 | ||
| 2657 | - | config := Config{ | |
| 2658 | - | ReadinessDelay: time.Millisecond, | |
| 2659 | - | DrainDelay: time.Millisecond, | |
| 2660 | - | StabilizationDelay: time.Millisecond, | |
| 2661 | - | } | |
| 2631 | + | config := testMinDelayConfig() | |
| 2662 | 2632 | svc := NewService(runtime, envLoader, eventBus, nil, config) | |
| 2663 | 2633 | ctx := testContext() | |
| 2664 | 2634 | ||
| @@ -25,6 +25,16 @@ func testContext() context.Context { | |||||
| 25 | return zerowrap.WithCtx(context.Background(), zerowrap.Default()) | 25 | return zerowrap.WithCtx(context.Background(), zerowrap.Default()) | ||
| 26 | } | 26 | } | ||
| 27 | 27 | ||||
| 28 | + | // testMinDelayConfig returns a Config with all timing delays set to 1ms, | |||
| 29 | + | // suitable for unit tests that don't want to wait for real timeouts. | |||
| 30 | + | func testMinDelayConfig() Config { | |||
| 31 | + | return Config{ | |||
| 32 | + | ReadinessDelay: time.Millisecond, | |||
| 33 | + | DrainDelay: time.Millisecond, | |||
| 34 | + | StabilizationDelay: time.Millisecond, | |||
| 35 | + | } | |||
| 36 | + | } | |||
| 37 | + | ||||
| 28 | func setupMetricsTest(t *testing.T) (*telemetry.Metrics, *sdkmetric.ManualReader) { | 38 | func setupMetricsTest(t *testing.T) (*telemetry.Metrics, *sdkmetric.ManualReader) { | ||
| 29 | t.Helper() | 39 | t.Helper() | ||
| 30 | 40 | ||||
| @@ -493,11 +503,7 @@ func TestService_Deploy_ResolvesExistingFromRuntime_WhenMemoryStale(t *testing.T | |||||
| 493 | eventBus := mocks.NewMockEventPublisher(t) | 503 | eventBus := mocks.NewMockEventPublisher(t) | ||
| 494 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | 504 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | ||
| 495 | 505 | ||||
| 496 | - | config := Config{ | 506 | + | config := testMinDelayConfig() |
| 497 | - | ReadinessDelay: time.Millisecond, | |||
| 498 | - | DrainDelay: time.Millisecond, | |||
| 499 | - | StabilizationDelay: time.Millisecond, | |||
| 500 | - | } | |||
| 501 | svc := NewService(runtime, envLoader, eventBus, nil, config) | 507 | svc := NewService(runtime, envLoader, eventBus, nil, config) | ||
| 502 | svc.SetProxyCacheInvalidator(cacheInvalidator) | 508 | svc.SetProxyCacheInvalidator(cacheInvalidator) | ||
| 503 | ctx := testContext() | 509 | ctx := testContext() | ||
| @@ -593,11 +599,7 @@ func TestService_Deploy_SkipRedundantDeploy_GetImageIDError(t *testing.T) { | |||||
| 593 | envLoader := mocks.NewMockEnvLoader(t) | 599 | envLoader := mocks.NewMockEnvLoader(t) | ||
| 594 | eventBus := mocks.NewMockEventPublisher(t) | 600 | eventBus := mocks.NewMockEventPublisher(t) | ||
| 595 | 601 | ||||
| 596 | - | config := Config{ | 602 | + | config := testMinDelayConfig() |
| 597 | - | ReadinessDelay: time.Millisecond, | |||
| 598 | - | DrainDelay: time.Millisecond, | |||
| 599 | - | StabilizationDelay: time.Millisecond, | |||
| 600 | - | } | |||
| 601 | svc := NewService(runtime, envLoader, eventBus, nil, config) | 603 | svc := NewService(runtime, envLoader, eventBus, nil, config) | ||
| 602 | ctx := testContext() | 604 | ctx := testContext() | ||
| 603 | 605 | ||||
| @@ -1839,11 +1841,7 @@ func TestService_Deploy_OrphanCleanupRemovesStaleNewContainer(t *testing.T) { | |||||
| 1839 | eventBus := mocks.NewMockEventPublisher(t) | 1841 | eventBus := mocks.NewMockEventPublisher(t) | ||
| 1840 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | 1842 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | ||
| 1841 | 1843 | ||||
| 1842 | - | config := Config{ | 1844 | + | config := testMinDelayConfig() |
| 1843 | - | ReadinessDelay: time.Millisecond, | |||
| 1844 | - | DrainDelay: time.Millisecond, | |||
| 1845 | - | StabilizationDelay: time.Millisecond, | |||
| 1846 | - | } | |||
| 1847 | svc := NewService(runtime, envLoader, eventBus, nil, config) | 1845 | svc := NewService(runtime, envLoader, eventBus, nil, config) | ||
| 1848 | svc.SetProxyCacheInvalidator(cacheInvalidator) | 1846 | svc.SetProxyCacheInvalidator(cacheInvalidator) | ||
| 1849 | ctx := testContext() | 1847 | ctx := testContext() | ||
| @@ -1913,11 +1911,7 @@ func TestService_Deploy_TrackedTempContainerUsesAlternateTempName(t *testing.T) | |||||
| 1913 | eventBus := mocks.NewMockEventPublisher(t) | 1911 | eventBus := mocks.NewMockEventPublisher(t) | ||
| 1914 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | 1912 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | ||
| 1915 | 1913 | ||||
| 1916 | - | config := Config{ | 1914 | + | config := testMinDelayConfig() |
| 1917 | - | ReadinessDelay: time.Millisecond, | |||
| 1918 | - | DrainDelay: time.Millisecond, | |||
| 1919 | - | StabilizationDelay: time.Millisecond, | |||
| 1920 | - | } | |||
| 1921 | svc := NewService(runtime, envLoader, eventBus, nil, config) | 1915 | svc := NewService(runtime, envLoader, eventBus, nil, config) | ||
| 1922 | svc.SetProxyCacheInvalidator(cacheInvalidator) | 1916 | svc.SetProxyCacheInvalidator(cacheInvalidator) | ||
| 1923 | ctx := testContext() | 1917 | ctx := testContext() | ||
| @@ -2104,11 +2098,7 @@ func TestService_Deploy_ConcurrentSameDomain(t *testing.T) { | |||||
| 2104 | eventBus := mocks.NewMockEventPublisher(t) | 2098 | eventBus := mocks.NewMockEventPublisher(t) | ||
| 2105 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | 2099 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | ||
| 2106 | 2100 | ||||
| 2107 | - | config := Config{ | 2101 | + | config := testMinDelayConfig() |
| 2108 | - | ReadinessDelay: time.Millisecond, | |||
| 2109 | - | DrainDelay: time.Millisecond, | |||
| 2110 | - | StabilizationDelay: time.Millisecond, | |||
| 2111 | - | } | |||
| 2112 | svc := NewService(runtime, envLoader, eventBus, nil, config) | 2102 | svc := NewService(runtime, envLoader, eventBus, nil, config) | ||
| 2113 | svc.SetProxyCacheInvalidator(cacheInvalidator) | 2103 | svc.SetProxyCacheInvalidator(cacheInvalidator) | ||
| 2114 | ctx := testContext() | 2104 | ctx := testContext() | ||
| @@ -2244,11 +2234,7 @@ func TestService_Deploy_CacheInvalidationBeforeOldContainerStop(t *testing.T) { | |||||
| 2244 | eventBus := mocks.NewMockEventPublisher(t) | 2234 | eventBus := mocks.NewMockEventPublisher(t) | ||
| 2245 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | 2235 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | ||
| 2246 | 2236 | ||||
| 2247 | - | config := Config{ | 2237 | + | config := testMinDelayConfig() |
| 2248 | - | ReadinessDelay: time.Millisecond, | |||
| 2249 | - | DrainDelay: time.Millisecond, | |||
| 2250 | - | StabilizationDelay: time.Millisecond, | |||
| 2251 | - | } | |||
| 2252 | svc := NewService(runtime, envLoader, eventBus, nil, config) | 2238 | svc := NewService(runtime, envLoader, eventBus, nil, config) | ||
| 2253 | svc.SetProxyCacheInvalidator(cacheInvalidator) | 2239 | svc.SetProxyCacheInvalidator(cacheInvalidator) | ||
| 2254 | ctx := testContext() | 2240 | ctx := testContext() | ||
| @@ -2325,11 +2311,7 @@ func TestService_Deploy_NilCacheInvalidator(t *testing.T) { | |||||
| 2325 | envLoader := mocks.NewMockEnvLoader(t) | 2311 | envLoader := mocks.NewMockEnvLoader(t) | ||
| 2326 | eventBus := mocks.NewMockEventPublisher(t) | 2312 | eventBus := mocks.NewMockEventPublisher(t) | ||
| 2327 | 2313 | ||||
| 2328 | - | config := Config{ | 2314 | + | config := testMinDelayConfig() |
| 2329 | - | ReadinessDelay: time.Millisecond, | |||
| 2330 | - | DrainDelay: time.Millisecond, | |||
| 2331 | - | StabilizationDelay: time.Millisecond, | |||
| 2332 | - | } | |||
| 2333 | // Intentionally NOT setting cache invalidator | 2315 | // Intentionally NOT setting cache invalidator | ||
| 2334 | svc := NewService(runtime, envLoader, eventBus, nil, config) | 2316 | svc := NewService(runtime, envLoader, eventBus, nil, config) | ||
| 2335 | ctx := testContext() | 2317 | ctx := testContext() | ||
| @@ -2484,11 +2466,7 @@ func TestService_Deploy_DoesNotSkipWhenImageIDDiffers(t *testing.T) { | |||||
| 2484 | eventBus := mocks.NewMockEventPublisher(t) | 2466 | eventBus := mocks.NewMockEventPublisher(t) | ||
| 2485 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | 2467 | cacheInvalidator := mocks.NewMockProxyCacheInvalidator(t) | ||
| 2486 | 2468 | ||||
| 2487 | - | config := Config{ | 2469 | + | config := testMinDelayConfig() |
| 2488 | - | ReadinessDelay: time.Millisecond, | |||
| 2489 | - | DrainDelay: time.Millisecond, | |||
| 2490 | - | StabilizationDelay: time.Millisecond, | |||
| 2491 | - | } | |||
| 2492 | svc := NewService(runtime, envLoader, eventBus, nil, config) | 2470 | svc := NewService(runtime, envLoader, eventBus, nil, config) | ||
| 2493 | svc.SetProxyCacheInvalidator(cacheInvalidator) | 2471 | svc.SetProxyCacheInvalidator(cacheInvalidator) | ||
| 2494 | ctx := testContext() | 2472 | ctx := testContext() | ||
| @@ -2587,11 +2565,7 @@ func TestService_Deploy_SkipRedundantDeploy_ContainerNotRunning(t *testing.T) { | |||||
| 2587 | envLoader := mocks.NewMockEnvLoader(t) | 2565 | envLoader := mocks.NewMockEnvLoader(t) | ||
| 2588 | eventBus := mocks.NewMockEventPublisher(t) | 2566 | eventBus := mocks.NewMockEventPublisher(t) | ||
| 2589 | 2567 | ||||
| 2590 | - | config := Config{ | 2568 | + | config := testMinDelayConfig() |
| 2591 | - | ReadinessDelay: time.Millisecond, | |||
| 2592 | - | DrainDelay: time.Millisecond, | |||
| 2593 | - | StabilizationDelay: time.Millisecond, | |||
| 2594 | - | } | |||
| 2595 | svc := NewService(runtime, envLoader, eventBus, nil, config) | 2569 | svc := NewService(runtime, envLoader, eventBus, nil, config) | ||
| 2596 | ctx := testContext() | 2570 | ctx := testContext() | ||
| 2597 | 2571 | ||||
| @@ -2654,11 +2628,7 @@ func TestService_Deploy_OrphanCleanup_NeverKillsRunningCanonical(t *testing.T) { | |||||
| 2654 | envLoader := mocks.NewMockEnvLoader(t) | 2628 | envLoader := mocks.NewMockEnvLoader(t) | ||
| 2655 | eventBus := mocks.NewMockEventPublisher(t) | 2629 | eventBus := mocks.NewMockEventPublisher(t) | ||
| 2656 | 2630 | ||||
| 2657 | - | config := Config{ | 2631 | + | config := testMinDelayConfig() |
| 2658 | - | ReadinessDelay: time.Millisecond, | |||
| 2659 | - | DrainDelay: time.Millisecond, | |||
| 2660 | - | StabilizationDelay: time.Millisecond, | |||
| 2661 | - | } | |||
| 2662 | svc := NewService(runtime, envLoader, eventBus, nil, config) | 2632 | svc := NewService(runtime, envLoader, eventBus, nil, config) | ||
| 2663 | ctx := testContext() | 2633 | ctx := testContext() | ||
| 2664 | 2634 | ||||