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: limit stack size in test-error-serdes #52674

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions test/parallel/test-error-serdes-recursive-fast.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Flags: --expose-internals --stack-size=128
Copy link
Member

Choose a reason for hiding this comment

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

Are these just three tests testing the same thing but with different stack sizes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, these belong to af75425 just to see if there's any difference in CI results on different platforms.
That commit also extracted the stack exhausting parts (primary suspect of flakiness) from the rest of the test to confirm that cyclic errors are the cause of timeout.

'use strict';
require('../common');
const assert = require('assert');
const { serializeError, deserializeError } = require('internal/error_serdes');

function cycle(err) {
return deserializeError(serializeError(err));
}

class ErrorWithCyclicCause extends Error {
get cause() {
return new ErrorWithCyclicCause();
}
}
const errorWithCyclicCause = Object
.defineProperty(new Error('Error with cause'), 'cause', { get() { return errorWithCyclicCause; } });

assert.strictEqual(Object.hasOwn(cycle(errorWithCyclicCause), 'cause'), true);

// When the cause is cyclic, it is serialized until Maxiumum call stack size is reached
let depth = 0;
let e = cycle(new ErrorWithCyclicCause('Error with cause'));
while (e.cause) {
e = e.cause;
depth++;
}
assert(depth > 1);
console.log('Successfully completed stack exhaust test at', depth);
29 changes: 29 additions & 0 deletions test/parallel/test-error-serdes-recursive-slow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Flags: --expose-internals --stack-size=3072
'use strict';
require('../common');
const assert = require('assert');
const { serializeError, deserializeError } = require('internal/error_serdes');

function cycle(err) {
return deserializeError(serializeError(err));
}

class ErrorWithCyclicCause extends Error {
get cause() {
return new ErrorWithCyclicCause();
}
}
const errorWithCyclicCause = Object
.defineProperty(new Error('Error with cause'), 'cause', { get() { return errorWithCyclicCause; } });

assert.strictEqual(Object.hasOwn(cycle(errorWithCyclicCause), 'cause'), true);

// When the cause is cyclic, it is serialized until Maxiumum call stack size is reached
let depth = 0;
let e = cycle(new ErrorWithCyclicCause('Error with cause'));
while (e.cause) {
e = e.cause;
depth++;
}
assert(depth > 1);
console.log('Successfully completed stack exhaust test at', depth);
29 changes: 29 additions & 0 deletions test/parallel/test-error-serdes-recursive.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const { serializeError, deserializeError } = require('internal/error_serdes');

function cycle(err) {
return deserializeError(serializeError(err));
}

class ErrorWithCyclicCause extends Error {
get cause() {
return new ErrorWithCyclicCause();
}
}
const errorWithCyclicCause = Object
.defineProperty(new Error('Error with cause'), 'cause', { get() { return errorWithCyclicCause; } });

assert.strictEqual(Object.hasOwn(cycle(errorWithCyclicCause), 'cause'), true);

// When the cause is cyclic, it is serialized until Maxiumum call stack size is reached
let depth = 0;
let e = cycle(new ErrorWithCyclicCause('Error with cause'));
while (e.cause) {
e = e.cause;
depth++;
}
assert(depth > 1);
console.log('Successfully completed stack exhaust test at', depth);
17 changes: 0 additions & 17 deletions test/parallel/test-error-serdes.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,10 @@ class ErrorWithThowingCause extends Error {
throw new Error('err');
}
}
class ErrorWithCyclicCause extends Error {
get cause() {
return new ErrorWithCyclicCause();
}
}
const errorWithCause = Object
.defineProperty(new Error('Error with cause'), 'cause', { get() { return { foo: 'bar' }; } });
const errorWithThrowingCause = Object
.defineProperty(new Error('Error with cause'), 'cause', { get() { throw new Error('err'); } });
const errorWithCyclicCause = Object
.defineProperty(new Error('Error with cause'), 'cause', { get() { return errorWithCyclicCause; } });

assert.strictEqual(cycle(new Error('Error with cause', { cause: 0 })).cause, 0);
assert.strictEqual(cycle(new Error('Error with cause', { cause: -1 })).cause, -1);
Expand All @@ -79,19 +72,9 @@ assert.strictEqual(cycle(new Error('Error with cause', { cause: 'foo' })).cause,
assert.deepStrictEqual(cycle(new Error('Error with cause', { cause: new Error('err') })).cause, new Error('err'));
assert.deepStrictEqual(cycle(errorWithCause).cause, { foo: 'bar' });
assert.strictEqual(Object.hasOwn(cycle(errorWithThrowingCause), 'cause'), false);
assert.strictEqual(Object.hasOwn(cycle(errorWithCyclicCause), 'cause'), true);
assert.deepStrictEqual(cycle(new ErrorWithCause('Error with cause')).cause, new Error('err'));
assert.strictEqual(cycle(new ErrorWithThowingCause('Error with cause')).cause, undefined);
assert.strictEqual(Object.hasOwn(cycle(new ErrorWithThowingCause('Error with cause')), 'cause'), false);
// When the cause is cyclic, it is serialized until Maxiumum call stack size is reached
let depth = 0;
let e = cycle(new ErrorWithCyclicCause('Error with cause'));
while (e.cause) {
e = e.cause;
depth++;
}
assert(depth > 1);


{
const err = new ERR_INVALID_ARG_TYPE('object', 'Object', 42);
Expand Down