Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
test(vlei): testing if the vlei server is up and running
Browse files Browse the repository at this point in the history
Caveat: This should be automated when deployed, changing localhost to actual host value
  • Loading branch information
aminbenmansour committed Oct 30, 2023
1 parent 19f846d commit 3d85345
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 -- */

Expand Down Expand Up @@ -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")
Expand Down
29 changes: 29 additions & 0 deletions src/test/kotlin/config/keri/acdc/vlei/ServerTestvLEI.kt
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit 3d85345

Please sign in to comment.