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

test_runner: use v8.serialize instead of TAP #47867

Merged
merged 6 commits into from
May 15, 2023

Conversation

MoLow
Copy link
Member

@MoLow MoLow commented May 4, 2023

Refs: #47663 (comment)
Fixes: #44656
Fixes: #47955
Fixes: #47481

not sure if this change is something we desire to document.

@MoLow MoLow requested a review from cjihrig May 4, 2023 21:14
@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/test_runner

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels May 4, 2023
Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

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

Left some comments. The only thing I'm really concerned about is some of the changes in test/fixtures/test-runner/output/spec_reporter_cli.snapshot. You should also share the performance gains you shared with me on Slack 😄

lib/internal/test_runner/utils.js Outdated Show resolved Hide resolved
lib/internal/test_runner/utils.js Show resolved Hide resolved
lib/internal/error_serdes.js Outdated Show resolved Hide resolved
lib/internal/error_serdes.js Outdated Show resolved Hide resolved
lib/internal/test_runner/reporter/v8.js Outdated Show resolved Hide resolved
lib/internal/test_runner/runner.js Outdated Show resolved Hide resolved
Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

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

Requesting changes just so that this doesn't land yet now that there is an approval.

lib/internal/error_serdes.js Outdated Show resolved Hide resolved
lib/internal/error_serdes.js Outdated Show resolved Hide resolved
lib/internal/test_runner/reporter/v8.js Outdated Show resolved Hide resolved
lib/internal/test_runner/runner.js Show resolved Hide resolved
lib/internal/test_runner/runner.js Outdated Show resolved Hide resolved
@MoLow
Copy link
Member Author

MoLow commented May 5, 2023

The only thing I'm really concerned about is some of the changes in test/fixtures/test-runner/output/spec_reporter_cli.snapshot.

Well - this is kind of a good thing since most of the changes reduce the delta between running with and without --test, you can compare most changes with test/fixtures/test-runner/output/spec_reporter.snapshot.:
other changes are some edge cases that seem a little harder to handle.

(remember spec reporter includes each failing test twice when looking at this diff :))

diff --git a/test/fixtures/test-runner/output/spec_reporter_cli.js b/test/fixtures/test-runner/output/spec_reporter_cli.js
index e88a7221fb..6a7c2d655f 100644
--- a/test/fixtures/test-runner/output/spec_reporter_cli.js
+++ b/test/fixtures/test-runner/output/spec_reporter_cli.js
@@ -5,7 +5,7 @@ const fixtures = require('../../../common/fixtures');
 const spawn = require('node:child_process').spawn;
 
 const child = spawn(process.execPath,
-                    ['--no-warnings', '--test', '--test-reporter', 'spec', fixtures.path('test-runner/output/output.js')],
+                    ['--no-warnings', '--test-reporter', 'spec', fixtures.path('test-runner/output/output.js')],
                     { stdio: 'pipe' });
 // eslint-disable-next-line no-control-regex
 child.stdout.on('data', (d) => process.stdout.write(d.toString().replace(/[^\x00-\x7F]/g, '').replace(/\u001b\[\d+m/g, '')));
diff --git a/test/fixtures/test-runner/output/spec_reporter_cli.snapshot b/test/fixtures/test-runner/output/spec_reporter_cli.snapshot
index a8a628e1e1..7682041770 100644
--- a/test/fixtures/test-runner/output/spec_reporter_cli.snapshot
+++ b/test/fixtures/test-runner/output/spec_reporter_cli.snapshot
@@ -109,7 +109,7 @@
  subtest sync throw fail (*ms)
 
  sync throw non-error fail (*ms)
-  'Symbol(thrown symbol from sync throw non-error fail)'
+  Symbol(thrown symbol from sync throw non-error fail)
 
  level 0a
    level 1a (*ms)
@@ -185,8 +185,8 @@
   Error [ERR_TEST_FAILURE]: callback invoked multiple times
       * {
     failureType: 'multipleCallbackInvocations',
-    code: 'ERR_TEST_FAILURE',
-    [cause]: 'callback invoked multiple times'
+    cause: 'callback invoked multiple times',
+    code: 'ERR_TEST_FAILURE'
   }
 
  callback async throw (*ms)
@@ -206,10 +206,10 @@
 
  'only' and 'runOnly' require the --test-only command-line option.
  custom inspect symbol fail (*ms)
-  { foo: 1 }
+  customized
 
  custom inspect symbol that throws fail (*ms)
-  { foo: 1 }
+  { foo: 1, [Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]] }
 
  subtest sync throw fails
    sync throw fails at first (*ms)
