@@ -2382,3 +2382,52 @@ func Test_allowPodStart(t *testing.T) {
2382
2382
})
2383
2383
}
2384
2384
}
2385
+
2386
+ func Test_calculateEffectiveGracePeriod (t * testing.T ) {
2387
+ zero := int64 (0 )
2388
+ two := int64 (2 )
2389
+ five := int64 (5 )
2390
+ thirty := int64 (30 )
2391
+ // no overrides, use what's on the spec
2392
+ pod := newNamedPod ("1" , "ns" , "running-pod" , false )
2393
+ pod .Spec .TerminationGracePeriodSeconds = & thirty
2394
+ gracePeriod , _ := calculateEffectiveGracePeriod (& podSyncStatus {}, pod , & KillPodOptions {})
2395
+ expectedGracePeriod := int64 (30 )
2396
+ if gracePeriod != expectedGracePeriod {
2397
+ t .Errorf ("Expected a grace period of %v, but was %v" , expectedGracePeriod , gracePeriod )
2398
+ }
2399
+
2400
+ // pod DeletionGracePeriodSeconds is set
2401
+ pod .DeletionGracePeriodSeconds = & five
2402
+ gracePeriod , _ = calculateEffectiveGracePeriod (& podSyncStatus {}, pod , & KillPodOptions {})
2403
+ expectedGracePeriod = five
2404
+ if gracePeriod != expectedGracePeriod {
2405
+ t .Errorf ("Expected a grace period of %v, but was %v" , expectedGracePeriod , gracePeriod )
2406
+ }
2407
+
2408
+ // grace period override
2409
+ gracePeriod , _ = calculateEffectiveGracePeriod (& podSyncStatus {}, pod , & KillPodOptions {
2410
+ PodTerminationGracePeriodSecondsOverride : & two ,
2411
+ })
2412
+ expectedGracePeriod = two
2413
+ if gracePeriod != expectedGracePeriod {
2414
+ t .Errorf ("Expected a grace period of %v, but was %v" , expectedGracePeriod , gracePeriod )
2415
+ }
2416
+
2417
+ // pod DeletionGracePeriodSeconds is zero
2418
+ pod .DeletionGracePeriodSeconds = & zero
2419
+ gracePeriod , _ = calculateEffectiveGracePeriod (& podSyncStatus {}, pod , & KillPodOptions {})
2420
+ expectedGracePeriod = int64 (1 )
2421
+ if gracePeriod != expectedGracePeriod {
2422
+ t .Errorf ("Expected a grace period of %v, but was %v" , expectedGracePeriod , gracePeriod )
2423
+ }
2424
+
2425
+ // grace period override is zero
2426
+ gracePeriod , _ = calculateEffectiveGracePeriod (& podSyncStatus {}, pod , & KillPodOptions {
2427
+ PodTerminationGracePeriodSecondsOverride : & zero ,
2428
+ })
2429
+ expectedGracePeriod = int64 (1 )
2430
+ if gracePeriod != expectedGracePeriod {
2431
+ t .Errorf ("Expected a grace period of %v, but was %v" , expectedGracePeriod , gracePeriod )
2432
+ }
2433
+ }
0 commit comments