Skip to content

Commit

Permalink
[Fix] Re-enable gradle test and fork JVM for every integration test c…
Browse files Browse the repository at this point in the history
…lass (#1038)
  • Loading branch information
lijamie98 authored Aug 5, 2023
1 parent 375a86a commit 334a2a9
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/sub_gradle_test_and_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Gradle test and build. (unit tests, integration tests, end-2-end tests and build)
env:
run_docker: false
run: ./gradlew clean build --no-daemon --stacktrace -x test
run: ./gradlew clean build --no-daemon --stacktrace

- name: Stop docker containers
env:
Expand Down
5 changes: 3 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ reactor-netty = { module = "io.projectreactor.netty:reactor-netty", version.ref
scala-library = { module = "org.scala-lang:scala-library", version.ref = "scala-library" }
servlet-api = { module = "javax.servlet:servlet-api", version.ref = "servlet-api" }
sqlite-jdbc = { module = "org.xerial:sqlite-jdbc", version.ref = "sqlite-jdbc" }
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
slf4j-log4j12 = { module = "org.slf4j:slf4j-log4j12", version.ref = "slf4j" }
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j2" }
slf4j-log4j12 = { module = "org.slf4j:slf4j-log4j12", version.ref = "slf4j2" }
slf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j2" }
stellar-wallet-sdk = { module = "org.stellar:wallet-sdk", version.ref = "stellar-wallet-sdk" }
toml4j = { module = "com.moandjiezana.toml:toml4j", version.ref = "toml4j" }
spring-kafka = { module = "org.springframework.kafka:spring-kafka", version.ref = "spring-kafka" }
Expand Down
16 changes: 10 additions & 6 deletions integration-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ plugins {
alias(libs.plugins.kotlin.jvm)
}

repositories {
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
}
}
repositories { maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") } }

dependencies {
implementation("org.springframework.boot:spring-boot")
Expand Down Expand Up @@ -52,4 +48,12 @@ dependencies {
testImplementation(libs.dotenv)
}

tasks { bootJar { enabled = false } }
tasks {
bootJar { enabled = false }
test {
useJUnitPlatform()
// Setting forkEvery to 1 makes Gradle test execution to start a separeate JVM for each integration test classes.
// This is to to avoid the interaction between static states between each integration test classes.
setForkEvery(1)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class AnchorPlatformEnd2EndTest : AbstractIntegrationTest(TestConfig(testProfile
@BeforeAll
@JvmStatic
fun construct() {
println("Running AnchorPlatformEnd2EndTest")
singleton.setUp()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class AnchorPlatformIntegrationTest :
@BeforeAll
@JvmStatic
fun construct() {
println("Running AnchorPlatformIntegrationTest")
singleton.setUp()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ internal class JwtAuthIntegrationTest : AbstractAuthIntegrationTest() {
@BeforeAll
@JvmStatic
fun setup() {
println("Running JwtAuthIntegrationTest")
testProfileRunner =
TestProfileExecutor(
TestConfig(testProfileName = "default").also {
Expand Down Expand Up @@ -261,6 +262,7 @@ internal class ApiKeyAuthIntegrationTest : AbstractAuthIntegrationTest() {
@BeforeAll
@JvmStatic
fun setup() {
println("Running ApiKeyAuthIntegrationTest")
testProfileRunner =
TestProfileExecutor(
TestConfig(testProfileName = "default").also {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class PostgresMigrationTest : AbstractIntegrationTest(PostgresConfig) {
@BeforeAll
@JvmStatic
fun construct() {
println("Running PostgresMigrationTest")
singleton.setUp()
}

Expand All @@ -64,6 +65,7 @@ class H2MigrationTest : AbstractIntegrationTest(H2Config) {
@BeforeAll
@JvmStatic
fun construct() {
println("Running H2MigrationTest")
singleton.setUp()
}

Expand All @@ -87,6 +89,7 @@ class SQLiteMigrationTest : AbstractIntegrationTest(SQLiteConfig) {
@BeforeAll
@JvmStatic
fun construct() {
println("Running SQLiteMigrationTest")
singleton.setUp()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal class KotlinReferenceServerIntegrationTest {

@BeforeAll
fun setup() {
println("Running KotlinReferenceServerIntegrationTest")
testProfileRunner.start()
}

Expand Down

This file was deleted.

4 changes: 1 addition & 3 deletions kotlin-reference-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ dependencies {
implementation(libs.java.stellar.sdk)
implementation(libs.jjwt)
implementation(libs.javax.jaxb.api)

implementation(libs.slf4j.log4j12)
implementation(libs.kotlin.logging)

implementation(libs.slf4j.simple)
implementation(project(mapOf("path" to ":api-schema")))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ fun readCfg(envMap: Map<String, String>?): Config {
}

fun stopServer() {
if (::referenceKotlinSever.isInitialized) (referenceKotlinSever).stop(1000, 1000)
log.info("Stopping Kotlin business reference server...")
if (::referenceKotlinSever.isInitialized) (referenceKotlinSever).stop(5000, 30000)
log.info("Kotlin reference server stopped...")
}

fun Application.configureRouting(cfg: Config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.util.logging.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import mu.KotlinLogging
import org.stellar.reference.ClientException
Expand Down Expand Up @@ -68,7 +68,7 @@ fun Route.testSep24(
val stellarAsset = asset.replace("stellar:", "")

// Run deposit processing asynchronously
CoroutineScope(Job()).launch {
CoroutineScope(Dispatchers.Default).launch {
depositService.processDeposit(
transactionId,
amountExpected,
Expand All @@ -88,7 +88,7 @@ fun Route.testSep24(
val stellarAsset = asset.replace("stellar:", "")

// Run deposit processing asynchronously
CoroutineScope(Job()).launch {
CoroutineScope(Dispatchers.Default).launch {
withdrawalService.processWithdrawal(transactionId, amountExpected, stellarAsset)
}
}
Expand Down
26 changes: 26 additions & 0 deletions kotlin-reference-server/src/main/resources/simplelogger.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# SLF4J's SimpleLogger configuration file
# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.

# Default logging detail level for all instances of SimpleLogger.
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, defaults to "info".
org.slf4j.simpleLogger.defaultLogLevel=INFO

# Logging detail level for a SimpleLogger instance named "xxxxx".
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, the default logging detail level is used.
#org.slf4j.simpleLogger.log.xxxxx=

# Set to true if you want the current date and time to be included in output messages.
# Default is false, and will output the number of milliseconds elapsed since startup.
#org.slf4j.simpleLogger.showDateTime=false

# The date and time format to be used in the output messages.
# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
# If the format is not specified or is invalid, the default format is used.
# The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z

# Set to true if you want to output the current thread name.
# Defaults to true.
#org.slf4j.simpleLogger.showThreadName=true
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void sendToSpring(
icex.getMessage(),
System.lineSeparator());
// We should not continue.
System.exit(1);
throw new RuntimeException(icex);
}
adapter.updateSpringEnv(applicationContext, config);
}
Expand Down
4 changes: 1 addition & 3 deletions wallet-reference-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ dependencies {
implementation(libs.hoplite.yaml)
implementation(libs.java.stellar.sdk)
implementation(libs.kotlin.logging)
implementation(libs.ktor.server.call.logging)
implementation(libs.slf4j.log4j12)

implementation(libs.slf4j.simple)
implementation(project(mapOf("path" to ":api-schema")))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import io.ktor.serialization.kotlinx.json.*
import io.ktor.server.application.*
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.server.plugins.callloging.*
import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.server.plugins.cors.routing.*
import io.ktor.server.routing.*
Expand All @@ -29,7 +28,6 @@ fun startServer(envMap: Map<String, String>?, wait: Boolean) {
walletServer =
embeddedServer(Netty, port = cfg.wallet.port) {
install(ContentNegotiation) { json() }
install(CallLogging)
configureRouting(cfg)
install(CORS) {
anyHost()
Expand Down Expand Up @@ -61,7 +59,9 @@ fun readCfg(envMap: Map<String, String>?): Config {
}

fun stopServer() {
if (::walletServer.isInitialized) (walletServer).stop(1000, 1000)
log.info("Stopping wallet server...")
if (::walletServer.isInitialized) (walletServer).stop(5000, 30000)
log.info("Wallet server stopped...")
}

fun Application.configureRouting(cfg: Config) {
Expand Down
26 changes: 26 additions & 0 deletions wallet-reference-server/src/main/resources/simplelogger.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# SLF4J's SimpleLogger configuration file
# Simple implementation of Logger that sends all enabled log messages, for all defined loggers, to System.err.

# Default logging detail level for all instances of SimpleLogger.
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, defaults to "info".
org.slf4j.simpleLogger.defaultLogLevel=INFO

# Logging detail level for a SimpleLogger instance named "xxxxx".
# Must be one of ("trace", "debug", "info", "warn", or "error").
# If not specified, the default logging detail level is used.
#org.slf4j.simpleLogger.log.xxxxx=

# Set to true if you want the current date and time to be included in output messages.
# Default is false, and will output the number of milliseconds elapsed since startup.
#org.slf4j.simpleLogger.showDateTime=false

# The date and time format to be used in the output messages.
# The pattern describing the date and time format is the same that is used in java.text.SimpleDateFormat.
# If the format is not specified or is invalid, the default format is used.
# The default format is yyyy-MM-dd HH:mm:ss:SSS Z.
#org.slf4j.simpleLogger.dateTimeFormat=yyyy-MM-dd HH:mm:ss:SSS Z

# Set to true if you want to output the current thread name.
# Defaults to true.
#org.slf4j.simpleLogger.showThreadName=true

0 comments on commit 334a2a9

Please sign in to comment.