Skip to content

Commit

Permalink
test: adapt test-v8-serdes for V8 9.9
Browse files Browse the repository at this point in the history
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
  • Loading branch information
targos committed Apr 9, 2022
1 parent 52ae4ab commit 0c02e0e
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions test/parallel/test-v8-serdes.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,41 @@ const hostObject = new (internalBinding('js_stream').JSStream)();
}

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

const des = new v8.DefaultDeserializer(buf);
des.readHeader();
assert.strictEqual(des.getWireFormatVersion(), 0x0d);

const value = des.readValue();
assert.strictEqual(value, value.foo);
}

{
const message = `New serialization format.
This test is expected to fail when V8 changes its serialization format.
When that happens, the "desStr" variable must be updated to the new value
and the change should be mentioned in the release notes, as it is semver-major.
Consider opening an issue as a heads up at https://github.com/nodejs/node/issues/new
`;

const desStr = 'ff0f6f2203666f6f5e007b01';

const desBuf = Buffer.from(desStr, 'hex');
const des = new v8.DefaultDeserializer(desBuf);
des.readHeader();
const value = des.readValue();

const ser = new v8.DefaultSerializer();
ser.writeHeader();
ser.writeValue(value);

ser.writeValue(des.readValue());

assert.deepStrictEqual(buf, ser.releaseBuffer());
assert.strictEqual(des.getWireFormatVersion(), 0x0d);
const serBuf = ser.releaseBuffer();
const serStr = serBuf.toString('hex');
assert.deepStrictEqual(serStr, desStr, message);
}

{
Expand Down

0 comments on commit 0c02e0e

Please sign in to comment.