-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pgmq): supports headers for pgmq v1.5.0
ref: tembo-io/pgmq#338
- Loading branch information
1 parent
8e347c7
commit adc36da
Showing
9 changed files
with
282 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/pgmq-js/test/lib/50.msg-manager/50.msg.send.headers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import assert from 'node:assert' | ||
|
||
import { fileShortPath } from '@waiting/shared-core' | ||
|
||
import { type QueueOptionsBase, type SendOptions, Pgmq, genRandomName } from '##/index.js' | ||
import { dbConfig } from '#@/config.unittest.js' | ||
|
||
|
||
const rndString = genRandomName(6) | ||
|
||
describe(fileShortPath(import.meta.url), () => { | ||
let mq: Pgmq | ||
const msg = { | ||
foo: 'bar', | ||
} | ||
const options: SendOptions = { | ||
queue: rndString, | ||
msg, | ||
headers: { barz: 'bar' }, | ||
} | ||
const createOpts: QueueOptionsBase = { queue: rndString } | ||
|
||
before(async () => { | ||
mq = new Pgmq('test', dbConfig) | ||
await mq.queue.createUnlogged(createOpts) | ||
}) | ||
after(async () => { | ||
await mq.queue.drop(createOpts) | ||
await mq.destroy() | ||
}) | ||
|
||
it(`msg.send(${rndString}), msg, headers`, async () => { | ||
const msgIds = await mq.msg.send(options) | ||
assert(msgIds.length === 1, 'send failed') | ||
assert(msgIds[0] === '1', 'send failed') | ||
}) | ||
}) | ||
|
42 changes: 42 additions & 0 deletions
42
packages/pgmq-js/test/lib/50.msg-manager/51.msg.sendBatch.headers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import assert from 'node:assert' | ||
|
||
import { fileShortPath } from '@waiting/shared-core' | ||
|
||
import { type QueueOptionsBase, type SendBatchOptions, Pgmq, genRandomName } from '##/index.js' | ||
import { dbConfig } from '#@/config.unittest.js' | ||
|
||
|
||
const rndString = genRandomName(6) | ||
|
||
describe(fileShortPath(import.meta.url), () => { | ||
let mq: Pgmq | ||
const headers1 = { key: 'k1' } | ||
const headers2 = { key: 'k2' } | ||
const msg = { | ||
foo: 'bar', | ||
} | ||
const opts: SendBatchOptions = { | ||
queue: rndString, | ||
msgs: [msg, msg], | ||
headers: [headers1, headers2], | ||
} | ||
const createOpts: QueueOptionsBase = { queue: rndString } | ||
|
||
before(async () => { | ||
mq = new Pgmq('test', dbConfig) | ||
await mq.queue.createUnlogged(createOpts) | ||
}) | ||
after(async () => { | ||
await mq.queue.drop(createOpts) | ||
await mq.destroy() | ||
}) | ||
|
||
it(`msg.sendBatch(${rndString}, msg[])`, async () => { | ||
const msgIds = await mq.msg.sendBatch(opts) | ||
assert(msgIds.length === 2, 'sendBatch failed') | ||
assert(msgIds[0] === '1', `sendBatch failed: ${msgIds[0]}`) | ||
assert(msgIds[1] === '2', `sendBatch failed: ${msgIds[1]}`) | ||
}) | ||
|
||
}) | ||
|
56 changes: 56 additions & 0 deletions
56
packages/pgmq-js/test/lib/50.msg-manager/66.msg.read.headers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import assert from 'node:assert' | ||
|
||
import { fileShortPath } from '@waiting/shared-core' | ||
|
||
import type { Message, QueueOptionsBase, ReadOptions, SendOptions } from '##/index.js' | ||
import { Pgmq, genRandomName } from '##/index.js' | ||
import { dbConfig } from '#@/config.unittest.js' | ||
|
||
|
||
const rndString = genRandomName(6) | ||
const msgToSend = { | ||
foo: 'bar', | ||
rnd: rndString, | ||
} | ||
|
||
describe(fileShortPath(import.meta.url), () => { | ||
let mq: Pgmq | ||
const opts: ReadOptions = { | ||
queue: rndString, | ||
} | ||
const createOpts: QueueOptionsBase = { queue: rndString } | ||
const headers = { key: rndString } | ||
|
||
before(async () => { | ||
const sendOpts: SendOptions = { | ||
queue: rndString, | ||
msg: msgToSend, | ||
headers, | ||
} | ||
mq = new Pgmq('test', dbConfig) | ||
await mq.queue.createUnlogged(createOpts) | ||
await mq.msg.send(sendOpts) | ||
}) | ||
after(async () => { | ||
await mq.queue.drop(createOpts) | ||
await mq.destroy() | ||
}) | ||
|
||
it(`msg.read(${rndString}) headers`, async () => { | ||
const msg: Message | null = await mq.msg.read(opts) | ||
assert(msg) | ||
assert(msg.msgId === '1') | ||
assert(msg.message, 'msg.message not exist') | ||
assert.deepStrictEqual(msg.message, msgToSend, 'msg.message not equal') | ||
assert.deepStrictEqual(msg.headers, headers, 'msg.headers not equal, msg.headers: ' + JSON.stringify(msg.headers)) | ||
|
||
assert(msg.enqueuedAt instanceof Date, 'msg.enqueuedAt not exist') | ||
assert(msg.enqueuedAt.getTime() > 0, 'msg.enqueuedAt invalid') | ||
|
||
assert(msg.readCt === 1, 'msg.readCt not equal 1') | ||
|
||
assert(msg.vt instanceof Date, 'msg.vt not exist') | ||
assert(msg.vt.getTime() > 0, 'msg.vt invalid') | ||
}) | ||
}) | ||
|
64 changes: 64 additions & 0 deletions
64
packages/pgmq-js/test/lib/50.msg-manager/67.msg.readBatch.headers-2.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import assert from 'node:assert' | ||
|
||
import { fileShortPath } from '@waiting/shared-core' | ||
|
||
import { type QueueOptionsBase, type ReadBatchOptions, type SendBatchOptions, Pgmq, genRandomName } from '##/index.js' | ||
import { dbConfig } from '#@/config.unittest.js' | ||
|
||
|
||
const rndString = genRandomName(6) | ||
const msgToSend = { | ||
foo: 'bar', | ||
rnd: rndString, | ||
} | ||
|
||
describe(fileShortPath(import.meta.url), () => { | ||
let mq: Pgmq | ||
const headers1 = { key: 'k1' } | ||
const options: ReadBatchOptions = { | ||
queue: rndString, | ||
vt: 0, | ||
qty: 3, | ||
} | ||
const createOpts: QueueOptionsBase = { queue: rndString } | ||
|
||
before(async () => { | ||
const sendOpts: SendBatchOptions = { | ||
queue: rndString, | ||
msgs: [msgToSend, msgToSend], | ||
headers: [headers1], | ||
} | ||
mq = new Pgmq('test', dbConfig) | ||
await mq.queue.createUnlogged(createOpts) | ||
await mq.msg.sendBatch(sendOpts) | ||
}) | ||
after(async () => { | ||
await mq.queue.drop(createOpts) | ||
await mq.destroy() | ||
}) | ||
|
||
it(`msg.readBatch(${rndString}) [headers, null]`, async () => { | ||
const msgs = await mq.msg.readBatch(options) | ||
assert(msgs.length === 2, 'msgs.length not equal 2') | ||
|
||
const [msg1, msg2] = msgs | ||
assert(msg1) | ||
assert(msg1.msgId === '1') | ||
assert.deepStrictEqual(msg1.message, msgToSend, 'msg.message not equal') | ||
assert.deepStrictEqual(msg1.headers, headers1, 'msg.headers not equal, msg.headers: ' + JSON.stringify(msg1.headers)) | ||
|
||
assert(msg1.enqueuedAt instanceof Date, 'msg.enqueuedAt not exist') | ||
assert(msg1.enqueuedAt.getTime() > 0, 'msg.enqueuedAt invalid') | ||
|
||
assert(msg1.readCt === 1, 'msg.readCt not equal 1') | ||
|
||
assert(msg1.vt instanceof Date, 'msg.vt not exist') | ||
assert(msg1.vt.getTime() > 0, 'msg.vt invalid') | ||
|
||
assert(msg2) | ||
assert(msg2.msgId === '2') | ||
assert.deepStrictEqual(msg2.message, msgToSend, 'msg.message not equal') | ||
assert(msg2.headers === null, 'msg.headers not equal, msg.headers: ' + JSON.stringify(msg2.headers)) | ||
}) | ||
}) | ||
|
65 changes: 65 additions & 0 deletions
65
packages/pgmq-js/test/lib/50.msg-manager/67.msg.readBatch.headers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import assert from 'node:assert' | ||
|
||
import { fileShortPath } from '@waiting/shared-core' | ||
|
||
import { type QueueOptionsBase, type ReadBatchOptions, type SendBatchOptions, Pgmq, genRandomName } from '##/index.js' | ||
import { dbConfig } from '#@/config.unittest.js' | ||
|
||
|
||
const rndString = genRandomName(6) | ||
const msgToSend = { | ||
foo: 'bar', | ||
rnd: rndString, | ||
} | ||
|
||
describe(fileShortPath(import.meta.url), () => { | ||
let mq: Pgmq | ||
const headers1 = { key: 'k1' } | ||
const headers2 = { key: 'k2' } | ||
const options: ReadBatchOptions = { | ||
queue: rndString, | ||
vt: 0, | ||
qty: 3, | ||
} | ||
const createOpts: QueueOptionsBase = { queue: rndString } | ||
|
||
before(async () => { | ||
const sendOpts: SendBatchOptions = { | ||
queue: rndString, | ||
msgs: [msgToSend, msgToSend], | ||
headers: [headers1, headers2], | ||
} | ||
mq = new Pgmq('test', dbConfig) | ||
await mq.queue.createUnlogged(createOpts) | ||
await mq.msg.sendBatch(sendOpts) | ||
}) | ||
after(async () => { | ||
await mq.queue.drop(createOpts) | ||
await mq.destroy() | ||
}) | ||
|
||
it(`msg.readBatch(${rndString}) headers`, async () => { | ||
const msgs = await mq.msg.readBatch(options) | ||
assert(msgs.length === 2, 'msgs.length not equal 2') | ||
|
||
const [msg1, msg2] = msgs | ||
assert(msg1) | ||
assert(msg1.msgId === '1') | ||
assert.deepStrictEqual(msg1.message, msgToSend, 'msg.message not equal') | ||
assert.deepStrictEqual(msg1.headers, headers1, 'msg.headers not equal, msg.headers: ' + JSON.stringify(msg1.headers)) | ||
|
||
assert(msg1.enqueuedAt instanceof Date, 'msg.enqueuedAt not exist') | ||
assert(msg1.enqueuedAt.getTime() > 0, 'msg.enqueuedAt invalid') | ||
|
||
assert(msg1.readCt === 1, 'msg.readCt not equal 1') | ||
|
||
assert(msg1.vt instanceof Date, 'msg.vt not exist') | ||
assert(msg1.vt.getTime() > 0, 'msg.vt invalid') | ||
|
||
assert(msg2) | ||
assert(msg2.msgId === '2') | ||
assert.deepStrictEqual(msg2.message, msgToSend, 'msg.message not equal') | ||
assert.deepStrictEqual(msg2.headers, headers2, 'msg.headers not equal, msg.headers: ' + JSON.stringify(msg2.headers)) | ||
}) | ||
}) | ||
|