Title: test: fix flaky test-worker-message-port-transfer-filehandle test by himself65 · Pull Request #59158 · nodejs/node · GitHub
Open Graph Title: test: fix flaky test-worker-message-port-transfer-filehandle test by himself65 · Pull Request #59158 · nodejs/node
X Title: test: fix flaky test-worker-message-port-transfer-filehandle test by himself65 · Pull Request #59158 · nodejs/node
Description: Fixes: #59145 Wrap all script into setInterval and you will see the error 'use strict'; const common = require('../common'); const assert = require('assert'); const fs = require('fs').promises; const vm = require('vm'); const { MessageChannel, moveMessagePortToContext } = require('worker_threads'); const { once } = require('events'); setInterval(async () => { (async function() { const fh = await fs.open(__filename); const { port1, port2 } = new MessageChannel(); assert.throws(() => { port1.postMessage(fh); }, { constructor: DOMException, name: 'DataCloneError', code: 25, }); // Check that transferring FileHandle instances works. assert.notStrictEqual(fh.fd, -1); port1.postMessage(fh, [ fh ]); assert.strictEqual(fh.fd, -1); const [ fh2 ] = await once(port2, 'message'); assert.strictEqual(Object.getPrototypeOf(fh2), Object.getPrototypeOf(fh)); assert.deepStrictEqual(await fh2.readFile(), await fs.readFile(__filename)); await fh2.close(); await assert.rejects(() => fh.readFile(), { code: 'EBADF' }); })().then(common.mustCall()); (async function() { // Check that there is no crash if the message is never read. const fh = await fs.open(__filename); const { port1 } = new MessageChannel(); assert.notStrictEqual(fh.fd, -1); port1.postMessage(fh, [ fh ]); assert.strictEqual(fh.fd, -1); })().then(common.mustCall()); (async function() { // Check that in the case of a context mismatch the message is discarded. const fh = await fs.open(__filename); const { port1, port2 } = new MessageChannel(); const ctx = vm.createContext(); const port2moved = moveMessagePortToContext(port2, ctx); port2moved.onmessage = common.mustCall((msgEvent) => { assert.strictEqual(msgEvent.data, 'second message'); port1.close(); }); // TODO(addaleax): Switch this to a 'messageerror' event once MessagePort // implements EventTarget fully and in a cross-context manner. port2moved.onmessageerror = common.mustCall((event) => { assert.strictEqual(event.data.code, 'ERR_MESSAGE_TARGET_CONTEXT_UNAVAILABLE'); }); port2moved.start(); assert.notStrictEqual(fh.fd, -1); port1.postMessage(fh, [ fh ]); assert.strictEqual(fh.fd, -1); port1.postMessage('second message'); })().then(common.mustCall()); (async function() { // Check that a FileHandle with a read in progress cannot be transferred. const fh = await fs.open(__filename); const { port1 } = new MessageChannel(); const readPromise = fh.readFile(); assert.throws(() => { port1.postMessage(fh, [fh]); }, { message: 'Cannot transfer FileHandle while in use', name: 'DataCloneError' }); assert.deepStrictEqual(await readPromise, await fs.readFile(__filename)); // await fh.close(); })().then(common.mustCall()); (async function() { // Check that filehandles with a close in progress cannot be transferred. const fh = await fs.open(__filename); const { port1 } = new MessageChannel(); const closePromise = fh.close(); assert.throws(() => { port1.postMessage(fh, [fh]); }, { message: 'Cannot transfer FileHandle while in use', name: 'DataCloneError' }); await closePromise; })().then(common.mustCall()); }, 10)
Open Graph Description: Fixes: #59145 Wrap all script into setInterval and you will see the error 'use strict'; const common = require('../common'); const assert = require('assert'); const fs = req...
X Description: Fixes: #59145 Wrap all script into setInterval and you will see the error 'use strict'; const common = require('../common'); const assert = require('assert&a...
Opengraph URL: https://github.com/nodejs/node/pull/59158
X: @github
Domain: redirect.github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:38742d4b-1a11-b216-51ec-affecc29aba9 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | B258:2EFA45:7BF2E8:B0967B:6A4BD36D |
| html-safe-nonce | 10cc8440320d02aa0a9483770b0d2b1b52ee404f0adbf70d202cf4f5399722de |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMjU4OjJFRkE0NTo3QkYyRTg6QjA5NjdCOjZBNEJEMzZEIiwidmlzaXRvcl9pZCI6IjQwNTEyNTA0MDUwNjkwMTc5NjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | dd32afcea27c1d9ffb7032f46fbe34db78beb9b88ba56b804724f3a2ddbbff7a |
| hovercard-subject-tag | pull_request:2684595999 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/nodejs/node/pull/59158/files |
| twitter:image | https://avatars.githubusercontent.com/u/14026360?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/14026360?s=400&v=4 |
| og:image:alt | Fixes: #59145 Wrap all script into setInterval and you will see the error 'use strict'; const common = require('../common'); const assert = require('assert'); const fs = req... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9df996be9551ac02247d09a2f7f64ece66c35ca28885d346e98fdfda9cdaa37b |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b71208a1c9ec7ccf364087569d0551f665dda674 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width