Skip to content

Commit

Permalink
Fix testUpgrade to not wait for a socket to be closed by server
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Mashkov authored and Thorsten Schleinzer committed Feb 26, 2019
1 parent c56dc60 commit 9418e2e
Showing 1 changed file with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1361,6 +1361,8 @@ abstract class EngineTestSuite<TEngine : ApplicationEngine, TConfiguration : App

@Test
open fun testUpgrade() {
val completed = CompletableDeferred<Unit>()

createAndStartServer {
get("/up") {
call.respond(object : OutgoingContent.ProtocolUpgrade() {
Expand All @@ -1372,11 +1374,20 @@ abstract class EngineTestSuite<TEngine : ApplicationEngine, TConfiguration : App

override suspend fun upgrade(input: ByteReadChannel, output: ByteWriteChannel, engineContext: CoroutineContext, userContext: CoroutineContext): Job {
return launch(engineContext) {
val bb = ByteBuffer.allocate(8)
input.readFully(bb)
bb.flip()
output.writeFully(bb)
output.close()
try {
val bb = ByteBuffer.allocate(8)
input.readFully(bb)
bb.flip()
output.writeFully(bb)
output.close()
input.readRemaining().use {
assertEquals(0, it.remaining)
}
completed.complete(Unit)
} catch (t: Throwable) {
completed.completeExceptionally(t)
throw t
}
}
}
})
Expand Down Expand Up @@ -1444,7 +1455,9 @@ abstract class EngineTestSuite<TEngine : ApplicationEngine, TConfiguration : App

assertEquals(0x1122334455667788L, ch.readLong())

assertEquals(-1, ch.readAvailable(ByteArray(1)))
close()

completed.await()
}
}
}
Expand Down

0 comments on commit 9418e2e

Please sign in to comment.