Skip to content

Commit

Permalink
Run integration tests on GitHub, save logs (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsuharnikov committed Oct 24, 2024
1 parent 7a5bb4e commit 1c6b894
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
31 changes: 30 additions & 1 deletion .github/workflows/check-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,41 @@ 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
with:
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: Generate genesis.conf
run: |
pushd local-network
sh genesis-update.sh
popd
- name: Check PR
run: sbt --batch "compile;test"
# run: sbt --batch "docker;consensus-client-it/test"
run: sbt --batch "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
10 changes: 6 additions & 4 deletions consensus-client-it/build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import com.github.sbt.git.SbtGit.git.gitCurrentBranch
import sbt.Tests.Group
import sbt.util

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
Expand All @@ -24,19 +25,20 @@ 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=ghcr.io/unitsnetwork/consensus-client:testnet-2",
// 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,
testGrouping := {
val PORTS_PER_TEST = 50
val DEFAULT_PORT_RANGE = (10000, 32000)

val javaHomeValue = (test / javaHome).value
val logDirectoryValue = (Test / logsDirectory).value
val envVarsValue = (Test / envVars).value
val javaOptionsValue = (Test / javaOptions).value

streams.value.log.log(util.Level.Info, s"javaOptions: ${javaOptionsValue.mkString(", ")}; logsDirectory: $logDirectoryValue")

val tests = (Test / definedTests).value

tests.zipWithIndex.map { case (suite, i) =>
Expand Down
5 changes: 2 additions & 3 deletions consensus-client-it/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
</encoder>
</appender>

<!-- Retries logs -->
<!-- Testcontainers logs -->
<logger name="org.rnorth.ducttape.unreliables" level="WARN"/>

<!-- Docker logs -->
<logger name="com.github.dockerjava" level="WARN"/>
<logger name="org.testcontainers" level="WARN"/>
<logger name="org.testcontainers.utility" level="ERROR"/>

<root level="TRACE">
<appender-ref ref="STDOUT"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -41,12 +43,28 @@ 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()

Thread.sleep(10000)

Files.write(
Path.of(System.getProperty("cc.it.logs.dir"), "waves-container.log"),
waves1.container.getLogs().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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 1c6b894

Please sign in to comment.