diff --git a/service-discovery/kubernetes/src/test/java/io/smallrye/stork/servicediscovery/kubernetes/KubernetesServiceDiscoveryTest.java b/service-discovery/kubernetes/src/test/java/io/smallrye/stork/servicediscovery/kubernetes/KubernetesServiceDiscoveryTest.java index 802830b0..456728fc 100644 --- a/service-discovery/kubernetes/src/test/java/io/smallrye/stork/servicediscovery/kubernetes/KubernetesServiceDiscoveryTest.java +++ b/service-discovery/kubernetes/src/test/java/io/smallrye/stork/servicediscovery/kubernetes/KubernetesServiceDiscoveryTest.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @@ -404,18 +405,17 @@ void shouldPreserveIdsOnRefetch() throws InterruptedException { @Test void shouldFetchInstancesFromTheClusterWhenCacheIsInvalidated() throws InterruptedException { - // Given a service with 3 instances registered in the cluster + // Given a service with 3 instances registered in the cluster, in `test` namespace // Stork gather the cache from the cluster // When the endpoints are removed (this invalidates the cache) // Stork is called to get service instances again // Stork contacts the cluster to get the instances : it gets 0 of them + String serviceName = "svc"; - TestConfigProvider.addServiceConfig("svc", null, "kubernetes", + TestConfigProvider.addServiceConfig(serviceName, null, "kubernetes", null, Map.of("k8s-host", k8sMasterUrl, "k8s-namespace", defaultNamespace, "refresh-period", "3")); Stork stork = StorkTestUtils.getNewStorkInstance(); - String serviceName = "svc"; - registerKubernetesResources(serviceName, defaultNamespace, "10.96.96.231", "10.96.96.232", "10.96.96.233"); AtomicReference> instances = new AtomicReference<>(); @@ -433,9 +433,7 @@ void shouldFetchInstancesFromTheClusterWhenCacheIsInvalidated() throws Interrupt assertThat(instances.get().stream().map(ServiceInstance::getHost)).containsExactlyInAnyOrder("10.96.96.231", "10.96.96.232", "10.96.96.233"); - client.endpoints().withName(serviceName).delete(); - - Thread.sleep(5000); + client.endpoints().inNamespace(defaultNamespace).withName(serviceName).withTimeout(100, TimeUnit.MILLISECONDS).delete(); service.getServiceDiscovery().getServiceInstances() .onFailure().invoke(th -> fail("Failed to get service instances from Kubernetes", th))