Skip to content

Commit 0854fce

Browse files
committed
test: adapt test-v8-serdes for V8 9.9
V8 changed the serialization format so we cannot expect that a value serialized by an old version can be reserialized to the same bytes. Change the test to expect that deserialization of the old value still works. Add another test which is expected to fail when the format changes so that we are aware when it happens and can call it out in the release notes. Closes: #41519 PR-URL: #42657 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
1 parent 40bc080 commit 0854fce

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

test/parallel/test-v8-serdes.js

+27-4
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,41 @@ const hostObject = new (internalBinding('js_stream').JSStream)();
155155
}
156156

157157
{
158+
// Test that an old serialized value can still be deserialized.
158159
const buf = Buffer.from('ff0d6f2203666f6f5e007b01', 'hex');
159160

160161
const des = new v8.DefaultDeserializer(buf);
161162
des.readHeader();
163+
assert.strictEqual(des.getWireFormatVersion(), 0x0d);
164+
165+
const value = des.readValue();
166+
assert.strictEqual(value, value.foo);
167+
}
168+
169+
{
170+
const message = `New serialization format.
171+
172+
This test is expected to fail when V8 changes its serialization format.
173+
When that happens, the "desStr" variable must be updated to the new value
174+
and the change should be mentioned in the release notes, as it is semver-major.
175+
176+
Consider opening an issue as a heads up at https://github.com/nodejs/node/issues/new
177+
`;
178+
179+
const desStr = 'ff0f6f2203666f6f5e007b01';
180+
181+
const desBuf = Buffer.from(desStr, 'hex');
182+
const des = new v8.DefaultDeserializer(desBuf);
183+
des.readHeader();
184+
const value = des.readValue();
162185

163186
const ser = new v8.DefaultSerializer();
164187
ser.writeHeader();
188+
ser.writeValue(value);
165189

166-
ser.writeValue(des.readValue());
167-
168-
assert.deepStrictEqual(buf, ser.releaseBuffer());
169-
assert.strictEqual(des.getWireFormatVersion(), 0x0d);
190+
const serBuf = ser.releaseBuffer();
191+
const serStr = serBuf.toString('hex');
192+
assert.deepStrictEqual(serStr, desStr, message);
170193
}
171194

172195
{

0 commit comments

Comments
 (0)