Skip to content

Commit

Permalink
Use a non-default port for upgrade-cli unit tests (#1512)
Browse files Browse the repository at this point in the history
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 <andrross@amazon.com>
  • Loading branch information
andrross authored Nov 5, 2021
1 parent eb5e454 commit 546ab21
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void testTaskExecution() throws Exception {
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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ public void testImportYmlConfigTask() throws IOException {
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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ private void assertYmlConfigImported() throws IOException {
Arrays.asList(
"---",
"cluster.name: \"my-cluster\"",
"http.port: \"42123\"",
"node.name: \"node-x\"",
"path.data:",
"- \"/mnt/data_1\"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ path:
- /mnt/data_1
- /mnt/data_2
logs: /var/log/eslogs
http.port: 42123

0 comments on commit 546ab21

Please sign in to comment.