Commit 08b09a2f622 for nodejs
commit 08b09a2f622739fdcf093edf752e69c6b180f7d6
Author: Filip Skokan <panva.ip@gmail.com>
Date: Wed Oct 21 09:33:12 2026 +0200
test: handle stringbytes allocation failures
Buffer.allocUnsafe() can throw ERR_MEMORY_ALLOCATION_FAILED under
memory pressure. Accept it alongside the V8 allocation-failure
message so the tests take their intended low-memory skip.
Signed-off-by: Filip Skokan <panva.ip@gmail.com>
Assisted-by: Codex
PR-URL: https://github.com/nodejs/node/pull/66887
Reviewed-By: Richard Lau <richard.lau@ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js
index fcf5279dd3c..87a754cb216 100644
--- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js
+++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js
@@ -17,7 +17,8 @@ try {
buf = Buffer.allocUnsafe(kStringMaxLength);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
- if (e.message !== 'Array buffer allocation failed') throw (e);
+ if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' &&
+ e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
}
diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js
index 6aff0445195..e03b5ae0352 100644
--- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js
+++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js
@@ -17,7 +17,8 @@ try {
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
- if (e.message !== 'Array buffer allocation failed') throw (e);
+ if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' &&
+ e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
}
diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js
index 7c8e2d92c6a..9ffff4fdbbe 100644
--- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js
+++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js
@@ -17,7 +17,8 @@ try {
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
- if (e.message !== 'Array buffer allocation failed') throw (e);
+ if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' &&
+ e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
}
diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js
index 176c095e22e..c962c491d0c 100644
--- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js
+++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js
@@ -18,7 +18,8 @@ try {
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
- if (e.message !== 'Array buffer allocation failed') throw (e);
+ if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' &&
+ e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
}
diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js
index a473e0e90fb..1cef739c5c3 100644
--- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js
+++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js
@@ -17,7 +17,8 @@ try {
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
- if (e.message !== 'Array buffer allocation failed') throw (e);
+ if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' &&
+ e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
}
diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js
index 25271fad94b..2e00ff49722 100644
--- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js
+++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js
@@ -17,7 +17,8 @@ try {
buf = Buffer.allocUnsafe(kStringMaxLength + 1);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
- if (e.message !== 'Array buffer allocation failed') throw (e);
+ if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' &&
+ e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
}
diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js
index 121ca2d62ba..6fbc52849c4 100644
--- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js
+++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js
@@ -17,7 +17,8 @@ try {
buf = Buffer.allocUnsafe(kStringMaxLength + 2);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
- if (e.message !== 'Array buffer allocation failed') throw (e);
+ if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' &&
+ e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
}
diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js
index b843be5a9ab..e13f865405c 100644
--- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js
+++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js
@@ -17,7 +17,8 @@ try {
buf = Buffer.allocUnsafe(kStringMaxLength * 2 + 2);
} catch (e) {
// If the exception is not due to memory confinement then rethrow it.
- if (e.message !== 'Array buffer allocation failed') throw (e);
+ if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' &&
+ e.message !== 'Array buffer allocation failed') throw (e);
common.skip(skipMessage);
}