From b5f7dff74ddbea5c9d527f55e598ec26735f7427 Mon Sep 17 00:00:00 2001 From: Piotr Findeisen Date: Fri, 12 Aug 2022 12:53:24 +0200 Subject: [PATCH] Prefetch Ryuk image with retries According to https://nineinchnick.github.io/trino-cicd/reports/flaky/, HTTP 500 when getting `testcontainers/ryuk` is not uncommon source of test flakiness. Let's try to improve the situation by fetching the image before tests are started. --- .github/workflows/ci.yml | 3 ++ testing/trino-testing-containers/pom.xml | 6 +++ .../containers/testcontainers-ryuk-image.txt | 1 + .../test/java/io/trino/server/TestDummy.java | 22 -------- .../testing/containers/TestRyukVersion.java | 51 +++++++++++++++++++ 5 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 testing/trino-testing-containers/src/main/resources/io/trino/testing/containers/testcontainers-ryuk-image.txt delete mode 100644 testing/trino-testing-containers/src/test/java/io/trino/server/TestDummy.java create mode 100644 testing/trino-testing-containers/src/test/java/io/trino/testing/containers/TestRyukVersion.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 989ae3316d25..9c6cbc23b1d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -458,6 +458,9 @@ jobs: run: | export MAVEN_OPTS="${MAVEN_INSTALL_OPTS}" $RETRY $MAVEN clean install ${MAVEN_FAST_INSTALL} ${MAVEN_GIB} -am -pl "${{ matrix.modules }}" + - name: Prefetch Ryuk + run: | + $RETRY docker pull "$(cat testing/trino-testing-containers/src/main/resources/io/trino/testing/containers/testcontainers-ryuk-image.txt)" - name: Maven Tests if: matrix.modules != 'plugin/trino-singlestore' run: $MAVEN test ${MAVEN_TEST} -pl ${{ matrix.modules }} ${{ matrix.profile != '' && format('-P {0}', matrix.profile) || '' }} diff --git a/testing/trino-testing-containers/pom.xml b/testing/trino-testing-containers/pom.xml index 96c5cbd1ffa8..981b21b60018 100644 --- a/testing/trino-testing-containers/pom.xml +++ b/testing/trino-testing-containers/pom.xml @@ -64,6 +64,12 @@ testcontainers + + org.assertj + assertj-core + test + + org.testng testng diff --git a/testing/trino-testing-containers/src/main/resources/io/trino/testing/containers/testcontainers-ryuk-image.txt b/testing/trino-testing-containers/src/main/resources/io/trino/testing/containers/testcontainers-ryuk-image.txt new file mode 100644 index 000000000000..8737503315af --- /dev/null +++ b/testing/trino-testing-containers/src/main/resources/io/trino/testing/containers/testcontainers-ryuk-image.txt @@ -0,0 +1 @@ +testcontainers/ryuk:0.3.3 diff --git a/testing/trino-testing-containers/src/test/java/io/trino/server/TestDummy.java b/testing/trino-testing-containers/src/test/java/io/trino/server/TestDummy.java deleted file mode 100644 index dea00f6fd596..000000000000 --- a/testing/trino-testing-containers/src/test/java/io/trino/server/TestDummy.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.trino.server; - -import org.testng.annotations.Test; - -public class TestDummy -{ - @Test - public void buildRequiresTestToExist() {} -} diff --git a/testing/trino-testing-containers/src/test/java/io/trino/testing/containers/TestRyukVersion.java b/testing/trino-testing-containers/src/test/java/io/trino/testing/containers/TestRyukVersion.java new file mode 100644 index 000000000000..2f484e58f531 --- /dev/null +++ b/testing/trino-testing-containers/src/test/java/io/trino/testing/containers/TestRyukVersion.java @@ -0,0 +1,51 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.trino.testing.containers; + +import com.github.dockerjava.api.model.Container; +import com.google.common.io.Resources; +import org.testcontainers.DockerClientFactory; +import org.testcontainers.utility.ResourceReaper; +import org.testng.annotations.Test; + +import java.util.List; + +import static com.google.common.collect.Iterables.getOnlyElement; +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.assertj.core.api.Assertions.assertThat; + +public class TestRyukVersion +{ + @Test + public void testRyukVersionResourceFile() + throws Exception + { + ResourceReaper.instance(); + List containers = DockerClientFactory.instance().client() + .listContainersCmd().withNameFilter(List.of("testcontainers-ryuk-" + DockerClientFactory.SESSION_ID)) + .exec(); + assertThat(containers).as("containers") + .hasSize(1); + + String currentImage = getOnlyElement(containers).getImage(); + // Sanity check the value we get from testcontainers includes version + assertThat(currentImage).as("currentImage") + .matches("testcontainers/ryuk:(.+)") + .doesNotContain("latest"); + + String ryukImageFromResource = Resources.toString(Resources.getResource(getClass(), "testcontainers-ryuk-currentImage.txt"), UTF_8).trim(); + assertThat(ryukImageFromResource).as("ryukImageFromResource") + .isEqualTo(currentImage); + } +}