From b0cea01f2b41bd678e56f707b2510eab3215c762 Mon Sep 17 00:00:00 2001 From: Auri Munoz Date: Tue, 24 Oct 2023 15:37:21 +0200 Subject: [PATCH] Fixes #667. Use .withTimout method for k8s client to block the thread until the endpoints no longer exists. --- .../kubernetes/KubernetesServiceDiscoveryTest.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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))