Skip to content

Commit

Permalink
fix(1290): Fix flaky Kubernetes actor tests
Browse files Browse the repository at this point in the history
- Make sure to run the Kubernetes actor unit test in single threaded mode in order to not influence other tests running in parallel
- Make sure to properly reset the actor's connected state after the tests
  • Loading branch information
christophd committed Jan 8, 2025
1 parent 4b2cb40 commit f85fb94
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

@Test(singleThreaded = true)
public class KubernetesActorTest {

private final KubernetesMockServer k8sServer = new KubernetesMockServer(new Context(), new MockWebServer(),
Expand All @@ -47,9 +48,9 @@ public void stop() {
k8sServer.destroy();
}

@Test
public void shouldVerifyConnectedState() {
try {
KubernetesActor.resetConnectionState();
Assert.assertFalse(new KubernetesActor(k8sClient).isDisabled());
} finally {
KubernetesActor.resetConnectionState();
Expand All @@ -63,14 +64,15 @@ public void shouldVerifyConnectedState() {
}
}

@Test
public void shouldOverruleConnectedState() {
boolean initial = KubernetesSettings.isEnabled();
try {
KubernetesActor.resetConnectionState();
System.setProperty("citrus.kubernetes.enabled", "false");
Assert.assertTrue(new KubernetesActor(k8sClient).isDisabled());
} finally {
System.setProperty("citrus.kubernetes.enabled", Boolean.toString(initial));
KubernetesActor.resetConnectionState();
}

initial = Boolean.parseBoolean(System.getProperty("citrus.test.actor.k8s.enabled", "true"));
Expand All @@ -79,6 +81,7 @@ public void shouldOverruleConnectedState() {
Assert.assertTrue(new KubernetesActor(k8sClient).isDisabled());
} finally {
System.setProperty("citrus.test.actor.k8s.enabled", Boolean.toString(initial));
KubernetesActor.resetConnectionState();
}
}
}

0 comments on commit f85fb94

Please sign in to comment.