Skip to content

Commit

Permalink
Docker tests (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
vsuharnikov authored Nov 22, 2024
1 parent 613d21a commit e51a320
Show file tree
Hide file tree
Showing 76 changed files with 2,473 additions and 338 deletions.
26 changes: 24 additions & 2 deletions .github/workflows/check-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,34 @@ jobs:
check-pr:
name: Check PR
runs-on: ubuntu-latest
env:
JAVA_OPTS: -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
SBT_IT_TEST_THREADS: 2
services:
docker:
image: docker:latest
options: --privileged # Required for Docker-in-Docker
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'
- name: Check PR
run: sbt --batch "compile;test"
- uses: sbt/setup-sbt@v1
- name: Run tests
run: |
sbt --batch "test;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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
.DS_Store
target
.bloop
.bsp
.metals
metals.sbt
.idea
docker/data
docker/logs
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# consensus-client

## 👨‍💻 Development

1. Run unit tests:
```bash
sbt test
```

2. Run integration tests:
1. Build the Docker image:
```bash
sbt docker
```
Note: Build the Docker image whenever the consensus client code is updated, including after pulling from the repository.
2. Run the integration tests:
```bash
sbt "consensus-client-it/test"
```
3. See logs in `consensus-client-it/target/test-logs`.
70 changes: 48 additions & 22 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,37 +1,43 @@
Global / onChangedBuildSource := ReloadOnSourceChanges
import com.github.sbt.git.SbtGit.GitKeys.gitCurrentBranch

enablePlugins(UniversalDeployPlugin, GitVersioning)
enablePlugins(UniversalDeployPlugin, GitVersioning, sbtdocker.DockerPlugin)

git.useGitDescribe := true
git.baseVersion := "1.0.0"
git.uncommittedSignifier := Some("DIRTY")

scalaVersion := "2.13.15"
organization := "network.units"
organizationName := "Units Network"
name := "consensus-client"
maintainer := "Units Network Team"
resolvers ++= Resolver.sonatypeOssRepos("releases") ++ Resolver.sonatypeOssRepos("snapshots") ++ Seq(Resolver.mavenLocal)
inScope(Global)(
Seq(
onChangedBuildSource := ReloadOnSourceChanges,
scalaVersion := "2.13.15",
organization := "network.units",
organizationName := "Units Network",
resolvers ++= Resolver.sonatypeOssRepos("releases") ++ Resolver.sonatypeOssRepos("snapshots") ++ Seq(Resolver.mavenLocal),
scalacOptions ++= Seq(
"-Xsource:3",
"-feature",
"-deprecation",
"-unchecked",
"-language:higherKinds",
"-language:implicitConversions",
"-language:postfixOps",
"-Ywarn-unused:-implicits",
"-Xlint"
)
)
)

name := "consensus-client"
maintainer := "Units Network Team"

libraryDependencies ++= Seq(
"com.wavesplatform" % "node-testkit" % "1.5.8" % "test",
"com.wavesplatform" % "node" % "1.5.8" % "provided",
"com.wavesplatform" % "node-testkit" % "1.5.8" % Test,
"com.wavesplatform" % "node" % "1.5.8" % Provided,
"com.softwaremill.sttp.client3" % "core_2.13" % "3.10.1",
"com.softwaremill.sttp.client3" %% "play-json" % "3.10.1",
"com.github.jwt-scala" %% "jwt-play-json" % "10.0.1"
)

scalacOptions ++= Seq(
"-Xsource:3",
"-feature",
"-deprecation",
"-unchecked",
"-language:higherKinds",
"-language:implicitConversions",
"-language:postfixOps",
"-Ywarn-unused:-implicits",
"-Xlint"
)

Compile / packageDoc / publishArtifact := false

def makeJarName(
Expand Down Expand Up @@ -81,3 +87,23 @@ buildTarballsForDocker := {
baseDirectory.value / "docker" / "target" / "consensus-client.tgz"
)
}

inTask(docker)(
Seq(
imageNames := Seq(
ImageName(s"consensus-client:${gitCurrentBranch.value}"), // Integration tests
ImageName("consensus-client:local") // local-network
),
dockerfile := NativeDockerfile(baseDirectory.value / "docker" / "Dockerfile"),
buildOptions := BuildOptions(cache = true)
)
)

docker := docker.dependsOn(LocalRootProject / buildTarballsForDocker).value

lazy val `consensus-client` = project.in(file("."))

lazy val `consensus-client-it` = project
.dependsOn(
`consensus-client` % "compile;test->test"
)
67 changes: 67 additions & 0 deletions consensus-client-it/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import com.github.sbt.git.SbtGit.git.gitCurrentBranch
import sbt.Tests.Group

import java.time.LocalDateTime
import java.time.format.DateTimeFormatter

description := "Consensus client integration tests"

libraryDependencies ++= Seq(
"org.testcontainers" % "testcontainers" % "1.20.3",
"org.web3j" % "core" % "4.9.8"
).map(_ % Test)

val logsDirectory = taskKey[File]("The directory for logs") // Task to evaluate and recreate the logs directory every time

Global / concurrentRestrictions := {
val threadNumber = Option(System.getenv("SBT_IT_TEST_THREADS")).fold(1)(_.toInt)
Seq(Tags.limit(Tags.ForkedTestGroup, threadNumber))
}

inConfig(Test)(
Seq(
logsDirectory := {
val runId: String = Option(System.getenv("RUN_ID")).getOrElse(DateTimeFormatter.ofPattern("MM-dd--HH_mm_ss").format(LocalDateTime.now))
val r = target.value / "test-logs" / runId
r.mkdirs()
r
},
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}"
),
testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-fFWD", ((Test / logsDirectory).value / "summary.log").toString),
fork := true,
testForkedParallel := true,
testGrouping := {
val javaHomeVal = (test / javaHome).value
val baseLogDirVal = (Test / logsDirectory).value
val envVarsVal = (Test / envVars).value
val javaOptionsVal = (Test / javaOptions).value

val tests = (Test / definedTests).value

tests.zipWithIndex.map { case (suite, i) =>
val suiteLogDir = baseLogDirVal / suite.name.replaceAll("""(\w)\w*\.""", "$1.") // foo.bar.Baz -> f.b.Baz
Group(
suite.name,
Seq(suite),
Tests.SubProcess(
ForkOptions(
javaHome = javaHomeVal,
outputStrategy = (Test / outputStrategy).value,
bootJars = Vector.empty[java.io.File],
workingDirectory = Option((Test / baseDirectory).value),
runJVMOptions = Vector(
s"-Dcc.it.logs.dir=$suiteLogDir"
) ++ javaOptionsVal,
connectInput = false,
envVars = envVarsVal
)
)
)
}
}
)
)
Loading

0 comments on commit e51a320

Please sign in to comment.