Moved multiconnect to it's own test file
This commit is contained in:
parent
1747701037
commit
e61f3e4711
@ -5,16 +5,11 @@ import dorkbox.network.Server
|
|||||||
import dorkbox.network.aeron.AeronDriver
|
import dorkbox.network.aeron.AeronDriver
|
||||||
import dorkbox.network.connection.Connection
|
import dorkbox.network.connection.Connection
|
||||||
import kotlinx.atomicfu.atomic
|
import kotlinx.atomicfu.atomic
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.GlobalScope
|
|
||||||
import kotlinx.coroutines.async
|
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.junit.Assert
|
import org.junit.Assert
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import kotlin.time.Duration.Companion.seconds
|
|
||||||
|
|
||||||
class DisconnectReconnectTest : BaseTest() {
|
class DisconnectReconnectTest : BaseTest() {
|
||||||
private val reconnectCount = atomic(0)
|
private val reconnectCount = atomic(0)
|
||||||
@ -128,55 +123,6 @@ class DisconnectReconnectTest : BaseTest() {
|
|||||||
Assert.assertEquals(4, reconnectCount.value)
|
Assert.assertEquals(4, reconnectCount.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
fun multiConnectClient() {
|
|
||||||
// clients first, so they try to connect to the server at (roughly) the same time
|
|
||||||
val config = clientConfig()
|
|
||||||
|
|
||||||
val client1: Client<Connection> = Client(config)
|
|
||||||
val client2: Client<Connection> = Client(config)
|
|
||||||
|
|
||||||
addEndPoint(client1)
|
|
||||||
addEndPoint(client2)
|
|
||||||
client1.onDisconnect {
|
|
||||||
logger.error("Disconnected 1!")
|
|
||||||
}
|
|
||||||
client2.onDisconnect {
|
|
||||||
logger.error("Disconnected 2!")
|
|
||||||
}
|
|
||||||
|
|
||||||
GlobalScope.launch {
|
|
||||||
client1.connect(LOCALHOST)
|
|
||||||
}
|
|
||||||
|
|
||||||
GlobalScope.launch {
|
|
||||||
client2.connect(LOCALHOST)
|
|
||||||
}
|
|
||||||
|
|
||||||
println("Starting server...")
|
|
||||||
|
|
||||||
run {
|
|
||||||
val configuration = serverConfig()
|
|
||||||
|
|
||||||
val server: Server<Connection> = Server(configuration)
|
|
||||||
addEndPoint(server)
|
|
||||||
server.bind()
|
|
||||||
|
|
||||||
server.onConnect {
|
|
||||||
logger.error("Disconnecting after 10 seconds.")
|
|
||||||
delay(10.seconds)
|
|
||||||
|
|
||||||
logger.error("Disconnecting....")
|
|
||||||
close()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
waitForThreads()
|
|
||||||
|
|
||||||
System.err.println("Connection count (after reconnecting) is: " + reconnectCount.value)
|
|
||||||
Assert.assertEquals(4, reconnectCount.value)
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CloseIface {
|
interface CloseIface {
|
||||||
suspend fun close()
|
suspend fun close()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user