From 546ab21989a27ae52cd557621ffac77ef4b09530 Mon Sep 17 00:00:00 2001 From: Andrew Ross Date: Fri, 5 Nov 2021 08:52:16 -0500 Subject: [PATCH] Use a non-default port for upgrade-cli unit tests (#1512) I observed a [test failure][1] that I believe was caused by the fact that an OpenSearch server happened to be running at localhost:9200 when these unit tests were executed. The code under test has logic to try to connect to localhost:9200 and then fall back to defaults if that port is not open. The tests expect these defaults and will fail if different data is returned. The change here is to use a non-default port to make it very unlikely that a real instance will be running at the non-default port. I don't know why an OpenSearch service happened to be running during the linked test failure, but I think making these unit tests more independent and isolated is helpful no matter the underlying cause in this case. [1]: https://fork-jenkins.searchservices.aws.dev/job/OpenSearch_CI/job/PR_Checks/job/Gradle_Check/975/artifact/gradle_check_975.log/*view*/ Signed-off-by: Andrew Ross --- .../org/opensearch/upgrade/DetectEsInstallationTaskTests.java | 2 +- .../java/org/opensearch/upgrade/ImportYmlConfigTaskTests.java | 3 ++- .../src/test/java/org/opensearch/upgrade/UpgradeCliTests.java | 1 + .../upgrade-cli/src/test/resources/config/elasticsearch.yml | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/DetectEsInstallationTaskTests.java b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/DetectEsInstallationTaskTests.java index fcabf24e9bd..1038e6d4a48 100644 --- a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/DetectEsInstallationTaskTests.java +++ b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/DetectEsInstallationTaskTests.java @@ -49,7 +49,7 @@ public class DetectEsInstallationTaskTests extends OpenSearchTestCase { task.accept(input); assertThat(taskInput.getEsConfig(), is(esConfig)); - assertThat(taskInput.getBaseUrl(), is("http://localhost:9200")); + assertThat(taskInput.getBaseUrl(), is("http://localhost:42123")); assertThat(taskInput.getPlugins(), hasSize(0)); assertThat(taskInput.getNode(), is("node-x")); assertThat(taskInput.getCluster(), is("my-cluster")); diff --git a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/ImportYmlConfigTaskTests.java b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/ImportYmlConfigTaskTests.java index ac30b2034b1..f328cc21685 100644 --- a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/ImportYmlConfigTaskTests.java +++ b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/ImportYmlConfigTaskTests.java @@ -59,8 +59,9 @@ public class ImportYmlConfigTaskTests extends OpenSearchTestCase { taskInput.setEsConfig(esConfig); task.accept(new Tuple<>(taskInput, terminal)); Settings settings = Settings.builder().loadFromPath(taskInput.getOpenSearchConfig().resolve("opensearch.yml")).build(); - assertThat(settings.keySet(), contains("cluster.name", "node.name", "path.data", "path.logs")); + assertThat(settings.keySet(), contains("cluster.name", "http.port", "node.name", "path.data", "path.logs")); assertThat(settings.get("cluster.name"), is("my-cluster")); + assertThat(settings.get("http.port"), is("42123")); assertThat(settings.get("node.name"), is("node-x")); assertThat(settings.get("path.data"), is("[/mnt/data_1, /mnt/data_2]")); assertThat(settings.get("path.logs"), is("/var/log/eslogs")); diff --git a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/UpgradeCliTests.java b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/UpgradeCliTests.java index 863313d8b41..3db782925a6 100644 --- a/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/UpgradeCliTests.java +++ b/distribution/tools/upgrade-cli/src/test/java/org/opensearch/upgrade/UpgradeCliTests.java @@ -113,6 +113,7 @@ public class UpgradeCliTests extends CommandTestCase { Arrays.asList( "---", "cluster.name: \"my-cluster\"", + "http.port: \"42123\"", "node.name: \"node-x\"", "path.data:", "- \"/mnt/data_1\"", diff --git a/distribution/tools/upgrade-cli/src/test/resources/config/elasticsearch.yml b/distribution/tools/upgrade-cli/src/test/resources/config/elasticsearch.yml index 4262adfba6d..083b4c7a745 100644 --- a/distribution/tools/upgrade-cli/src/test/resources/config/elasticsearch.yml +++ b/distribution/tools/upgrade-cli/src/test/resources/config/elasticsearch.yml @@ -5,3 +5,4 @@ path: - /mnt/data_1 - /mnt/data_2 logs: /var/log/eslogs +http.port: 42123