From a032f475902f7d9283ec233b69baeeabb167e8b6 Mon Sep 17 00:00:00 2001 From: Vyatcheslav Suharnikov Date: Wed, 23 Oct 2024 14:56:00 +0400 Subject: [PATCH] Run integration tests on GitHub, save logs (WIP) --- .github/workflows/check-pr.yml | 25 ++++++++++++++++++- consensus-client-it/build.sbt | 3 ++- .../src/test/resources/logback-test.xml | 5 ++-- .../scala/units/network/BaseItTestSuite.scala | 22 +++++++++++++--- .../test/docker/WavesNodeContainer.scala | 3 ++- 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/.github/workflows/check-pr.yml b/.github/workflows/check-pr.yml index 3c3b2246..f2dfed82 100644 --- a/.github/workflows/check-pr.yml +++ b/.github/workflows/check-pr.yml @@ -6,6 +6,16 @@ jobs: check-pr: name: Check PR runs-on: ubuntu-latest + env: + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + services: + docker: + image: docker:latest + options: --privileged # Required for Docker-in-Docker (dind) + volumes: + - /var/run/docker.sock:/var/run/docker.sock + ports: + - 2375:2375 steps: - uses: actions/checkout@v4 - uses: actions/setup-java@v4 @@ -13,5 +23,18 @@ jobs: distribution: 'temurin' java-version: '11' cache: 'sbt' + # - uses: sbt/setup-sbt@v1 + # - name: Install dependencies + # # testcontainers uses nc: + # # https://github.com/testcontainers/testcontainers-java/blob/main/core/src/main/java/org/testcontainers/containers/wait/internal/InternalCommandPortListeningCheck.java#L33 + # run: sudo apt-get update && sudo apt-get install -y netcat - name: Check PR - run: sbt --batch "compile;test" + run: sbt --batch "docker;consensus-client-it/test" + - name: Archive logs + uses: actions/upload-artifact@v4 + if: always() + with: + name: test-logs_${{ env.BRANCH_NAME }}_${{ github.run_id }} + path: consensus-client-it/target/test-logs + if-no-files-found: warn + retention-days: 14 diff --git a/consensus-client-it/build.sbt b/consensus-client-it/build.sbt index d93cfa82..529bdd4a 100644 --- a/consensus-client-it/build.sbt +++ b/consensus-client-it/build.sbt @@ -24,7 +24,8 @@ inConfig(Test)( javaOptions ++= Seq( s"-Dlogback.configurationFile=${(Test / resourceDirectory).value}/logback-test.xml", // Fixes a logback blaming for multiple configs s"-Dcc.it.configs.dir=${baseDirectory.value.getParent}/local-network/configs", - s"-Dcc.it.docker.image=consensus-client:${gitCurrentBranch.value}" + s"-Dcc.it.docker.image=consensus-client:${gitCurrentBranch.value}", + s"-Dcc.it.logs.dir=${(Test / logsDirectory).value}" ), testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-fFWD", ((Test / logsDirectory).value / "summary.log").toString), parallelExecution := true, diff --git a/consensus-client-it/src/test/resources/logback-test.xml b/consensus-client-it/src/test/resources/logback-test.xml index ce24c467..01166258 100644 --- a/consensus-client-it/src/test/resources/logback-test.xml +++ b/consensus-client-it/src/test/resources/logback-test.xml @@ -22,12 +22,11 @@ - + - - + diff --git a/consensus-client-it/src/test/scala/units/network/BaseItTestSuite.scala b/consensus-client-it/src/test/scala/units/network/BaseItTestSuite.scala index ced811b6..bc16d7fd 100644 --- a/consensus-client-it/src/test/scala/units/network/BaseItTestSuite.scala +++ b/consensus-client-it/src/test/scala/units/network/BaseItTestSuite.scala @@ -10,10 +10,12 @@ import org.scalatest.concurrent.Eventually import org.scalatest.freespec.AnyFreeSpec import org.scalatest.matchers.should.Matchers import org.scalatest.{BeforeAndAfterAll, EitherValues, OptionValues} +import org.testcontainers.containers.output.OutputFrame.OutputType import units.network.test.docker.{EcContainer, Networks, WavesNodeContainer} import units.test.CustomMatchers import java.nio.charset.StandardCharsets +import java.nio.file.{Files, Path} trait BaseItTestSuite extends AnyFreeSpec @@ -41,12 +43,26 @@ trait BaseItTestSuite super.beforeAll() log.debug(s"Docker network name: ${network.getName}, id: ${network.getId}") // Force create network - ec1.start() - ec1.logPorts() - waves1.start() waves1.waitReady() waves1.logPorts() + + Files.write( + Path.of(System.getProperty("cc.it.logs.dir"), "waves-container.log"), + waves1.container.getLogs(OutputType.STDOUT, OutputType.STDOUT, OutputType.END).getBytes(StandardCharsets.UTF_8) + ) + + log.info(s"Last height: ${waves1.api.height}") // TODO remove + + ec1.start() + ec1.logPorts() + log.info(s"Last execution block: ${ec1.engineApi.getLastExecutionBlock}") // Works // TODO remove + +// waves1.start() +// waves1.waitReady() +// waves1.logPorts() +// Thread.sleep(10000) +// log.info(s"Last height: ${waves1.api.height}") // TODO remove } override protected def afterAll(): Unit = { diff --git a/consensus-client-it/src/test/scala/units/network/test/docker/WavesNodeContainer.scala b/consensus-client-it/src/test/scala/units/network/test/docker/WavesNodeContainer.scala index afcc8a6b..4b87cb4f 100644 --- a/consensus-client-it/src/test/scala/units/network/test/docker/WavesNodeContainer.scala +++ b/consensus-client-it/src/test/scala/units/network/test/docker/WavesNodeContainer.scala @@ -22,7 +22,8 @@ class WavesNodeContainer( chainContractAddress: Address, ecEngineApiUrl: String ) extends BaseContainer(s"wavesnode-$number") { - protected override val container = new GenericContainer(DockerImageName.parse(System.getProperty("cc.it.docker.image"))) + // protected + override val container = new GenericContainer(DockerImageName.parse(System.getProperty("cc.it.docker.image"))) .withNetwork(network) .withExposedPorts(ApiPort) .withEnv(