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

Support dart2wasm in node.js tests #2259

Merged
merged 10 commits into from
Aug 27, 2024
Merged

Conversation

simolus3
Copy link
Contributor

Support dart2wasm as a compiler for tests running in Node.js. dart2wasm emits a .mjs file exporting definitions to load generated wasm modules, the only additional thing we have to do is wrap that in a simple entrypoint file compiling the wasm module and invoking the startup wrapper.

There's no support for stack trace maps yet. We also don't support precompiled node wasm tests yet (dart2wasm is also not currently supported by build_web_compilers, so we're blocked on that either way).

In the test runtime, I had to migrate off require as that function is not in the global context for .mjs files. It looks like we can use await import instead though. If we need to support ancient Node versions that lack import support, I can adapt that to still use require when compiled with dart2js for compatibility.

@simolus3 simolus3 changed the title Support dart2wasm in node.js Support dart2wasm in node.js tests Jul 26, 2024
@natebosch
Copy link
Member

I'm not worried about supporting old node versions. I think using import should be fine.

My initial reaction was to not want to adopt more complexity for node (which I still hope to separate out to a different package if we find the time for it), but this doesn't look like it will cause extra maintenance burden for us. @jakemac53 do you have any concerns?

@jakemac53
Copy link
Contributor

I am generally comfortable with this, yes.

@simolus3
Copy link
Contributor Author

simolus3 commented Aug 1, 2024

Speaking of old node versions, the ubuntu-latest image on GitHub actions ships Node.js version 18 which is too old to support the WebAssembly modules generated by dart2wasm.

I guess we can use actions/setup-node, but I'm not sure if mono_repo allows adding custom actions steps to stages? And that's probably the kind of maintenance burden you were hoping to avoid...

@jakemac53
Copy link
Contributor

I guess we can use actions/setup-node, but I'm not sure if mono_repo allows adding custom actions steps to stages? And that's probably the kind of maintenance burden you were hoping to avoid...

Hmm, yeah I don't think it supports that.

@simolus3
Copy link
Contributor Author

simolus3 commented Aug 2, 2024

I have changed the tests to skip dart2wasm if we're running on older node versions. That's not great because it means that this feature is not tested in the CI, but it also means that we won't have to change the CI setup (and at some point ubuntu-latest will ship a recent node version).

@natebosch natebosch requested a review from a team as a code owner August 23, 2024 00:20
Consistent versions to make CI happier.
Copy link

github-actions bot commented Aug 23, 2024

PR Health

Package publish validation ✔️
Package Version Status
package:checks 0.3.1-wip WIP (no publish necessary)
package:test 1.25.9-wip WIP (no publish necessary)
package:test_api 0.7.4-wip WIP (no publish necessary)
package:test_core 0.6.6-wip WIP (no publish necessary)

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

@natebosch
Copy link
Member

I fixed up some of the failing CI jobs. It looks like there are still some legitimate failures.

[Node.js, Dart2Wasm] loading test/hello_world_test.dart (failed)
  Generated wasm module '/tmp/dart_test_WWPNVK/test_KVONWA/hello_world_test.dart.node_test.dart.wasm.wasm', and JS init file '/tmp/dart_test_WWPNVK/test_KVONWA/hello_world_test.dart.node_test.dart.wasm.mjs'.
  node:internal/process/promises:288
              triggerUncaughtException(err, true /* fromPromise */);
              ^
  [CompileError: WebAssembly.compileStreaming(): expected signature definition 0x60, got 0x4e @+13]
  Node.js v[18](https://github.com/dart-lang/test/actions/runs/10523203385/job/29176912922?pr=2259#step:6:21).20.4
  TimeoutException after 0:12:00.000000: Test timed out after 12 minutes.
  package:test_api/src/backend/invoker.dart 338:28  Invoker._handleError.<fn>
  dart:async/zone.dart 1391:47                      _rootRun
  dart:async/zone.dart 1301:[19](https://github.com/dart-lang/test/actions/runs/10523203385/job/29176912922?pr=2259#step:6:22)                      _CustomZone.run
  package:test_api/src/backend/invoker.dart 336:10  Invoker._handleError
  package:test_api/src/backend/invoker.dart 291:9   Invoker.heartbeat.<fn>.<fn>
  dart:async/zone.dart 1399:13                      _rootRun
  dart:async/zone.dart 1301:19                      _CustomZone.run
  package:test_api/src/backend/invoker.dart 290:38  Invoker.heartbeat.<fn>
  dart:async-patch/timer_patch.dart 18:15           Timer._createTimer.<fn>
  dart:isolate-patch/timer_impl.dart 398:19         _Timer._runTimers
  dart:isolate-patch/timer_impl.dart 4[29](https://github.com/dart-lang/test/actions/runs/10523203385/job/29176912922?pr=2259#step:6:32):5          _Timer._handleMessage
  dart:isolate-patch/isolate_patch.dart 184:12      _RawReceivePort._handleMessage

@natebosch
Copy link
Member

It also looks like some of the tests are timing out with a really poor UX - the test runner isn't noticing it and the tests are spinning. I'm not sure if thats a new issue, or if it's surfacing an existing issue with some types of timeouts

@simolus3
Copy link
Contributor Author

It also looks like some of the tests are timing out with a really poor UX - the test runner isn't noticing it and the tests are spinning. I'm not sure if thats a new issue, or if it's surfacing an existing issue with some types of timeouts

This is caused by old Node versions not being able to load the dart2wasm-generated WebAssembly modules. This causes the node process to exit before connecting to the server opened by the test runner. The runner unfortunately waits for a connection, so it didn't detect this condition.
I've changed the implementation to throw an error in that case, which then considers the test failed. I've added a test exercising this behavior to ensure we're not hitting these timeouts on unsupported Node versions, but it also means that we can't run the integration tests in Node on GitHub actions.

@natebosch natebosch merged commit 032ef1d into dart-lang:master Aug 27, 2024
49 checks passed
@simolus3 simolus3 deleted the node-wasm branch August 27, 2024 08:22
copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Sep 13, 2024
…l, http, lints, mockito, shelf, test, test_descriptor, typed_data, web, webkit_inspection_protocol, yaml

Revisions updated by `dart tools/rev_sdk_deps.dart`.

args (https://github.com/dart-lang/args/compare/1a24d61..e623652):
  e623652  2024-08-26  Kevin Moore  Fix angle brackets in doc comments (dart-archive/args#281)

browser_launcher (https://github.com/dart-lang/browser_launcher/compare/fa98c77..0acd188):
  0acd188  2024-08-22  Srujan Gaddam  Add CHANGELOG entry for dart-archive/browser_launcher#63 and publish 1.2.2 (dart-archive/browser_launcher#64)

collection (https://github.com/dart-lang/collection/compare/0c1f829..24b75d8):
  24b75d8  2024-08-26  Kevin Moore  Fix angle brackets in doc comments (dart-archive/collection#358)

csslib (https://github.com/dart-lang/csslib/compare/192d720..d486627):
  d486627  2024-08-26  Kevin Moore  Fix angle brackets in doc comments (dart-archive/csslib#206)

ecosystem (https://github.com/dart-lang/ecosystem/compare/8626bff..4ba6f15):
  4ba6f15  2024-09-04  Devon Carew  update the prompt to include `needs-info` (dart-lang/ecosystem#296)
  3496f54  2024-09-02  Moritz  Continue with labeling after error with issue transfer (dart-lang/ecosystem#293)
  bb45d73  2024-09-02  Moritz  Run `dart pub global run mono_repo generate` (dart-lang/ecosystem#295)
  8d5860b  2024-09-01  dependabot[bot]  Bump the github-actions group with 3 updates (dart-lang/ecosystem#297)
  6de3e8c  2024-08-29  Devon Carew  fix calculation for the labels to apply (dart-lang/ecosystem#294)
  183fdd0  2024-08-28  Devon Carew  contribute a prompt benchmarking script (dart-lang/ecosystem#292)
  f7191b7  2024-08-28  Moritz  Transfer issues in `package:trebuchet` (dart-lang/ecosystem#291)
  5da8a7a  2024-08-26  Moritz  Add `package:trebuchet` to repo. (dart-lang/ecosystem#289)
  dd8d12a  2024-08-23  Nate Bosch  Add check label to github action job name (dart-lang/ecosystem#290)

html (https://github.com/dart-lang/html/compare/0da420c..5516387):
  5516387  2024-08-28  Kevin Moore  Drop Pair util class (dart-archive/html#255)
  50837e5  2024-08-28  Nate Bosch  Fix doc comments (dart-archive/html#256)

http (https://github.com/dart-lang/http/compare/b97b8dc..dfeecf0):
  dfeecf0  2024-08-28  Brian Quinlan  Convert a `java.lang.OutOfMemoryError` into a `ClientException` (dart-lang/http#1299)
  a41141d  2024-08-28  Brian Quinlan  cupertino_http: Use `sharedDarwinSource` (dart-lang/http#1290)
  51beb4e  2024-08-28  Yaroslav Vorobev  fix(http_client_conformance_tests): multipart server (dart-lang/http#1292)
  bbfce40  2024-08-28  Brian Quinlan  Add a reference to AdapterWebSocketChannel for WebSocketChannel users (dart-lang/http#1297)
  7f21111  2024-08-21  Moritz  Add PR Health workflow (dart-lang/http#1296)

lints (https://github.com/dart-lang/lints/compare/894b500..9e4fd7d):
  9e4fd7d  2024-09-10  Lenz Paul  Fixes formatting error in the rules.md table (dart-lang/lints#206)
  6580f83  2024-09-05  Sam Rawlins  Remove avoid_null_checks_in_equality_operators from recommended (dart-lang/lints#201)

mockito (https://github.com/dart-lang/mockito/compare/eb4d1da..d0fda0c):
  d0fda0c  2024-09-11  Sam Rawlins  Bump CI tasks to use Dart 3.5.0 as stable
  2259e10  2024-09-11  Sam Rawlins  Pass a Dart language version to the Dart formatter.
  d7a8334  2024-09-10  Sam Rawlins  mockito: stop using deprecated analyzer APIs.

shelf (https://github.com/dart-lang/shelf/compare/9f2dffe..d53a8f9):
  d53a8f9  2024-09-06  Nate Bosch  Prepare to publish shelf_static (dart-lang/shelf#443)
  e725c73  2024-09-06  mx1up  Loosen mime package constraint (dart-lang/shelf#441)
  efbc566  2024-09-05  Nate Bosch  Remove links to core types with generics (dart-lang/shelf#442)

test (https://github.com/dart-lang/test/compare/cd3dbd5..9a2d155):
  9a2d155b  2024-09-11  Nate Bosch  Run package:test tests on mac (dart-lang/test#2280)
  569c6eb6  2024-09-01  dependabot[bot]  Bump the github-actions group with 2 updates (dart-lang/test#2275)
  db8cf091  2024-08-28  Nate Bosch  Remove the Pair utility (dart-lang/test#2271)
  032ef1dc  2024-08-27  Simon Binder  Support dart2wasm in node.js tests (dart-lang/test#2259)
  90481cf8  2024-08-23  Nate Bosch  Limit which health checks run (dart-lang/test#2270)
  337c7fb0  2024-08-21  Moritz  Update publish.yaml (dart-lang/test#2269)

test_descriptor (https://github.com/dart-lang/test_descriptor/compare/90743bc..3b85d38):
  3b85d38  2024-08-26  Kevin Moore  Fix angle brackets in doc comments (dart-lang/test_descriptor#70)

typed_data (https://github.com/dart-lang/typed_data/compare/365468a..2bb9e6e):
  2bb9e6e  2024-08-26  Kevin Moore  Require Dart 3.5, use TypeDataList in many places (dart-archive/typed_data#92)

web (https://github.com/dart-lang/web/compare/fb30192..933a37d):
  933a37d  2024-09-10  Srujan Gaddam  Update dart_style and use latestLanguageVersion (dart-lang/web#301)

webkit_inspection_protocol (https://github.com/google/webkit_inspection_protocol.dart/compare/119b877..e7418d7):
  e7418d7  2024-08-26  Kevin Moore  Update min SDK and a number of lints (google/webkit_inspection_protocol.dart#128)

yaml (https://github.com/dart-lang/yaml/compare/a645c39..b3d299e):
  b3d299e  2024-08-28  Kevin Moore  Drop Pair util class (dart-lang/yaml#169)

Change-Id: Ic3461659a40427c0deaafab8c79cade332f76edb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385302
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Auto-Submit: Devon Carew <devoncarew@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants