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-7675 Support CIO client for wasm-js and js #4441

Merged
merged 10 commits into from
Nov 8, 2024

Conversation

whyoleg
Copy link
Contributor

@whyoleg whyoleg commented Nov 1, 2024

Subsystem
Client CIO

Motivation
Fixes: https://youtrack.jetbrains.com/issue/KTOR-7675/Client-CIO-engine-support-for-wasm-js-and-js
It's a preparation for server CIO support for wasm-js and js.

Solution
Most of the code in ktor-client-cio is just copied with minor changes.
The most of the changes are related to two general parts in client tests:

  • support for client engines registration for wasm-js and js too support automatic engine selection and allows to dynamically access registered engines in ktor-client-tests
  • commonize ktor-client-tests code and align logic of filtering between platforms

@whyoleg whyoleg changed the title Support CIO client for wasm-js and js KTOR-7675 Support CIO client for wasm-js and js Nov 1, 2024
onlyWithEngine: String?,
block: suspend TestClientBuilder<HttpClientEngineConfig>.() -> Unit
) {
if (skipEngines.any { it.startsWith("native") }) return
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: because of this condition, some of the tests previously were skipped wrong.

E.g if f.e there were skipEngines=listOf("native:CIO"), because of this condition (startsWith("native")), the test was skipped for all engines on native.

Because it's fixed now, some of the test are failed on CI :)
I will skip again some of them - probably all other tests should be checked also for false positive - e.g if it says skip then it should fail - not sure how it will work on practice

@osipxd osipxd self-requested a review November 4, 2024 16:36
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.

Thank you for the pull request!
I have just a few minor comments.

HttpClientEngineContainer::class.java,
HttpClientEngineContainer::class.java.classLoader
).iterator()
}.toList()
Copy link
Member

Choose a reason for hiding this comment

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

toList conversion could be omitted

Suggested change
}.toList()
}

Copy link
Member

Choose a reason for hiding this comment

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

I've created a separate task to fix this ServiceLoader issue in the whole project: KTOR-7698

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 will drop changes in this file from this PR.

Yeah, we could drop toList here, but overall, it's more of a safeguard for not calling ServiceLoader.load multiple times: as Iterable { ... } factory will call lambda (creating Iterator), and so ServiceLoader.load each time it's accessed.
e.g:

val engines = Iterable { ... }

val a1 = engines.firstOrNull() // will create iterator
val a2 = engines.firstOrNull() // will create one more iterator

Just to keep in mind, and probably in this case would be nice to document this somewhere


/**
* Helper interface to test client.
*/
expect abstract class ClientLoader(timeoutSeconds: Int = 60) {
abstract class ClientLoader(private val timeout: Duration = 1.minutes) {
/**
* Perform test against all clients from dependencies.
*/
fun clientTests(
skipEngines: List<String> = emptyList(),
Copy link
Member

Choose a reason for hiding this comment

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

Off-topic. This parameter was always confusing for me because clientTests calls usually look like clientTests(listOf("Js", "Jetty")) and I read it like "run tests on Js and Jetty clients" which is completely opposite to the truth.
If it is not only me, I'll create an issue.

Copy link
Contributor Author

@whyoleg whyoleg Nov 5, 2024

Choose a reason for hiding this comment

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

I agree, it's very confusing, though, listing all engines to run tests will be worse, as it will be too wordy in most cases and probably not worth it.

As a middle ground, it's possible to add vararg hack: Unit as a first argument to enforce named arguments :)
Credits for this wild idea goes to https://github.com/typesafegithub/github-workflows-kt/blob/52701fc95016d449a150a68f57763b365a429d47/github-workflows-kt/src/main/kotlin/io/github/typesafegithub/workflows/dsl/JobBuilder.kt#L65
Not sure it's worth it, but at least it will be much more explicit.

Copy link
Member

Choose a reason for hiding this comment

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

KTOR-7723 Engine exclusion from clientTests is confusing

@osipxd osipxd self-requested a review November 7, 2024 09:05
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! Thanks

@whyoleg
Copy link
Contributor Author

whyoleg commented Nov 8, 2024

@osipxd, just curious, is there anything else needed from my side, so that the PR could be merged?
I'm already ready to create the last PR in a series with server support :)

@osipxd
Copy link
Member

osipxd commented Nov 8, 2024

Nothing! I was just waiting for CI and then forgot to merge this.
Thank you for pinging me!

@osipxd osipxd merged commit 4a8a103 into ktorio:3.1.0-eap Nov 8, 2024
11 of 13 checks passed
osipxd pushed a commit that referenced this pull request Nov 8, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
@whyoleg whyoleg deleted the commonize-cio-client branch November 8, 2024 16:39
e5l pushed a commit that referenced this pull request Nov 13, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
e5l pushed a commit that referenced this pull request Nov 14, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
osipxd pushed a commit that referenced this pull request Nov 16, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
e5l pushed a commit that referenced this pull request Nov 19, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
osipxd pushed a commit that referenced this pull request Nov 22, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
e5l pushed a commit that referenced this pull request Nov 25, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
e5l pushed a commit that referenced this pull request Nov 26, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
e5l pushed a commit that referenced this pull request Nov 27, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
e5l pushed a commit that referenced this pull request Nov 28, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
e5l pushed a commit that referenced this pull request Nov 29, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
e5l pushed a commit that referenced this pull request Dec 3, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
e5l pushed a commit that referenced this pull request Dec 3, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
osipxd pushed a commit that referenced this pull request Dec 6, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
osipxd pushed a commit that referenced this pull request Dec 11, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
osipxd pushed a commit that referenced this pull request Dec 12, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
osipxd pushed a commit that referenced this pull request Dec 12, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
osipxd pushed a commit that referenced this pull request Dec 19, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
Stexxe pushed a commit that referenced this pull request Dec 24, 2024
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
e5l pushed a commit that referenced this pull request Jan 8, 2025
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
osipxd pushed a commit that referenced this pull request Jan 9, 2025
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
osipxd pushed a commit that referenced this pull request Jan 9, 2025
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
osipxd pushed a commit that referenced this pull request Jan 9, 2025
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(js+wasmJs)
osipxd pushed a commit that referenced this pull request Jan 9, 2025
* Support multiple client engines for JS/WasmJs
* CIO client Js/WasmJs support
* Enable CIO tests in client tests
* Make client engines `data object` to have `toString`
* Make ClientLoader work with multiple engines on js/wasmJs and so test CIO engine on nodejs(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.

2 participants