This repository has been archived by the owner on Jan 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(vlei): testing if the vlei server is up and running
Caveat: This should be automated when deployed, changing localhost to actual host value
- Loading branch information
1 parent
19f846d
commit 3d85345
Showing
2 changed files
with
32 additions
and
0 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
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 |
---|---|---|
@@ -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 | ||
} | ||
} | ||
} |