From 3d853457db407ac5ba6e2c3a2e5d96cabe0396f9 Mon Sep 17 00:00:00 2001 From: aminbenmansour Date: Mon, 30 Oct 2023 03:39:52 +0100 Subject: [PATCH] test(vlei): testing if the vlei server is up and running Caveat: This should be automated when deployed, changing localhost to actual host value --- build.gradle.kts | 3 ++ .../config/keri/acdc/vlei/ServerTestvLEI.kt | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index 858c82f..80c647a 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -40,6 +40,7 @@ dependencies { exclude("com.sksamuel.hoplite", "hoplite-yaml") exclude("com.sksamuel.hoplite", "hoplite-hikaricp") } + testImplementation("org.junit.jupiter:junit-jupiter:5.8.1") /* -- KTOR -- */ @@ -137,6 +138,8 @@ dependencies { testImplementation("io.kotest:kotest-assertions-core:5.5.5") testImplementation("io.kotest.extensions:kotest-assertions-ktor:2.0.0")*/ testImplementation("io.ktor:ktor-server-tests-jvm:$ktorVersion") + testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.2") + testImplementation("org.junit.jupiter:junit-jupiter:5.9.2") // Logging implementation("io.github.oshai:kotlin-logging:5.1.0") diff --git a/src/test/kotlin/config/keri/acdc/vlei/ServerTestvLEI.kt b/src/test/kotlin/config/keri/acdc/vlei/ServerTestvLEI.kt index 4d40889..05e3719 100644 --- a/src/test/kotlin/config/keri/acdc/vlei/ServerTestvLEI.kt +++ b/src/test/kotlin/config/keri/acdc/vlei/ServerTestvLEI.kt @@ -1,4 +1,33 @@ package config.keri.acdc.vlei +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async +import kotlinx.coroutines.runBlocking +import kotlin.test.assertTrue +import java.net.InetSocketAddress +import java.net.Socket +import org.junit.Test class ServerTestvLEI { + @Test + fun testServerAvailability() = runBlocking { + val host = "localhost" + val port = 7723 + + val serverAvailable = async(Dispatchers.IO) { + isServerAvailable(host, port) + } + + assertTrue(serverAvailable.await(), "The server on $host:$port is not available.") + } + + private fun isServerAvailable(host: String, port: Int): Boolean { + return try { + Socket().use { socket -> + socket.connect(InetSocketAddress(host, port), 2000) + true + } + } catch (e: Exception) { + false + } + } } \ No newline at end of file