@@ -281,8 +281,8 @@
       * {
     generatedMessage: true,
     code: 'ERR_ASSERTION',
-    actual: { foo: 1, bar: 1 },
-    expected: <ref *1> { bar: 2, c: [Circular *1] },
+    actual: [Object],
+    expected: [Object],
     operator: 'deepEqual'
   }
 
@@ -400,7 +400,7 @@
       *
 
  sync throw non-error fail (*ms)
-  'Symbol(thrown symbol from sync throw non-error fail)'
+  Symbol(thrown symbol from sync throw non-error fail)
 
  +long running (*ms)
   'test did not finish before its parent and was cancelled'
@@ -440,8 +440,8 @@
   Error [ERR_TEST_FAILURE]: callback invoked multiple times
       * {
     failureType: 'multipleCallbackInvocations',
-    code: 'ERR_TEST_FAILURE',
-    [cause]: 'callback invoked multiple times'
+    cause: 'callback invoked multiple times',
+    code: 'ERR_TEST_FAILURE'
   }
 
  callback async throw (*ms)
@@ -450,10 +450,10 @@
       *
 
  custom inspect symbol fail (*ms)
-  { foo: 1 }
+  customized
 
  custom inspect symbol that throws fail (*ms)
-  { foo: 1 }
+  { foo: 1, [Symbol(nodejs.util.inspect.custom)]: [Function: [nodejs.util.inspect.custom]] }
 
  sync throw fails at first (*ms)
   Error: thrown from subtest sync throw fails at first
@@ -519,8 +519,8 @@
       * {
     generatedMessage: true,
     code: 'ERR_ASSERTION',
-    actual: { foo: 1, bar: 1 },
-    expected: <ref *1> { bar: 2, c: [Circular *1] },
+    actual: [Object],
+    expected: [Object],
     operator: 'deepEqual'
   }
 

You should also share the performance gains you shared with me on Slack 😄

Sure! I tried later on and it seemed like there is not always such a good performance gain - it really depends on the suite you run.
for example, running NODE_REGENERATE_SNAPSHOTS=1 ./node test/parallel/test-runner-output.mjs with and without this change perform pretty much the same.
however, I did a comparison on some tests suite I run at work and the results were:

v18.16.0:    ℹ duration_ms 22166.480125
v20.1.0:     ℹ duration_ms 6148.818709
v21.0.0-pre: ℹ duration_ms 5225.974167

@MoLow MoLow force-pushed the test-runner-v8-reporter branch 2 times, most recently from d9c12f8 to cb71d5c Compare May 5, 2023 11:10
@MoLow
Copy link
Member Author

MoLow commented May 5, 2023

now there almost no delta between with and without --test, besides some very specific edge cases

@cjihrig
Copy link
Contributor

cjihrig commented May 5, 2023

Well - this is kind of a good thing since most of the changes reduce the delta between running with and without --test

Thanks for clarifying. That's good news.

@MoLow MoLow force-pushed the test-runner-v8-reporter branch from cb71d5c to 4f92f53 Compare May 7, 2023 14:06
@MoLow MoLow requested a review from cjihrig May 8, 2023 11:36
@MoLow MoLow force-pushed the test-runner-v8-reporter branch 2 times, most recently from b0698ed to 7990e81 Compare May 8, 2023 13:22
Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

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

