Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KTOR-7359 Implement a suspending version of EmbeddedServer.start and EmbeddedServer.stop #4481

Merged
merged 6 commits into from
Nov 19, 2024

Conversation

whyoleg
Copy link
Contributor

@whyoleg whyoleg commented Nov 14, 2024

Subsystem
Server

Motivation

Solution

Only startSuspend and stopSuspend functions were added with minimal bridge for JVM and Native implementations.
That was done like this, because in most cases users will anyway call start and stop, and it's not clear, which engines could support suspend start/stop (e.g CIO can, for sure, but for others it's not that clear).
That's why minimally invasive changes were implemented to support wasm-js and js case, where runBlocking is not available.

PR also contains changes to EngineTestBase for js and wasm-js as this is the main consumer for those new APIs.

Note: probably some commonization is possible for both EmbeddedServer and EngineTestBase, it should be investigated.

Copy link
Member

@e5l e5l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please check the CI?

* That's why we assign port after the server is started in [startServer]
* Note: this means, that [port] can be used only after calling [createAndStartServer] or [startServer].
*/
private var _port: Int = 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider extracting a constant for non initialized value and use a different value (other than default port)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, used -1

@@ -101,7 +125,8 @@ actual constructor(
// we start it on the global scope because we don't want it to fail the whole test
// as far as we have retry loop on call side
val starting = GlobalScope.async {
server.start(wait = false)
server.startSuspend(wait = false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make an extension function here like server.listeningPorts()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that the commend was for this line:

_port = server.engine.resolvedConnectors().first().port

I don't think, that we do really need this, as this is rather specific and mostly needed in tests where we need to launch both server and client (e.g ktor, or in projects like rsocket-kotlin)

@e5l
Copy link
Member

e5l commented Nov 15, 2024

Please check the code style problems

Copy link
Member

@osipxd osipxd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Could you rebase the PR one more time? 🙏

@osipxd osipxd merged commit ba4d001 into ktorio:3.1.0-eap Nov 19, 2024
10 of 13 checks passed
osipxd pushed a commit that referenced this pull request Nov 22, 2024
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
e5l pushed a commit that referenced this pull request Nov 25, 2024
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
e5l pushed a commit that referenced this pull request Nov 26, 2024
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
e5l pushed a commit that referenced this pull request Nov 27, 2024
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
e5l pushed a commit that referenced this pull request Nov 28, 2024
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
e5l pushed a commit that referenced this pull request Nov 29, 2024
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
e5l pushed a commit that referenced this pull request Dec 3, 2024
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
e5l pushed a commit that referenced this pull request Dec 3, 2024
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
osipxd pushed a commit that referenced this pull request Dec 6, 2024
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
osipxd pushed a commit that referenced this pull request Dec 11, 2024
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
osipxd pushed a commit that referenced this pull request Dec 11, 2024
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
osipxd pushed a commit that referenced this pull request Dec 12, 2024
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
osipxd pushed a commit that referenced this pull request Dec 12, 2024
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
osipxd pushed a commit that referenced this pull request Dec 12, 2024
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
osipxd pushed a commit that referenced this pull request Dec 19, 2024
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
Stexxe pushed a commit that referenced this pull request Dec 24, 2024
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
e5l pushed a commit that referenced this pull request Jan 8, 2025
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
osipxd pushed a commit that referenced this pull request Jan 8, 2025
…EmbeddedServer.stop (#4481)

* Add startSuspend/stopSuspend in EmbeddedServer
* Make EngineTestBase work on js/wasmJs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants