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

Set up pytest node tests #1717

Merged
merged 48 commits into from
Jul 20, 2021
Merged

Set up pytest node tests #1717

merged 48 commits into from
Jul 20, 2021

Conversation

hoodmane
Copy link
Member

No description provided.

@hoodmane
Copy link
Member Author

globalThis is weird in Firefox...

@hoodmane
Copy link
Member Author

Okay we're up to 666/735 core node tests passing and 7 I've xfailed because they use many browser-only APIs. Of the 68 remaining failures, 60 are cascading failures due to timeouts in test_core_python. After a timeout my node driver should probably be refreshed. Or maybe the communication protocol can somehow be fixed up to be able to clean up old garbage in stdout. Might require some work though. Maybe I can raise the default timeout in the short term.

Also, the node tests are REALLY slow. I'm not sure why they are so slow tbh, but it's actually about similar to what happened on my libffi port. There, node tests take 15x longer (sometimes even more), here they only take 6x longer than the selenuim tests.

Copy link
Member

@rth rth left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

xfailing those tests sound good to me.

Interestingly with my node test driver, the time difference between selenium_standalone and selenium doesn't seem very large. test-core-node takes 6x as long as test-core-chrome but test-packages-node only takes 1.25x as long.

Might be due to a 50ms sleep by default after each send command and you are sending line by line.. https://stackoverflow.com/a/60423834/1791279

I think we would need to figure out how to make the test-core[node] faster (if the above idea doesn't work) as otherwise >1h run time is going to difficult to manage in CI and it might mean that we won't be able to run it on PRs (since we only have 4 parallel jobs in CircleCI)

node_test_driver.js Outdated Show resolved Hide resolved
testsetup.js Outdated Show resolved Hide resolved
testsetup.js Outdated Show resolved Hide resolved
ADD docs/requirements-doc.txt requirements.txt /

RUN pip3 --no-cache-dir install -r /requirements.txt \
&& pip3 --no-cache-dir install -r /requirements-doc.txt
Copy link
Member

Choose a reason for hiding this comment

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

It's indeed much better thanks!

conftest.py Outdated Show resolved Hide resolved
@hoodmane
Copy link
Member Author

hoodmane commented Jul 19, 2021

due to a 50ms sleep by default after each send command and you are sending line by line

Hmm. I guess I can try sending all at once.

I think we would need to figure out how to make the test-core[node] faster.

I am working on embedding node into a Python extension so we can avoid this pexpect nonsense. It is working decently so far (I can run_js a Javascript code string and get back the return value). The biggest problem with this approach is that node doesn't seem to ship libnode.so or the other shared libraries from a build. It took around three hours to build node on my local machine. I am just building node in the most standard configuration though:

./configure --shared
make -j4

so I think it would be okay to stash libnode.so somewhere if we can't find someone who has already done this.

@rth
Copy link
Member

rth commented Jul 19, 2021

Hmm. I guess I can try sending all at once.

In the above SO link, there was also the option of setting that sleep value to 0 which should help.

so I think it would be okay to stash libnode.so somewhere if we can't find someone who has already done this.

Yeah, we can't reasonably ask people to build node from sources. I think shipping a .so also likely wouldn't work as that's not portable: it won't work for Linux/MacOS users who are trying to build outside of Docker.

Maybe profiling a typical pexpect session to understand what's going on would help?

@hoodmane
Copy link
Member Author

we can't reasonably ask people to build node from sources

Well this isn't a key aspect of the project, I think we could just tell people that to run node tests they should either use docker or acquire a libnode.so that works on their system?

@hoodmane
Copy link
Member Author

Apparently electron uses libnode.so so maybe we can find it in electron distros?

@rth
Copy link
Member

rth commented Jul 19, 2021

True, but it would overall make contributing more complex if say one of the node tests failed and one need to reproduce. Also even to include that .so into Docker doesn't sound straightforward. I would rather not compile node even for building Docker images.

My point is that it would be good to first try to understand why pexpect is slow. Serializing strings for input/output shouldn't be that much overhead.

@hoodmane
Copy link
Member Author

hoodmane commented Jul 19, 2021

Yeah "embed node into a python module" is a bit in the fun but logistically impractical direction. Also, it's pretty incredible how much better the docs for the Python C api are than for the Node C++ API. The Node / v8 API seems significantly more complicated but the docs are close to nonexistent.

@rth
Copy link
Member

rth commented Jul 19, 2021

Apparently electron uses libnode.so so maybe we can find it in electron distros?

I'm not too familiar with electron distros, but I agree that one of the challenges we have is really to keep the tools we use as simple as possible. It's already and a very complex build setup, so the more additional tools we use the more difficult it is for new contributors to approach it (and also for us to have solid enough expertise in those tools).

@hoodmane
Copy link
Member Author

Here's the discussion where people said it would be good to ship an so (to avoid forcing embedders to build it):
nodejs/node#24028

There is also metacall but documentation is very thin.

@hoodmane
Copy link
Member Author

hoodmane commented Jul 19, 2021

It looks like electron links libnode.a so doesn't distribute it.

@hoodmane
Copy link
Member Author

Yeah hopefully we can make pexpect work, turns out embedding node is a huge can of worms.

@hoodmane
Copy link
Member Author

Looks like delaybeforesend=None did the trick, now node tests run the fastest of the three.

@hoodmane
Copy link
Member Author

Looks like we already xfailed the pillow test on chrome and firefox. I think this is all ready now.

@hoodmane
Copy link
Member Author

@rth Tests all pass. I think this is ready to merge, unless you have further comments.

@rth
Copy link
Member

rth commented Jul 20, 2021

Thanks for working on this @hoodmane !

@rth rth merged commit f0bd568 into pyodide:main Jul 20, 2021
@rth rth deleted the node-tests branch July 20, 2021 08:48
sthagen added a commit to sthagen/pyodide-pyodide that referenced this pull request Jul 20, 2021
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