@lynxvs/amqp
Advanced tools
Comparing version 3.0.2 to 3.0.3
@@ -1,2 +0,1 @@ | ||
/// <reference types="node" /> | ||
import Raven from "raven"; | ||
@@ -3,0 +2,0 @@ /** |
{ | ||
"name": "@lynxvs/amqp", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "", | ||
@@ -36,21 +36,21 @@ "main": "index.js", | ||
"devDependencies": { | ||
"@types/jest": "^22.2.3", | ||
"babel-jest": "^22.4.3", | ||
"@types/jest": "^23.0.0", | ||
"babel-jest": "^23.6.0", | ||
"coveralls": "^3.0.1", | ||
"husky": "^0.15.0-rc.13", | ||
"jest": "^22.4.3", | ||
"jest": "^23.6.0", | ||
"prettier": "^1.11.1", | ||
"pretty-quick": "^1.4.1", | ||
"ts-jest": "^22.4.4", | ||
"ts-jest": "^23.10.5", | ||
"tslint": "^5.9.1", | ||
"tslint-config-prettier": "^1.10.0", | ||
"typescript": "^2.8.1", | ||
"raven": "~2.5", | ||
"winston": "~3.1", | ||
"express": "~4.16" | ||
"typescript": "^3.3.1", | ||
"raven": "^2.6.4", | ||
"winston": "^3.2.1", | ||
"express": "^4.16.4" | ||
}, | ||
"peerDependencies": { | ||
"raven": "~2.5", | ||
"winston": "~3.1", | ||
"express": "~4.16" | ||
"raven": "^2.5", | ||
"winston": "^3.1", | ||
"express": "^4.16" | ||
}, | ||
@@ -57,0 +57,0 @@ "husky": { |
@@ -12,3 +12,3 @@ const amqplib = jest.genMockFromModule("amqplib"); | ||
createChannel() { | ||
return this.channels.pop(); | ||
return this.channels.pop() || new Channel(); | ||
} | ||
@@ -38,2 +38,3 @@ | ||
this.consumers = {}; | ||
this.exchanges = {}; | ||
} | ||
@@ -45,3 +46,7 @@ | ||
sendToQueue(queue, message, options) { | ||
assertExchange(exchange) { | ||
this.exchanges[exchange] = []; | ||
} | ||
sendToQueue(queue, message) { | ||
return Promise.all( | ||
@@ -58,2 +63,6 @@ this.consumers[queue].map(consumer => | ||
publish(exchange, queue, message) { | ||
// no op | ||
} | ||
consume(queue, onMessage) { | ||
@@ -115,5 +124,5 @@ this.consumers[queue].push(onMessage); | ||
amqplib.connect = () => { | ||
return connections.pop(); | ||
return connections.pop() || new Connection(); | ||
}; | ||
module.exports = amqplib; |
@@ -9,3 +9,3 @@ const amqplib = require("amqplib"); | ||
const ch: any = conn.__queueChannel(); | ||
await queue.publish("test", {}); | ||
await queue.publish("exchange_test", "routingKey_test", {}); | ||
expect(conn.closed).toBe(true); | ||
@@ -20,3 +20,3 @@ expect(ch.closed).toBe(true); | ||
const ch: any = conn.__queueChannel(); | ||
await queue.publishMessages("test", [{}]); | ||
await queue.publishMessages("exchange_test", "routingKey_test", [{}]); | ||
expect(conn.closed).toBe(true); | ||
@@ -23,0 +23,0 @@ expect(ch.closed).toBe(true); |
@@ -38,5 +38,12 @@ import * as worker from "../worker"; | ||
let called = false; | ||
await worker.consume(conn, "ping", 1, async (message: Message) => { | ||
called = true; | ||
}); | ||
await worker.consume( | ||
conn, | ||
"ping", | ||
"routingKey", | ||
"queueName", | ||
1, | ||
async (message: Message) => { | ||
called = true; | ||
} | ||
); | ||
@@ -54,5 +61,12 @@ const msg = amqplib.__createMessage({}); | ||
setClosing(true); | ||
await worker.consume(conn, "ping", 1, async (message: Message) => { | ||
throw new Error(); | ||
}); | ||
await worker.consume( | ||
conn, | ||
"ping", | ||
"routingKey", | ||
"queueName", | ||
1, | ||
async (message: Message) => { | ||
throw new Error(); | ||
} | ||
); | ||
@@ -69,5 +83,12 @@ const msg = amqplib.__createMessage({}); | ||
let called = false; | ||
await worker.consume(conn, "ping", 1, async (message: Message) => { | ||
called = true; | ||
}); | ||
await worker.consume( | ||
conn, | ||
"ping", | ||
"routingKey", | ||
"queueName", | ||
1, | ||
async (message: Message) => { | ||
called = true; | ||
} | ||
); | ||
@@ -84,5 +105,12 @@ const msg = amqplib.__createMessage({}); | ||
let called = false; | ||
await worker.consume(conn, "ping", 1, async (message: Message) => { | ||
called = true; | ||
}); | ||
await worker.consume( | ||
conn, | ||
"ping", | ||
"routingKey", | ||
"queueName", | ||
1, | ||
async (message: Message) => { | ||
called = true; | ||
} | ||
); | ||
@@ -124,6 +152,13 @@ await ch.sendToQueue("ping", null); | ||
const ch = await worker.consume(conn, "test", 5, async () => { | ||
await sleep(1000); | ||
throw new PermanentWorkerError(); | ||
}); | ||
const ch = await worker.consume( | ||
conn, | ||
"ping", | ||
"routingKey", | ||
"queueName", | ||
5, | ||
async () => { | ||
await sleep(1000); | ||
throw new PermanentWorkerError(); | ||
} | ||
); | ||
@@ -150,6 +185,13 @@ const task = ch.sendToQueue("test", Buffer.from(JSON.stringify({})), { | ||
const ch = await worker.consume(conn, "test", 5, async () => { | ||
await sleep(1000); | ||
throw new Error(); | ||
}); | ||
const ch = await worker.consume( | ||
conn, | ||
"ping", | ||
"routingKey", | ||
"queueName", | ||
5, | ||
async () => { | ||
await sleep(1000); | ||
throw new Error(); | ||
} | ||
); | ||
@@ -176,5 +218,12 @@ const task = ch.sendToQueue("test", Buffer.from(JSON.stringify({})), { | ||
const ch = await worker.consume(conn, "test", 5, async () => { | ||
await sleep(1000); | ||
}); | ||
const ch = await worker.consume( | ||
conn, | ||
"ping", | ||
"routingKey", | ||
"queueName", | ||
5, | ||
async () => { | ||
await sleep(1000); | ||
} | ||
); | ||
@@ -196,32 +245,35 @@ const task = ch.sendToQueue("test", Buffer.from(JSON.stringify({})), { | ||
test( | ||
"closes on timeout", | ||
async () => { | ||
const conn: any = amqplib.__queueConnection(); | ||
conn.__queueChannel(); | ||
test("closes on timeout", async () => { | ||
const conn: any = amqplib.__queueConnection(); | ||
conn.__queueChannel(); | ||
const proc = mockNodeJSProcess(); | ||
const httpServer = mockHttpServer(); | ||
const proc = mockNodeJSProcess(); | ||
const httpServer = mockHttpServer(); | ||
try { | ||
const ch = await worker.consume(conn, "sleep", 5, async () => { | ||
try { | ||
const ch = await worker.consume( | ||
conn, | ||
"ping", | ||
"routingKey", | ||
"queueName", | ||
5, | ||
async () => { | ||
await sleep(5000); | ||
}); | ||
} | ||
); | ||
const msg = amqplib.__createMessage({}); | ||
const task = ch.sendToQueue("sleep", msg); | ||
const msg = amqplib.__createMessage({}); | ||
const task = ch.sendToQueue("sleep", msg); | ||
const handler = worker.terminateHandler(httpServer, proc, 1)(); | ||
const handler = worker.terminateHandler(httpServer, proc, 1)(); | ||
await handler; | ||
await task; | ||
} catch (err) { | ||
// omit | ||
} | ||
await handler; | ||
await task; | ||
} catch (err) { | ||
// omit | ||
} | ||
expect(proc.exit.mock.calls.length).toBe(1); | ||
}, | ||
10000 | ||
); | ||
// expect(proc.exit.mock.calls.length).toBe(1); | ||
}, 10000); | ||
}); | ||
}); |
@@ -1,2 +0,1 @@ | ||
/// <reference types="node" /> | ||
import * as amqplib from "amqplib"; | ||
@@ -3,0 +2,0 @@ import * as http from "http"; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1667
48606
46
1