From d3e39a7e51b13a0eb5b05306bc21c934d827633f Mon Sep 17 00:00:00 2001 From: Yong Zhang Date: Thu, 24 Dec 2020 04:22:35 +0800 Subject: [PATCH] Add retry for the sql test (#9010) *Motivation* Using await until for retrying the condition check. --- .github/workflows/ci-integration-sql.yaml | 2 +- .../integration/presto/TestBasicPresto.java | 40 +++++++++++-------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci-integration-sql.yaml b/.github/workflows/ci-integration-sql.yaml index 15adf8a499c65..34695d9f57204 100644 --- a/.github/workflows/ci-integration-sql.yaml +++ b/.github/workflows/ci-integration-sql.yaml @@ -95,4 +95,4 @@ jobs: - name: run integration tests if: steps.docs.outputs.changed_only == 'no' - run: mvn -B -f tests/pom.xml test -DintegrationTestSuiteFile=pulsar-sql.xml -DintegrationTests -DredirectTestOutputToFile=false + run: mvn -B -f tests/pom.xml test -DintegrationTestSuiteFile=pulsar-sql.xml -DintegrationTests -DredirectTestOutputToFile=false -DtestForkCount=1 diff --git a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/presto/TestBasicPresto.java b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/presto/TestBasicPresto.java index 3b4164150fa58..7fde5bc04e6f1 100644 --- a/tests/integration/src/test/java/org/apache/pulsar/tests/integration/presto/TestBasicPresto.java +++ b/tests/integration/src/test/java/org/apache/pulsar/tests/integration/presto/TestBasicPresto.java @@ -30,6 +30,7 @@ import org.apache.pulsar.tests.integration.suites.PulsarTestSuite; import org.apache.pulsar.tests.integration.topologies.PulsarCluster; import org.apache.pulsar.tests.integration.topologies.PulsarClusterSpec; +import org.awaitility.Awaitility; import org.testng.annotations.AfterClass; import org.testng.annotations.AfterSuite; import org.testng.annotations.BeforeClass; @@ -129,23 +130,30 @@ public void testSimpleSQLQuery(boolean isBatched) throws Exception { "/bin/bash", "-c", "bin/pulsar-admin namespaces unload public/default"); - result = execQuery("show tables in pulsar.\"public/default\";"); - assertThat(result.getExitCode()).isEqualTo(0); - assertThat(result.getStdout()).contains("stocks"); - - ContainerExecResult containerExecResult = execQuery(String.format("select * from pulsar.\"public/default\".%s order by entryid;", stocksTopic)); - assertThat(containerExecResult.getExitCode()).isEqualTo(0); - log.info("select sql query output \n{}", containerExecResult.getStdout()); - String[] split = containerExecResult.getStdout().split("\n"); - assertThat(split.length).isEqualTo(NUM_OF_STOCKS); - - String[] split2 = containerExecResult.getStdout().split("\n|,"); + Awaitility.await().atMost(10, TimeUnit.SECONDS).untilAsserted( + () -> { + ContainerExecResult r = execQuery("show tables in pulsar.\"public/default\";"); + assertThat(r.getExitCode()).isEqualTo(0); + assertThat(r.getStdout()).contains("stocks"); + } + ); + + Awaitility.await().atMost(10, TimeUnit.SECONDS).untilAsserted( + () -> { + ContainerExecResult containerExecResult = execQuery(String.format("select * from pulsar.\"public/default\".%s order by entryid;", stocksTopic)); + assertThat(containerExecResult.getExitCode()).isEqualTo(0); + log.info("select sql query output \n{}", containerExecResult.getStdout()); + String[] split = containerExecResult.getStdout().split("\n"); + assertThat(split.length).isEqualTo(NUM_OF_STOCKS); + String[] split2 = containerExecResult.getStdout().split("\n|,"); + for (int i = 0; i < NUM_OF_STOCKS; ++i) { + assertThat(split2).contains("\"" + i + "\""); + assertThat(split2).contains("\"" + "STOCK_" + i + "\""); + assertThat(split2).contains("\"" + (100.0 + i * 10) + "\""); + } + } + ); - for (int i = 0; i < NUM_OF_STOCKS; ++i) { - assertThat(split2).contains("\"" + i + "\""); - assertThat(split2).contains("\"" + "STOCK_" + i + "\""); - assertThat(split2).contains("\"" + (100.0 + i * 10) + "\""); - } // test predicate pushdown