aboutsummaryrefslogtreecommitdiffstats
path: root/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxTest.java')
-rw-r--r--routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxTest.java24
1 files changed, 21 insertions, 3 deletions
diff --git a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxTest.java b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxTest.java
index fb21d153ded..3e88fecd222 100644
--- a/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxTest.java
+++ b/routing-generator/src/test/java/com/yahoo/vespa/hosted/routing/nginx/NginxTest.java
@@ -1,4 +1,4 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.routing.nginx;
import com.google.common.jimfs.Jimfs;
@@ -27,7 +27,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -38,6 +37,8 @@ import static org.junit.Assert.fail;
*/
public class NginxTest {
+ private static final String diffCommand = "diff -U1 /opt/vespa/var/vespa-hosted/routing/nginxl4.conf /opt/vespa/var/vespa-hosted/routing/nginxl4.conf.tmp";
+
@Test
public void load_routing_table() {
NginxTester tester = new NginxTester();
@@ -93,6 +94,7 @@ public class NginxTest {
.assertLoadedConfig(true)
.assertConfigContents("nginx-updated.conf")
.assertTemporaryConfigRemoved(true)
+ .assertProducedDiff()
.assertRotatedFiles("nginxl4.conf-2022-01-01-15:00:00.000")
.assertMetric(Nginx.CONFIG_RELOADS_METRIC, 2)
.assertMetric(Nginx.OK_CONFIG_RELOADS_METRIC, 2);
@@ -102,6 +104,7 @@ public class NginxTest {
tester.load(table0);
tester.clock.advance(Duration.ofDays(4).plusSeconds(1));
tester.load(table1)
+ .assertProducedDiff()
.assertRotatedFiles("nginxl4.conf-2022-01-04-15:00:00.000",
"nginxl4.conf-2022-01-08-15:00:01.000");
tester.clock.advance(Duration.ofDays(4));
@@ -116,7 +119,7 @@ public class NginxTest {
private final RoutingStatusMock routingStatus = new RoutingStatusMock();
private final ProcessExecuterMock processExecuter = new ProcessExecuterMock();
private final MockMetric metric = new MockMetric();
- private final Nginx nginx = new Nginx(fileSystem, processExecuter, Sleeper.NOOP, clock, routingStatus, metric);
+ private final Nginx nginx = new Nginx(fileSystem, processExecuter, Sleeper.NOOP, clock, routingStatus, metric, true);
public NginxTester load(RoutingTable table) {
processExecuter.clearHistory();
@@ -158,6 +161,12 @@ public class NginxTest {
return this;
}
+
+ public NginxTester assertProducedDiff() {
+ assertTrue(processExecuter.history.contains(diffCommand));
+ return this;
+ }
+
public NginxTester assertLoadedConfig(boolean loaded) {
String reloadCommand = "/usr/bin/sudo /opt/vespa/bin/vespa-reload-nginx";
if (loaded) {
@@ -198,6 +207,15 @@ public class NginxTest {
history.add(command);
int exitCode = 0;
String out = "";
+ if(command.equals(diffCommand))
+ return new Pair<>(1, """
+ --- /opt/vespa/var/vespa-hosted/routing/nginxl4.conf 2023-10-09 05:28:09.815315000 +0000
+ +++ /opt/vespa/var/vespa-hosted/routing/nginxl4.conf.tmp 2023-10-09 05:28:27.223030000 +0000
+ @@ -45,7 +45,6 @@
+ server 123.example.com:4443;
+ - server 456.example.com:4443;
+ server 789.example.com:4443;""");
+
if (++currentFailCount <= wantedFailCount) {
exitCode = 1;
out = "failing to unit test";