Skip to content

Commit

Permalink
Fix and enable the ignored test again (#263)
Browse files Browse the repository at this point in the history
* Fix and enable the ignored test again

This reverts commit ad102f6.

* Removed unused param

Signed-off-by: Thomas Segismont <[email protected]>

---------

Signed-off-by: Thomas Segismont <[email protected]>
  • Loading branch information
tsegismont authored Feb 17, 2024
1 parent ad102f6 commit ee84097
Showing 1 changed file with 35 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@ import io.vertx.core.Context
import io.vertx.core.Future
import io.vertx.core.Promise
import io.vertx.core.Vertx
import io.vertx.core.http.HttpClientOptions
import io.vertx.core.http.HttpMethod
import io.vertx.core.http.HttpServerOptions
import io.vertx.core.http.RequestOptions
import io.vertx.core.http.*
import io.vertx.core.impl.ContextInternal
import io.vertx.core.impl.VertxInternal
import io.vertx.ext.unit.TestContext
import io.vertx.ext.unit.junit.RunTestOnContext
import io.vertx.ext.unit.junit.VertxUnitRunner
import kotlinx.coroutines.*
import org.junit.After
import org.junit.Assert.*
import org.junit.Ignore
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand All @@ -51,11 +48,21 @@ class VertxCoroutineTest {

private lateinit var vertx: Vertx
private lateinit var ai: AsyncInterface
private lateinit var client: HttpClient
private lateinit var server: HttpServer

@Before
fun before() {
vertx = rule.vertx()
ai = AsyncInterfaceImpl(vertx)
client = vertx.createHttpClient(HttpClientOptions().setDefaultPort(8080))
server = vertx.createHttpServer(HttpServerOptions().setPort(8080))
}

@After
fun tearDown(tc: TestContext) {
client.close()
server.close().onComplete(tc.asyncAssertSuccess())
}

@Test
Expand Down Expand Up @@ -89,31 +96,21 @@ class VertxCoroutineTest {
}

@Test
fun `test fiber Handler`(testContext: TestContext) {
val async = testContext.async()
val server = vertx.createHttpServer(HttpServerOptions().setPort(8080))
fun `test fiber Handler`(tc: TestContext) {
server.requestHandler { req ->
GlobalScope.launch(vertx.dispatcher()) {
val res = awaitResult { ai.methodWithParamsAndHandlerNoReturn("oranges", 23, it) }
assertEquals("oranges23", res)
req.response().end()
}
}
server.listen().onComplete { res ->
assertTrue(res.succeeded())
val client = vertx.createHttpClient(HttpClientOptions().setDefaultPort(8080))
client.request(HttpMethod.GET, "/somepath").onComplete { ar1 ->
assertTrue(ar1.succeeded())
val req = ar1.result()
req.send().onComplete { ar2 ->
assertTrue(ar2.succeeded())
val resp = ar2.result()
assertTrue(resp.statusCode() == 200)
client.close()
server.close().onComplete { async.complete() }
}
}
}
server.listen().onComplete(tc.asyncAssertSuccess {
client.request(HttpMethod.GET, "/somepath").onComplete(tc.asyncAssertSuccess { request ->
request.send().onComplete(tc.asyncAssertSuccess { response ->
assertEquals(200, response.statusCode())
})
})
})
}

@Test
Expand Down Expand Up @@ -448,23 +445,23 @@ class VertxCoroutineTest {
}
}

@Ignore
@Test
fun `test Coroutine execution not always performed with dispatch`(testContext: TestContext) {
val latch = testContext.async()
val context = (vertx as VertxInternal).getOrCreateContext()
val duplicatedContext = context.duplicate()
val httpClient = vertx.createHttpClient()
duplicatedContext.runOnContext {
GlobalScope.launch(Vertx.currentContext().dispatcher()) {
val resp = httpClient.request(RequestOptions().setMethod(HttpMethod.GET).setAbsoluteURI("https://example.com"))
.coAwait().apply { end().coAwait() }
.response()
.coAwait()
resp.body().coAwait()
latch.complete()
fun `test Coroutine execution not always performed with dispatch`(tc: TestContext) {
server.requestHandler { it.response().end() }.listen().onComplete(tc.asyncAssertSuccess {
val latch = tc.async()
val context = (vertx as VertxInternal).getOrCreateContext()
val duplicatedContext = context.duplicate()
duplicatedContext.runOnContext {
GlobalScope.launch(Vertx.currentContext().dispatcher()) {
val resp = client.request(HttpMethod.GET, "/")
.coAwait().apply { end().coAwait() }
.response()
.coAwait()
resp.body().coAwait()
latch.complete()
}
}
}
})
}

@Test
Expand Down

0 comments on commit ee84097

Please sign in to comment.