test: RED - Updated keys must survive, if HAProxy reloads
authorKai Moritz <kai@juplo.de>
Wed, 20 Mar 2024 22:02:22 +0000 (23:02 +0100)
committerKai Moritz <kai@juplo.de>
Fri, 22 Mar 2024 16:39:20 +0000 (17:39 +0100)
* The Handover-IT hast to signal HAProxy to reload, after a new backend was
  started for the first time.
* Otherwise, HAProxy is not able to detect newly started backend-instances,
  because with docker, the name of a backend cannot be resolved, before it
  is started.
* This test formulates the expectation, that dynamically added changes,
  that were applyed with the help of the Data Plane API, persist a reload.
* *The test fails*, because HAProxy restores all maps from disk, if it
  reloads, but the dynamically made changes are never synced back to disk.

src/test/java/de/juplo/kafka/chat/backend/implementation/haproxy/HaproxyDataPlaneApiShardingPublisherStrategyIT.java

index 9235a06..41ed2de 100644 (file)
@@ -9,11 +9,13 @@ import org.springframework.web.reactive.function.client.WebClient;
 import org.testcontainers.containers.GenericContainer;
 import org.testcontainers.containers.Network;
 import org.testcontainers.containers.output.Slf4jLogConsumer;
+import org.testcontainers.containers.wait.strategy.Wait;
 import org.testcontainers.junit.jupiter.Container;
 import org.testcontainers.junit.jupiter.Testcontainers;
 import org.testcontainers.utility.DockerImageName;
 import org.testcontainers.utility.MountableFile;
 import reactor.core.publisher.Mono;
+import reactor.util.retry.Retry;
 
 import java.time.Duration;
 
@@ -27,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 public class HaproxyDataPlaneApiShardingPublisherStrategyIT
 {
   @Test
-  void test()
+  void test() throws InterruptedException
   {
     Mono<String> result = shardingPublisherStrategy.publishOwnership(SHARD);
 
@@ -35,6 +37,17 @@ public class HaproxyDataPlaneApiShardingPublisherStrategyIT
         .isEqualTo(INSTANCE_ID);
     assertThat(getMapEntryValueForKey(SHARD).block(Duration.ofSeconds(5)))
         .isEqualTo(INSTANCE_ID);
+
+    HAPROXY
+        .getDockerClient()
+        .killContainerCmd(HAPROXY.getContainerId())
+        .withSignal("HUP")
+        .exec();
+
+    Thread.sleep(1000); // << No clue, how to detect that the reload is complete
+
+    assertThat(getMapEntryValueForKey(SHARD).block(Duration.ofSeconds(5)))
+        .isEqualTo(INSTANCE_ID);
   }
 
 
@@ -58,6 +71,7 @@ public class HaproxyDataPlaneApiShardingPublisherStrategyIT
             return response.createError();
           }
         })
+        .retryWhen(Retry.fixedDelay(15, Duration.ofSeconds(1)))
         .map(entry -> entry.value());
   }