From 7e2ade6896e7b6cf5ca156fd6fad0bb8caf86d54 Mon Sep 17 00:00:00 2001 From: RedYetiDev <38299977+RedYetiDev@users.noreply.github.com> Date: Fri, 6 Sep 2024 20:52:00 -0400 Subject: [PATCH] test: remove unused common utilities --- test/common/README.md | 31 ------------- test/common/crypto.js | 18 -------- test/common/http2.js | 19 -------- test/common/tick.js | 1 - test/common/udppair.js | 101 ----------------------------------------- 5 files changed, 170 deletions(-) delete mode 100644 test/common/udppair.js diff --git a/test/common/README.md b/test/common/README.md index 72e34fd4302b15..a2f58961e87d5b 100644 --- a/test/common/README.md +++ b/test/common/README.md @@ -853,24 +853,6 @@ socket.write(frame.data); The serialized `Buffer` may be retrieved using the `frame.data` property. -### Class: DataFrame extends Frame - -The `http2.DataFrame` is a subclass of `http2.Frame` that serializes a `DATA` -frame. - - - -```js -// id is the 32-bit stream identifier -// payload is a Buffer containing the DATA payload -// padlen is an 8-bit integer giving the number of padding bytes to include -// final is a boolean indicating whether the End-of-stream flag should be set, -// defaults to false. -const frame = new http2.DataFrame(id, payload, padlen, final); - -socket.write(frame.data); -``` - ### Class: HeadersFrame The `http2.HeadersFrame` is a subclass of `http2.Frame` that serializes a @@ -1138,19 +1120,6 @@ are likely sufficient to hold a single file of `size` bytes. This is useful for skipping tests that require hundreds of megabytes or even gigabytes of temporary files, but it is inaccurate and susceptible to race conditions. -## UDP pair helper - -The `common/udppair` module exports a function `makeUDPPair` and a class -`FakeUDPWrap`. - -`FakeUDPWrap` emits `'send'` events when data is to be sent on it, and provides -an `emitReceived()` API for actin as if data has been received on it. - -`makeUDPPair` returns an object `{ clientSide, serverSide }` where each side -is an `FakeUDPWrap` connected to the other side. - -There is no difference between client or server side beyond their names. - ## WPT module ### `harness` diff --git a/test/common/crypto.js b/test/common/crypto.js index ba47285df49a43..10432d7e7a7e32 100644 --- a/test/common/crypto.js +++ b/test/common/crypto.js @@ -33,23 +33,6 @@ const modp2buf = Buffer.from([ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, ]); -function testDH({ publicKey: alicePublicKey, privateKey: alicePrivateKey }, - { publicKey: bobPublicKey, privateKey: bobPrivateKey }, - expectedValue) { - const buf1 = crypto.diffieHellman({ - privateKey: alicePrivateKey, - publicKey: bobPublicKey, - }); - const buf2 = crypto.diffieHellman({ - privateKey: bobPrivateKey, - publicKey: alicePublicKey, - }); - assert.deepStrictEqual(buf1, buf2); - - if (expectedValue !== undefined) - assert.deepStrictEqual(buf1, expectedValue); -} - // Asserts that the size of the given key (in chars or bytes) is within 10% of // the expected size. function assertApproximateSize(key, expectedSize) { @@ -117,7 +100,6 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); module.exports = { modp2buf, - testDH, assertApproximateSize, testEncryptDecrypt, testSignVerify, diff --git a/test/common/http2.js b/test/common/http2.js index 6df1c29c09eecd..1968b5bcfd39d0 100644 --- a/test/common/http2.js +++ b/test/common/http2.js @@ -81,24 +81,6 @@ class SettingsFrame extends Frame { } } -class DataFrame extends Frame { - constructor(id, payload, padlen = 0, final = false) { - let len = payload.length; - let flags = 0; - if (final) flags |= FLAG_EOS; - const buffers = [payload]; - if (padlen > 0) { - buffers.unshift(Buffer.from([padlen])); - buffers.push(PADDING.slice(0, padlen)); - len += padlen + 1; - flags |= FLAG_PADDED; - } - super(len, 0, flags, id); - buffers.unshift(this[kFrameData]); - this[kFrameData] = Buffer.concat(buffers); - } -} - class HeadersFrame extends Frame { constructor(id, payload, padlen = 0, final = false) { let len = payload.length; @@ -138,7 +120,6 @@ class AltSvcFrame extends Frame { module.exports = { Frame, AltSvcFrame, - DataFrame, HeadersFrame, SettingsFrame, PingFrame, diff --git a/test/common/tick.js b/test/common/tick.js index b02315b10ca96f..7bb86a81d52a6b 100644 --- a/test/common/tick.js +++ b/test/common/tick.js @@ -1,5 +1,4 @@ 'use strict'; -require('../common'); module.exports = function tick(x, cb) { function ontick() { diff --git a/test/common/udppair.js b/test/common/udppair.js deleted file mode 100644 index 3f2b0aed78a169..00000000000000 --- a/test/common/udppair.js +++ /dev/null @@ -1,101 +0,0 @@ -'use strict'; -const { internalBinding } = require('internal/test/binding'); -const { JSUDPWrap } = internalBinding('js_udp_wrap'); -const EventEmitter = require('events'); - -// FakeUDPWrap is a testing utility that emulates a UDP connection -// for the sake of making UDP tests more deterministic. -class FakeUDPWrap extends EventEmitter { - constructor() { - super(); - - this._handle = new JSUDPWrap(); - - this._handle.onreadstart = () => this._startReading(); - this._handle.onreadstop = () => this._stopReading(); - this._handle.onwrite = - (wrap, buffers, addr) => this._write(wrap, buffers, addr); - this._handle.getsockname = (obj) => { - Object.assign(obj, { address: '127.0.0.1', family: 'IPv4', port: 1337 }); - return 0; - }; - - this.reading = false; - this.bufferedReceived = []; - this.emitBufferedImmediate = null; - } - - _emitBuffered = () => { - if (!this.reading) return; - if (this.bufferedReceived.length > 0) { - this.emitReceived(this.bufferedReceived.shift()); - this.emitBufferedImmediate = setImmediate(this._emitBuffered); - } else { - this.emit('wantRead'); - } - }; - - _startReading() { - this.reading = true; - this.emitBufferedImmediate = setImmediate(this._emitBuffered); - } - - _stopReading() { - this.reading = false; - clearImmediate(this.emitBufferedImmediate); - } - - _write(wrap, buffers, addr) { - this.emit('send', { buffers, addr }); - setImmediate(() => this._handle.onSendDone(wrap, 0)); - } - - afterBind() { - this._handle.onAfterBind(); - } - - emitReceived(info) { - if (!this.reading) { - this.bufferedReceived.push(info); - return; - } - - const { - buffers, - addr: { - family = 4, - address = '127.0.0.1', - port = 1337, - }, - flags = 0, - } = info; - - let familyInt; - switch (family) { - case 'IPv4': familyInt = 4; break; - case 'IPv6': familyInt = 6; break; - default: throw new Error('bad family'); - } - - for (const buffer of buffers) { - this._handle.emitReceived(buffer, familyInt, address, port, flags); - } - } -} - -function makeUDPPair() { - const serverSide = new FakeUDPWrap(); - const clientSide = new FakeUDPWrap(); - - serverSide.on('send', - (chk) => setImmediate(() => clientSide.emitReceived(chk))); - clientSide.on('send', - (chk) => setImmediate(() => serverSide.emitReceived(chk))); - - return { serverSide, clientSide }; -} - -module.exports = { - FakeUDPWrap, - makeUDPPair, -};