Skip to content

Assorted test fixes and cleanup #3383

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

Merged
merged 5 commits into from
Feb 13, 2025
Merged
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
22 changes: 12 additions & 10 deletions packages/pg-protocol/src/inbound-parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ var expectedTwoParameterMessage = {
}

var testForMessage = function (buffer: Buffer, expectedMessage: any) {
it('recieves and parses ' + expectedMessage.name, async () => {
it('receives and parses ' + expectedMessage.name, async () => {
const messages = await parseBuffers([buffer])
const [lastMessage] = messages

Expand Down Expand Up @@ -487,12 +487,12 @@ describe('PgPacketStream', function () {
assert.equal(message.fields[4], '!')
})

var testMessageRecievedAfterSpiltAt = async function (split: number) {
var testMessageReceivedAfterSplitAt = async function (split: number) {
var firstBuffer = Buffer.alloc(fullBuffer.length - split)
var secondBuffer = Buffer.alloc(fullBuffer.length - firstBuffer.length)
fullBuffer.copy(firstBuffer, 0, 0)
fullBuffer.copy(secondBuffer, 0, firstBuffer.length)
const messages = await parseBuffers([fullBuffer])
const messages = await parseBuffers([firstBuffer, secondBuffer])
const message = messages[0] as any
assert.equal(message.fields.length, 5)
assert.equal(message.fields[0], null)
Expand All @@ -503,17 +503,19 @@ describe('PgPacketStream', function () {
}

it('parses when split in the middle', function () {
testMessageRecievedAfterSpiltAt(6)
return testMessageReceivedAfterSplitAt(6)
})

it('parses when split at end', function () {
testMessageRecievedAfterSpiltAt(2)
return testMessageReceivedAfterSplitAt(2)
})

it('parses when split at beginning', function () {
testMessageRecievedAfterSpiltAt(fullBuffer.length - 2)
testMessageRecievedAfterSpiltAt(fullBuffer.length - 1)
testMessageRecievedAfterSpiltAt(fullBuffer.length - 5)
return Promise.all([
testMessageReceivedAfterSplitAt(fullBuffer.length - 2),
testMessageReceivedAfterSplitAt(fullBuffer.length - 1),
testMessageReceivedAfterSplitAt(fullBuffer.length - 5),
])
})
})

Expand All @@ -540,7 +542,7 @@ describe('PgPacketStream', function () {
})
}
// sanity check
it('recieves both messages when packet is not split', async function () {
it('receives both messages when packet is not split', async function () {
const messages = await parseBuffers([fullBuffer])
verifyMessages(messages)
})
Expand All @@ -554,7 +556,7 @@ describe('PgPacketStream', function () {
verifyMessages(messages)
}

describe('recieves both messages when packet is split', function () {
describe('receives both messages when packet is split', function () {
it('in the middle', function () {
return splitAndVerifyTwoMessages(11)
})
Expand Down
12 changes: 2 additions & 10 deletions packages/pg-protocol/src/testing/buffer-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export default class BufferList {
return this.add(Buffer.from([val >>> 8, val >>> 0]), front)
}

public getByteLength(initial?: number) {
public getByteLength() {
return this.buffers.reduce(function (previous, current) {
return previous + current.length
}, initial || 0)
}, 0)
}

public addInt32(val: number, first?: boolean) {
Expand Down Expand Up @@ -64,12 +64,4 @@ export default class BufferList {
})
return result
}

public static concat(): Buffer {
var total = new BufferList()
for (var i = 0; i < arguments.length; i++) {
total.add(arguments[i])
}
return total.join()
}
}
12 changes: 2 additions & 10 deletions packages/pg/test/buffer-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ p.addInt16 = function (val, front) {
return this.add(Buffer.from([val >>> 8, val >>> 0]), front)
}

p.getByteLength = function (initial) {
p.getByteLength = function () {
return this.buffers.reduce(function (previous, current) {
return previous + current.length
}, initial || 0)
}, 0)
}

p.addInt32 = function (val, first) {
Expand Down Expand Up @@ -65,12 +65,4 @@ p.join = function (appendLength, char) {
return result
}

BufferList.concat = function () {
var total = new BufferList()
for (var i = 0; i < arguments.length; i++) {
total.add(arguments[i])
}
return total.join()
}

module.exports = BufferList