-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create E2E test infrastructure (#172)
This PR aims to create the infrastructure for all E2E Testing done in this project. Adds the following: - New Module called Suites -> This aims to separate E2E tests from any implementations. - Uses JUint 5 as a testing framework. - Clear test separation, which will allow for easier test plan implementation in the future. - Uses testcontainers to managa and handle Block Node Application containers - Include the first test from the test plan #183 Signed-off-by: georgi-l95 <[email protected]>
- Loading branch information
1 parent
9dae530
commit 5ab76fd
Showing
12 changed files
with
495 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
## | ||
# Copyright (C) 2024 Hedera Hashgraph, LLC | ||
# | ||
# 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. | ||
## | ||
name: "E2E Test Suites" | ||
on: | ||
push: | ||
branches: | ||
- main | ||
- release/* | ||
pull_request: | ||
branches: | ||
- "*" | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
env: | ||
GRADLE_EXEC: ./gradlew | ||
|
||
jobs: | ||
e2e-tests: | ||
runs-on: block-node-linux-medium | ||
steps: | ||
- name: Harden Runner | ||
uses: step-security/harden-runner@17d0e2bd7d51742c71671bd19fa12bdc9d40a3d6 # v2.8.1 | ||
with: | ||
egress-policy: audit | ||
|
||
- name: Checkout code | ||
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Expand Shallow Clone for Spotless | ||
run: | | ||
if [ -f .git/shallow ]; then | ||
git fetch --unshallow --no-recurse-submodules | ||
else | ||
echo "Repository is not shallow, no need to unshallow." | ||
fi | ||
- name: Set up JDK 21 | ||
uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 # v4.2.1 | ||
with: | ||
distribution: 'temurin' | ||
java-version: '21' | ||
|
||
- name: Build application | ||
run: ${{ env.GRADLE_EXEC }} build | ||
|
||
- name: Run Acceptance Tests | ||
id: acceptance-tests | ||
run: ${GRADLE_EXEC} runSuites |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
buildSrc/src/main/kotlin/com.hedera.block.suites.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright (C) 2024 Hedera Hashgraph, LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
plugins { | ||
id("application") | ||
id("com.hedera.block.conventions") | ||
id("me.champeau.jmh") | ||
} | ||
|
||
val maven = publishing.publications.create<MavenPublication>("maven") { from(components["java"]) } | ||
|
||
signing.sign(maven) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (C) 2022-2024 Hedera Hashgraph, LLC | ||
* | ||
* 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. | ||
*/ | ||
|
||
plugins { | ||
id("application") | ||
id("com.hedera.block.suites") | ||
} | ||
|
||
description = "Hedera Block Node E2E Suites" | ||
|
||
application { | ||
mainModule = "com.hedera.block.suites" | ||
mainClass = "com.hedera.block.suites.BaseSuite" | ||
} | ||
|
||
mainModuleInfo { | ||
requires("org.junit.jupiter.api") | ||
requires("org.junit.platform.suite.api") | ||
requires("org.testcontainers") | ||
requires("io.github.cdimascio") | ||
runtimeOnly("org.testcontainers.junit-jupiter") | ||
runtimeOnly("org.junit.jupiter.engine") | ||
} | ||
|
||
val updateDockerEnv = | ||
tasks.register<Exec>("updateDockerEnv") { | ||
description = | ||
"Creates the .env file in the docker folder that contains environment variables for Docker" | ||
group = "docker" | ||
|
||
workingDir(layout.projectDirectory.dir("../server/docker")) | ||
commandLine("./update-env.sh", project.version) | ||
} | ||
|
||
// Task to build the Docker image | ||
tasks.register<Exec>("createDockerImage") { | ||
description = "Creates the Docker image of the Block Node Server based on the current version" | ||
group = "docker" | ||
|
||
dependsOn(updateDockerEnv, tasks.assemble) | ||
workingDir(layout.projectDirectory.dir("../server/docker")) | ||
commandLine("./docker-build.sh", project.version, layout.projectDirectory.dir("..").asFile) | ||
} | ||
|
||
tasks.register<Test>("runSuites") { | ||
description = "Runs E2E Test Suites" | ||
group = "suites" | ||
dependsOn("createDockerImage") | ||
|
||
useJUnitPlatform() | ||
testLogging { events("passed", "skipped", "failed") } | ||
testClassesDirs = sourceSets["main"].output.classesDirs | ||
classpath = sourceSets["main"].runtimeClasspath | ||
} |
124 changes: 124 additions & 0 deletions
124
suites/src/main/java/com/hedera/block/suites/BaseSuite.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Copyright (C) 2022-2024 Hedera Hashgraph, LLC | ||
* | ||
* 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 com.hedera.block.suites; | ||
|
||
import io.github.cdimascio.dotenv.Dotenv; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.wait.strategy.Wait; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
/** | ||
* BaseSuite is an abstract class that provides common setup and teardown functionality for test | ||
* suites using Testcontainers to manage a Docker container for the Block Node server. | ||
* | ||
* <p>This class is responsible for: | ||
* | ||
* <ul> | ||
* <li>Starting a Docker container running the Block Node Application with a specified version. | ||
* <li>Stopping the container after tests have been executed. | ||
* </ul> | ||
* | ||
* <p>The Block Node Application version is retrieved dynamically from an environment file (.env). | ||
*/ | ||
public abstract class BaseSuite { | ||
|
||
/** Container running the Block Node Application */ | ||
protected static GenericContainer<?> blockNodeContainer; | ||
|
||
/** Port that is used by the Block Node Application */ | ||
protected static int blockNodePort; | ||
|
||
/** | ||
* Default constructor for the BaseSuite class. | ||
* | ||
* <p>This constructor can be used by subclasses or the testing framework to initialize the | ||
* BaseSuite. It does not perform any additional setup. | ||
*/ | ||
public BaseSuite() { | ||
// No additional setup required | ||
} | ||
|
||
/** | ||
* Setup method to be executed before all tests. | ||
* | ||
* <p>This method initializes the Block Node server container using Testcontainers. | ||
*/ | ||
@BeforeAll | ||
public static void setup() { | ||
blockNodeContainer = getConfiguration(); | ||
blockNodeContainer.start(); | ||
} | ||
|
||
/** | ||
* Teardown method to be executed after all tests. | ||
* | ||
* <p>This method stops the Block Node server container if it is running. It ensures that | ||
* resources are cleaned up after the test suite execution is complete. | ||
*/ | ||
@AfterAll | ||
public static void teardown() { | ||
if (blockNodeContainer != null) { | ||
blockNodeContainer.stop(); | ||
} | ||
} | ||
|
||
/** | ||
* Retrieves the configuration for the Block Node server container. | ||
* | ||
* <p>This method initializes the Block Node container with the version retrieved from the .env | ||
* file. It configures the container and returns it. | ||
* | ||
* <p>Specific configuration steps include: | ||
* | ||
* <ul> | ||
* <li>Setting the environment variable "VERSION" from the .env file. | ||
* <li>Exposing the default gRPC port (8080). | ||
* <li>Using the Testcontainers health check mechanism to ensure the container is ready. | ||
* </ul> | ||
* | ||
* @return a configured {@link GenericContainer} instance for the Block Node server | ||
*/ | ||
public static GenericContainer<?> getConfiguration() { | ||
String blockNodeVersion = BaseSuite.getBlockNodeVersion(); | ||
blockNodePort = 8080; | ||
blockNodeContainer = | ||
new GenericContainer<>( | ||
DockerImageName.parse("block-node-server:" + blockNodeVersion)) | ||
.withExposedPorts(blockNodePort) | ||
.withEnv("VERSION", blockNodeVersion) | ||
.waitingFor(Wait.forListeningPort()) | ||
.waitingFor(Wait.forHealthcheck()); | ||
return blockNodeContainer; | ||
} | ||
|
||
/** | ||
* Retrieves the Block Node server version from the .env file. | ||
* | ||
* <p>This method loads the .env file from the "../server/docker" directory and extracts the | ||
* value of the "VERSION" environment variable, which represents the version of the Block Node | ||
* server to be used in the container. | ||
* | ||
* @return the version of the Block Node server as a string | ||
*/ | ||
private static String getBlockNodeVersion() { | ||
Dotenv dotenv = Dotenv.configure().directory("../server/docker").filename(".env").load(); | ||
|
||
return dotenv.get("VERSION"); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
suites/src/main/java/com/hedera/block/suites/grpc/GrpcTestSuites.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (C) 2022-2024 Hedera Hashgraph, LLC | ||
* | ||
* 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 com.hedera.block.suites.grpc; | ||
|
||
import com.hedera.block.suites.grpc.negative.NegativeServerAvailabilityTests; | ||
import com.hedera.block.suites.grpc.positive.PositiveServerAvailabilityTests; | ||
import org.junit.platform.suite.api.SelectClasses; | ||
import org.junit.platform.suite.api.Suite; | ||
|
||
/** | ||
* Test suite for running gRPC server availability tests, including both positive and negative test | ||
* scenarios. | ||
* | ||
* <p>This suite aggregates the tests from {@link PositiveServerAvailabilityTests} and {@link | ||
* NegativeServerAvailabilityTests}. The {@code @Suite} annotation allows running all selected | ||
* classes in a single test run. | ||
*/ | ||
@Suite | ||
@SelectClasses({PositiveServerAvailabilityTests.class, NegativeServerAvailabilityTests.class}) | ||
public class GrpcTestSuites { | ||
|
||
/** | ||
* Default constructor for the {@link GrpcTestSuites} class. This constructor is empty as it | ||
* does not need to perform any initialization. | ||
*/ | ||
public GrpcTestSuites() {} | ||
} |
Oops, something went wrong.