-
Notifications
You must be signed in to change notification settings - Fork 422
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
Add Scala.js support to sttp client #860
Conversation
@adamw I looked briefly at your changes in the http4s server for client tests. If I understand it correctly, it listens on a port dynamically provided by the OS now. The issue is that with the separation between client tests and the testserver as done in this PR, we need a hardcoded port (this approach is also used in sttp). Especially since we can't really configure the ScalaTest JS runner from the build. |
@sbrunk yeah you are right, we'll have to bring back the hard-coded port for the client tests (server tests are the most problematic here anyway, as they allocate a lot of ports). But I'm stuck on fixing some flaky tests to be able to release again since a couple of days, and these are some of my attempts to mitigate the problem. It's better, but not yet fixed ;) |
984b7c4
to
5f1de53
Compare
With
Do you know if it's possible to log the full raw request/response in sttp or in http4s testserver when running the tests somehow? I think it could be helpful to see how the first request is different when using a JVM backend. In the second test it seems the JS version is missing the charset. Meaning it sets the |
So I was playing a bit with cURL it seems in the first test the issue is that I haven't looked into it yet, but my guess is that perhaps the header is overwritten in sttp's fetch backend? Apparently when using |
So that's the header of the part that is being changed? Look at the it seems that custom content-type can only be set for blobs, and otherwise headers are not added. This might be a limitation of the backend - which would mean that we cannot do much. Or it might be that headers can be somehow added in the fetch implementation as well, but we're simply not doing it (yet :) ) |
Ah sorry I meant
To actually work, the
Using the JavaScript |
I did a quick test by changing sttp's PR coming soon. |
The multipart tests pass now by using The remaining blocker is now this exception in the test runner when running
I have to admit I'm a bit clueless where to start looking for the cause here. I've already asked on the Scala.js gitter channel but without an answer so far. I've also started to write down which tests cause this by commenting them out one by one, because it only happens in ~8 tests or so, so perhaps we can see a pattern there. I'll post the list here when I'm done finding all tests causing this error. |
Hm never saw that error as well - do you have a single test that's failing like that? Could be easier to investigate. Are these only multipart tests? |
Here's the list. The failing ones all come from
tapir/client/tests/src/main/scala/sttp/tapir/client/tests/ClientBasicTests.scala Lines 67 to 68 in 6826ffc
|
Besides these four tests that cause the runner failure, we now have one remaining failing test:
In this test: tapir/client/tests/src/main/scala/sttp/tapir/client/tests/ClientBasicTests.scala Lines 44 to 51 in 4852803
Given this response from the testserver:
It seems like there's something wrong with how the response headers are converted to a list here. |
Turns out this is actually a restriction of how the the According to https://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html that's actually allowed by HTTP.
So the question is what we should do about it. |
@sbrunk multi-header support is something that differs from client to client and server to server. If fetch behaves this way, we have to embrace that and adjust the test - I think checking that there's either three headers or one combined would be sufficient |
f41955a
to
6edf86b
Compare
Make client tests async so we can run them on JS. Move client testserver into its own sbt subproject so we can use it from the ScalaTest JS runner.
6edf86b
to
24d8972
Compare
@adamw I've adjusted the test accordingly and rebased against master. I've also created https://github.com/scala-js/scala-js/issues/4310 due to the test runner failures, perhaps the Scala.js devs have an idea what could cause that issue. |
0313fbf
to
dbbcd0b
Compare
42cff45
to
419f891
Compare
@adamw I added support for using Firefox with geckodriver (including autmatic download) as a replacement for Chrome/chromedriver and it is working locally now. Unfortunately it still doesn't work in GH actions due to memory issues even with a larger heap. The build often seems to hang at some point without any output, and when it fails, there are no logs. |
I've done some experiments splitting linking and test into different steps (in a new branch). Giving the JVM in the linking step 6G heap and during the test 1G gets us a little bit further. With this setup, the tests seem to finish but then the build fails with a timeout trying to connect to the browser: My suspicion is that the tests start to many Firefox instances and only clean them up at the end so the runner runs out of resources. |
@sbrunk this size of memory consumption seems suspicious, in sttp-client we've got more JS modules and the tests pass fine. But maybe it's a chrome vs firefox problem? Can we somehow start a single firefox instance or is that not possible? |
Workaround until scala-js/scala-js#4317 has a solution
@adamw looks like this is due to a current limitation of the sbt test framework integration. See scala-js/scala-js#4317. It only shows up now because Firefox needs a little bit more memory than Chrome which makes a difference with ~30 processes running at the same time... The suggested workaround is to call tapir/.github/workflows/ci.yml Lines 34 to 38 in 0b00138
So if you're ok with that workaround for now this PR should be ready for review now. |
Actually now it occurred to me that maybe a simplification is possible. We only really need to start firefox for Another question - shouldn't we enumerate (in gh actions ci.yml) both e.g. |
@adamw yes that's what I had done initially but you suggested self-contained build without having to install node so I went with the full browser approach (see our discussion in #815 (comment)).
Ah yes good catch. Totally missed 2.12 in the workaround. |
Released in https://github.com/softwaremill/tapir/releases/tag/v0.17.0-M11 - thanks! |
This builds on top of #815.
sttp-client
to Scala.js.This is still a draft because it relies on a published artifact of
com.softwaremill.common:tagging
for Scala.js 1 (right now it's only published for Scala.js 0.6). I could build this locally from the repo without any changes, so it really only needs publishing.There are also still some failing tests.
SttpClientMultipartTests
are failing and a bunch of tests fromSttpClientBasicTests
are also failing with a weird stacktrace (if I comment these out, 32 tests pass). The first test causing this isStacktrace:
So this needs some more investigation.
I also saw that you just changed the client testserver a bit @adamw but I haven't rebased yet because there are some conflicts due to moving the testserver into its own module.