-
-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
kotlin: mount of coroutine routes doesn't work
- fix #3228
- Loading branch information
Edgar Espina
committed
Feb 26, 2024
1 parent
285fa53
commit 92ee4e7
Showing
2 changed files
with
104 additions
and
24 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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Jooby https://jooby.io | ||
* Apache License Version 2.0 https://jooby.io/LICENSE.txt | ||
* Copyright 2014 Edgar Espina | ||
*/ | ||
package i3228 | ||
|
||
import io.jooby.junit.ServerTest | ||
import io.jooby.junit.ServerTestRunner | ||
import io.jooby.kt.Kooby | ||
import java.util.concurrent.Executor | ||
import org.junit.jupiter.api.Assertions | ||
|
||
class RouterWithoutWorker : | ||
Kooby({ | ||
coroutine { | ||
get("/i3228/without-worker") { | ||
"nonBlocking: " + | ||
ctx.route.isNonBlocking + | ||
", coroutine: " + | ||
ctx.route.attributes["coroutine"] | ||
} | ||
} | ||
}) | ||
|
||
class RouterWithoutWorkerNoCoroutine : | ||
Kooby({ | ||
get("/i3228/without-worker-no-coroutine") { | ||
"nonBlocking: " + | ||
ctx.route.isNonBlocking + | ||
", coroutine: " + | ||
ctx.route.attributes["coroutine"] | ||
} | ||
}) | ||
|
||
class RouterWithWorker(worker: Executor) : | ||
Kooby({ | ||
this.worker = worker | ||
coroutine { | ||
get("/i3228/with-worker") { | ||
"nonBlocking: " + | ||
ctx.route.isNonBlocking + | ||
", coroutine: " + | ||
ctx.route.attributes["coroutine"] | ||
} | ||
} | ||
}) | ||
|
||
class Issue3228 { | ||
@ServerTest | ||
fun shouldCopyCoroutineState(runner: ServerTestRunner) = | ||
runner | ||
.use { | ||
Kooby { -> | ||
mount(RouterWithWorker(this.worker)) | ||
mount(RouterWithoutWorker()) | ||
coroutine { mount(RouterWithoutWorkerNoCoroutine()) } | ||
} | ||
} | ||
.ready { client -> | ||
client.get("/i3228/without-worker") { rsp -> | ||
Assertions.assertEquals("nonBlocking: true, coroutine: true", rsp.body!!.string()) | ||
} | ||
client.get("/i3228/without-worker-no-coroutine") { rsp -> | ||
Assertions.assertEquals("nonBlocking: true, coroutine: true", rsp.body!!.string()) | ||
} | ||
client.get("/i3228/with-worker") { rsp -> | ||
Assertions.assertEquals("nonBlocking: true, coroutine: true", rsp.body!!.string()) | ||
} | ||
} | ||
} |