The changes in lib/internal/error_serdes.js should be in a separate commit, and arguably a separate PR, and with approval from @nodejs/workers

lib/internal/test_runner/utils.js Show resolved Hide resolved
lib/internal/test_runner/reporter/v8.js Outdated Show resolved Hide resolved
Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

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

The changes in lib/internal/error_serdes.js should be in a separate commit, and arguably a separate PR, and with approval from @nodejs/workers

lib/internal/error_serdes.js Outdated Show resolved Hide resolved
lib/internal/test_runner/reporter/v8.js Outdated Show resolved Hide resolved

// Index 0 should always be present because we just pushed data into it.
let messageBufferHead = this.#messageBuffer[0];
let headerIndex = messageBufferHead.indexOf(v8Header);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
let headerIndex = messageBufferHead.indexOf(v8Header);
let headerIndex = ArrayPrototypeIndexOf(messageBufferHead, v8Header);

Copy link
Member Author

Choose a reason for hiding this comment

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

messageBufferHead is a Buffer

Copy link
Member

Choose a reason for hiding this comment

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

If it's a Buffer, you should be able to use Uint8ArrayPrototypeIndexOf

Copy link
Member Author

@MoLow MoLow May 14, 2023

Choose a reason for hiding this comment

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

I have tried but:

./node --expose-internals -p "require('internal/test/binding').primordials.Uint8ArrayPrototypeIndexOf()" 

results in require(...).primordials.Uint8ArrayPrototypeIndexOf is not a function
and

./node --expose-internals -p "require('internal/test/binding').primordials.TypedArrayPrototypeIndexOf(Buffer.from('Hello'), Buffer.from('ll'))"

results in -1

This comment was marked as outdated.

lib/internal/test_runner/runner.js Outdated Show resolved Hide resolved
lib/internal/test_runner/runner.js Outdated Show resolved Hide resolved
lib/internal/test_runner/runner.js Outdated Show resolved Hide resolved
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@MoLow MoLow added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 15, 2023
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot
Copy link
Collaborator

process.stdout.write(Buffer.from("arbitrary - mid"));
process.stdout.write(Buffer.concat([chunk, Buffer.from("arbitrary - post")]));
}
})();
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have a .then(common.mustCall()) here?

Copy link
Member Author

Choose a reason for hiding this comment

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

no need, we snapshot the output

// Flags: --test --expose-internals
'use strict';

const v8_reporter = require('internal/test_runner/reporter/v8-serializer');
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const v8_reporter = require('internal/test_runner/reporter/v8-serializer');
const v8Reporter = require('internal/test_runner/reporter/v8-serializer');

Copy link
Member Author

Choose a reason for hiding this comment

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

if this is the only comment, Il skip it :)

@MoLow MoLow added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels May 15, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label May 15, 2023
@nodejs-github-bot nodejs-github-bot merged commit 7116bc0 into nodejs:main May 15, 2023
@nodejs-github-bot
Copy link
Collaborator

Landed in 7116bc0

targos pushed a commit that referenced this pull request May 15, 2023
PR-URL: #47867
Fixes: #44656
Fixes: #47955
Fixes: #47481
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
@MoLow MoLow deleted the test-runner-v8-reporter branch May 23, 2023 05:57
@MoLow
Copy link
Member Author

MoLow commented May 23, 2023

note: if backported, please backport along with #48106

danielleadams pushed a commit that referenced this pull request Jul 6, 2023
PR-URL: #47867
Fixes: #44656
Fixes: #47955
Fixes: #47481
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
MoLow added a commit to MoLow/node that referenced this pull request Jul 6, 2023
PR-URL: nodejs#47867
Fixes: nodejs#44656
Fixes: nodejs#47955
Fixes: nodejs#47481
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. test_runner Issues and PRs related to the test runner subsystem.
Projects
None yet
9 participants