From 046ab939c163d35d923ae2565087554f6399f30d Mon Sep 17 00:00:00 2001 From: SeongChan Lee Date: Fri, 2 Aug 2024 13:02:14 +0900 Subject: [PATCH] Adjust flaky timeouts --- tests/webhooks.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/tests/webhooks.rs b/tests/webhooks.rs index 655ea0c..4b363fb 100644 --- a/tests/webhooks.rs +++ b/tests/webhooks.rs @@ -169,11 +169,16 @@ async fn pod_is_deleted_within(context: &TestContext, name: &str, timeout: Durat false } +const DELETE_AFTER_SECS: u64 = 10; +const DELETE_AFTER: Duration = Duration::from_secs(DELETE_AFTER_SECS); +const DELETE_DELAY_APPROX_SECS: u64 = DELETE_AFTER_SECS * 60 / 100; +const DELETE_DELAY_APPROX: Duration = Duration::from_secs(DELETE_DELAY_APPROX_SECS); + #[tokio::test] async fn should_delay_deletion_by_kubectl_delete() { within_test_namespace(|context| async move { let config = Config { - delete_after: Duration::from_secs(10), + delete_after: DELETE_AFTER, experimental_general_ingress: true, }; setup(&context, config).await; @@ -235,11 +240,11 @@ spec: let context = Arc::clone(&context); async move { let start = Instant::now(); - kubectl!(&context, ["delete", "pod", "some-pod", "--wait=false"]); + kubectl!(&context, ["delete", "pod", "some-pod"]); let duration = Instant::now() - start; assert!( - duration > Duration::from_secs(10 - 2), + duration > DELETE_DELAY_APPROX, "should be delayed approx. 10s" ); } @@ -276,10 +281,10 @@ spec: let context = Arc::clone(&context); async move { let start = Instant::now(); - kubectl!(&context, ["delete", "pod", "some-pod", "--wait=false"]); + kubectl!(&context, ["delete", "pod", "some-pod"]); let duration = Instant::now() - start; assert!( - duration > Duration::from_secs(10 - 2), + duration > DELETE_DELAY_APPROX, "should still wait approx. 10s" ); } @@ -287,7 +292,7 @@ spec: assert!(event_tracker.issued_soon("DelayDeletion", "Draining").await); assert!( - pod_is_alive_for(&context, "some-pod", Duration::from_secs(10 - 2)).await, + pod_is_alive_for(&context, "some-pod", DELETE_DELAY_APPROX).await, "pod is alive for approx. 10s" ); @@ -295,7 +300,7 @@ spec: second.await.unwrap(); assert!( - pod_is_deleted_within(&context, "some-pod", Duration::from_secs(10)).await, + pod_is_deleted_within(&context, "some-pod", Duration::from_secs(20)).await, "pod is eventually deleted" ); }) @@ -306,7 +311,7 @@ spec: async fn should_allow_deletion_when_pod_is_not_ready() { within_test_namespace(|context| async move { let config = Config { - delete_after: Duration::from_secs(10), + delete_after: DELETE_AFTER, experimental_general_ingress: true, }; setup(&context, config).await; @@ -374,7 +379,7 @@ spec: async fn should_allow_deletion_when_pod_is_not_exposed() { within_test_namespace(|context| async move { let config = Config { - delete_after: Duration::from_secs(10), + delete_after: DELETE_AFTER, experimental_general_ingress: true, }; setup(&context, config).await; @@ -406,7 +411,7 @@ async fn should_allow_deletion_when_pod_is_not_exposed() { async fn should_allow_deletion_when_dry_run() { within_test_namespace(|context| async move { let config = Config { - delete_after: Duration::from_secs(10), + delete_after: DELETE_AFTER, experimental_general_ingress: true, }; setup(&context, config).await; @@ -434,7 +439,7 @@ async fn should_allow_deletion_when_dry_run() { async fn should_delay_deletion_by_deployment_rollout() { within_test_namespace(|context| async move { let config = Config { - delete_after: Duration::from_secs(10), + delete_after: DELETE_AFTER, experimental_general_ingress: true, }; setup(&context, config).await; @@ -542,7 +547,7 @@ spec: assert!(event_tracker.issued_soon("DelayDeletion", "Drain").await); assert!( - pod_is_alive_for(&context, &pod_name, Duration::from_secs(10 - 2)).await, + pod_is_alive_for(&context, &pod_name, DELETE_DELAY_APPROX).await, "pod is alive for approx. 10s" ); @@ -552,7 +557,7 @@ spec: ); assert!( - pod_is_deleted_within(&context, &pod_name, Duration::from_secs(10)).await, + pod_is_deleted_within(&context, &pod_name, Duration::from_secs(20)).await, "pod is eventually deleted" ); })