amqplib 2.1.0 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +54 -0
- package/callback_api.d.ts +19 -3
- package/index.d.ts +18 -2
- package/lib/callback_model.js +3 -22
- package/lib/channel.js +27 -1
- package/lib/channel_model.js +4 -29
- package/lib/properties.d.ts +3 -0
- package/lib/recovery.js +71 -10
- package/package.json +12 -2
- package/.claude/commands/lint-disable.md +0 -9
- package/.claude/commands/lint-enable.md +0 -12
- package/.claude/settings.local.json +0 -7
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -41
- package/.github/workflows/publish.yml +0 -59
- package/.github/workflows/test.yml +0 -54
- package/CLAUDE.md +0 -12
- package/Makefile +0 -42
- package/bin/amqp-rabbitmq-0.9.1.json +0 -483
- package/bin/generate-defs.js +0 -734
- package/biome.json +0 -51
- package/lefthook.yml +0 -17
- package/test/bitset.test.js +0 -65
- package/test/callback_api.test.js +0 -439
- package/test/channel.test.js +0 -918
- package/test/channel_api.test.js +0 -599
- package/test/codec.test.js +0 -171
- package/test/connect.test.js +0 -155
- package/test/connection.test.js +0 -772
- package/test/data.test.js +0 -33
- package/test/frame.test.js +0 -180
- package/test/lib/data.js +0 -249
- package/test/lib/util.js +0 -223
- package/test/mux.test.js +0 -258
- package/test/recovery.test.js +0 -402
- package/test/uri_spec.test.js +0 -210
package/biome.json
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"formatter": {
|
|
3
|
-
"enabled": true,
|
|
4
|
-
"formatWithErrors": false,
|
|
5
|
-
"indentStyle": "space",
|
|
6
|
-
"indentWidth": 2,
|
|
7
|
-
"lineWidth": 140,
|
|
8
|
-
"lineEnding": "lf",
|
|
9
|
-
"attributePosition": "auto",
|
|
10
|
-
"includes": ["**/*.js", "!test"]
|
|
11
|
-
},
|
|
12
|
-
"linter": {
|
|
13
|
-
"enabled": true,
|
|
14
|
-
"rules": {
|
|
15
|
-
"complexity": {
|
|
16
|
-
"noCommaOperator": "error",
|
|
17
|
-
"noUselessCatch": "error",
|
|
18
|
-
"useArrowFunction": "error",
|
|
19
|
-
"useOptionalChain": "off",
|
|
20
|
-
"noArguments": "error",
|
|
21
|
-
"useLiteralKeys": "off"
|
|
22
|
-
},
|
|
23
|
-
"suspicious": {
|
|
24
|
-
"noRedundantUseStrict": "error",
|
|
25
|
-
"noAsyncPromiseExecutor": "off",
|
|
26
|
-
"noGlobalIsNan": "error",
|
|
27
|
-
"noGlobalIsFinite": "error",
|
|
28
|
-
"noPrototypeBuiltins": "error",
|
|
29
|
-
"noVar": "error",
|
|
30
|
-
"noExportsInTest": "off",
|
|
31
|
-
"useIterableCallbackReturn": "off"
|
|
32
|
-
},
|
|
33
|
-
"style": {
|
|
34
|
-
"useSingleVarDeclarator": "error"
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
"includes": ["**/*.js", "!lib/defs.js"]
|
|
38
|
-
},
|
|
39
|
-
"javascript": {
|
|
40
|
-
"formatter": {
|
|
41
|
-
"arrowParentheses": "always",
|
|
42
|
-
"bracketSameLine": false,
|
|
43
|
-
"bracketSpacing": true,
|
|
44
|
-
"jsxQuoteStyle": "double",
|
|
45
|
-
"quoteProperties": "asNeeded",
|
|
46
|
-
"quoteStyle": "single",
|
|
47
|
-
"semicolons": "always",
|
|
48
|
-
"trailingCommas": "all"
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
package/lefthook.yml
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
pre-commit:
|
|
2
|
-
commands:
|
|
3
|
-
format:
|
|
4
|
-
glob: "**/*.js"
|
|
5
|
-
exclude:
|
|
6
|
-
- "test/*.js"
|
|
7
|
-
run: npx biome format {staged_files} --write
|
|
8
|
-
stage_fixed: true
|
|
9
|
-
lint:
|
|
10
|
-
glob: "**/*.js"
|
|
11
|
-
run: npx biome lint {staged_files} --write
|
|
12
|
-
stage_fixed: true
|
|
13
|
-
typecheck:
|
|
14
|
-
glob: "{**/*.d.ts,types/*.ts}"
|
|
15
|
-
run: npm run typecheck
|
|
16
|
-
test:
|
|
17
|
-
run: npm test
|
package/test/bitset.test.js
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
const { describe, it } = require('node:test');
|
|
2
|
-
const claire = require('claire');
|
|
3
|
-
const { BitSet } = require('../lib/bitset');
|
|
4
|
-
|
|
5
|
-
const { forAll, data: arb, label, choice, transform } = claire;
|
|
6
|
-
|
|
7
|
-
const PosInt = transform(Math.floor, arb.Positive);
|
|
8
|
-
const EmptyBitSet = label('bitset', transform((size) => new BitSet(size), choice(arb.Nothing, PosInt)));
|
|
9
|
-
|
|
10
|
-
describe('BitSet', () => {
|
|
11
|
-
it('get bit', forAll(EmptyBitSet, PosInt)
|
|
12
|
-
.satisfy((b, bit) => {
|
|
13
|
-
b.set(bit);
|
|
14
|
-
return b.get(bit);
|
|
15
|
-
})
|
|
16
|
-
.asTest());
|
|
17
|
-
|
|
18
|
-
it('clear bit', forAll(EmptyBitSet, PosInt)
|
|
19
|
-
.satisfy((b, bit) => {
|
|
20
|
-
b.set(bit);
|
|
21
|
-
b.clear(bit);
|
|
22
|
-
return !b.get(bit);
|
|
23
|
-
})
|
|
24
|
-
.asTest());
|
|
25
|
-
|
|
26
|
-
it('next set of empty', forAll(EmptyBitSet)
|
|
27
|
-
.satisfy((b) => {
|
|
28
|
-
return b.nextSetBit(0) === -1;
|
|
29
|
-
})
|
|
30
|
-
.asTest());
|
|
31
|
-
|
|
32
|
-
it('next set of one bit', forAll(EmptyBitSet, PosInt)
|
|
33
|
-
.satisfy((b, bit) => {
|
|
34
|
-
b.set(bit);
|
|
35
|
-
return b.nextSetBit(0) === bit;
|
|
36
|
-
})
|
|
37
|
-
.asTest());
|
|
38
|
-
|
|
39
|
-
it('next set same bit', forAll(EmptyBitSet, PosInt)
|
|
40
|
-
.satisfy((b, bit) => {
|
|
41
|
-
b.set(bit);
|
|
42
|
-
return b.nextSetBit(bit) === bit;
|
|
43
|
-
})
|
|
44
|
-
.asTest());
|
|
45
|
-
|
|
46
|
-
it('next set following bit', forAll(EmptyBitSet, PosInt)
|
|
47
|
-
.satisfy((b, bit) => {
|
|
48
|
-
b.set(bit);
|
|
49
|
-
return b.nextSetBit(bit + 1) === -1;
|
|
50
|
-
})
|
|
51
|
-
.asTest());
|
|
52
|
-
|
|
53
|
-
it('next clear of empty', forAll(EmptyBitSet, PosInt)
|
|
54
|
-
.satisfy((b, bit) => {
|
|
55
|
-
return b.nextClearBit(bit) === bit;
|
|
56
|
-
})
|
|
57
|
-
.asTest());
|
|
58
|
-
|
|
59
|
-
it('next clear of one set', forAll(EmptyBitSet, PosInt)
|
|
60
|
-
.satisfy((b, bit) => {
|
|
61
|
-
b.set(bit);
|
|
62
|
-
return b.nextClearBit(bit) === bit + 1;
|
|
63
|
-
})
|
|
64
|
-
.asTest());
|
|
65
|
-
});
|
|
@@ -1,439 +0,0 @@
|
|
|
1
|
-
const { describe, it, afterEach } = require('node:test');
|
|
2
|
-
const assert = require('node:assert');
|
|
3
|
-
const domain = require('node:domain');
|
|
4
|
-
const { connect } = require('../callback_api');
|
|
5
|
-
const { schedule, randomString, latch } = require('./lib/util');
|
|
6
|
-
|
|
7
|
-
function waitForMessages(ch, q, cb) {
|
|
8
|
-
ch.checkQueue(q, (e, ok) => {
|
|
9
|
-
if (e != null) return cb(e);
|
|
10
|
-
else if (ok.messageCount > 0) return cb(null, ok);
|
|
11
|
-
else schedule(waitForMessages.bind(null, ch, q, cb));
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
describe('Callback API', () => {
|
|
16
|
-
|
|
17
|
-
describe('connect', () => {
|
|
18
|
-
it('at all', (_t, done) => {
|
|
19
|
-
connect((err, c) => {
|
|
20
|
-
assert.ifError(err);
|
|
21
|
-
c.close(done);
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe('updateSecret', () => {
|
|
27
|
-
|
|
28
|
-
let c;
|
|
29
|
-
|
|
30
|
-
afterEach((_t, done) => {
|
|
31
|
-
if (c) c.close(() => done())
|
|
32
|
-
else done();
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('updateSecret', (_t, done) => {
|
|
36
|
-
connect((err, _c) => {
|
|
37
|
-
assert.ifError(err);
|
|
38
|
-
c = _c;
|
|
39
|
-
c.updateSecret(Buffer.from('new secret'), 'no reason', (err) => {
|
|
40
|
-
assert.ifError(err);
|
|
41
|
-
done();
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('emits update-secret-ok event', (_t, done) => {
|
|
47
|
-
connect((err, _c) => {
|
|
48
|
-
assert.ifError(err);
|
|
49
|
-
c = _c;
|
|
50
|
-
c.on('update-secret-ok', () => done());
|
|
51
|
-
c.updateSecret(Buffer.from('new secret'), 'no reason', (err) => {
|
|
52
|
-
assert.ifError(err);
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
const channel_test_fn = (method) => {
|
|
59
|
-
return (name, options, chfun) => {
|
|
60
|
-
if (typeof options === 'function') {
|
|
61
|
-
chfun = options;
|
|
62
|
-
options = {};
|
|
63
|
-
}
|
|
64
|
-
it(name, (_t, done) => {
|
|
65
|
-
connect((err, c) => {
|
|
66
|
-
assert.ifError(err);
|
|
67
|
-
c[method](options, ((err, ch) => {
|
|
68
|
-
assert.ifError(err);
|
|
69
|
-
chfun(ch, done);
|
|
70
|
-
}));
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
};
|
|
75
|
-
const channel_test = channel_test_fn('createChannel');
|
|
76
|
-
const confirm_channel_test = channel_test_fn('createConfirmChannel');
|
|
77
|
-
|
|
78
|
-
describe('channel open', () => {
|
|
79
|
-
channel_test('at all', (ch, done) => {
|
|
80
|
-
ch.connection.close(done);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
channel_test('open and close', (ch, done) => {
|
|
84
|
-
ch.close((err) => {
|
|
85
|
-
assert.ifError(err);
|
|
86
|
-
ch.connection.close(done);
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
describe('assert, check, delete', () => {
|
|
92
|
-
|
|
93
|
-
let ch;
|
|
94
|
-
|
|
95
|
-
afterEach((_t, done) => {
|
|
96
|
-
ch?.connection?.close(done);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
channel_test('assert, check, delete queue', (_ch, done) => {
|
|
100
|
-
ch = _ch;
|
|
101
|
-
ch.assertQueue('test.cb.queue', {}, (err, { queue }) => {
|
|
102
|
-
assert.ifError(err);
|
|
103
|
-
assert.strictEqual(queue, 'test.cb.queue');
|
|
104
|
-
ch.checkQueue('test.cb.queue', (err, ok) => {
|
|
105
|
-
assert.ifError(err);
|
|
106
|
-
assert.ok(ok);
|
|
107
|
-
ch.deleteQueue('test.cb.queue', {}, done);
|
|
108
|
-
})
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
channel_test('assert, check, delete exchange', (_ch, done) => {
|
|
113
|
-
ch = _ch;
|
|
114
|
-
ch.assertExchange('test.cb.exchange', 'topic', {}, (err, { exchange }) => {
|
|
115
|
-
assert.ifError(err);
|
|
116
|
-
assert.strictEqual(exchange, 'test.cb.exchange');
|
|
117
|
-
ch.checkExchange('test.cb.exchange', (err, _ok) => {
|
|
118
|
-
assert.ifError(err);
|
|
119
|
-
ch.deleteExchange('test.cb.exchange', {}, done);
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
channel_test('fail on check non-queue', (_ch, done) => {
|
|
125
|
-
ch = _ch;
|
|
126
|
-
const decrementLatch = latch(2, done);
|
|
127
|
-
ch.on('error', (err) => {
|
|
128
|
-
assert.match(err.message, /Channel closed by server/)
|
|
129
|
-
decrementLatch()
|
|
130
|
-
});
|
|
131
|
-
ch.checkQueue('test.cb.nothere', (err) => {
|
|
132
|
-
assert.match(err.message, /QueueDeclare; 404 \(NOT-FOUND\)/);
|
|
133
|
-
decrementLatch();
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
channel_test('fail on check non-exchange', (_ch, done) => {
|
|
138
|
-
ch = _ch;
|
|
139
|
-
const decrementLatch = latch(2, done);
|
|
140
|
-
ch.on('error', (err) => {
|
|
141
|
-
assert.match(err.message, /Channel closed by server/)
|
|
142
|
-
decrementLatch()
|
|
143
|
-
});
|
|
144
|
-
ch.checkExchange('test.cb.nothere', (err) => {
|
|
145
|
-
assert.match(err.message, /ExchangeDeclare; 404 \(NOT-FOUND\)/);
|
|
146
|
-
decrementLatch();
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('bindings', () => {
|
|
152
|
-
|
|
153
|
-
let ch;
|
|
154
|
-
|
|
155
|
-
afterEach((_t, done) => {
|
|
156
|
-
ch?.connection?.close(done);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
channel_test('bind queue', (_ch, done) => {
|
|
160
|
-
ch = _ch;
|
|
161
|
-
ch.assertQueue('test.cb.bindq', {}, (err, q) => {
|
|
162
|
-
assert.ifError(err);
|
|
163
|
-
ch.assertExchange('test.cb.bindex', 'fanout', {}, (err, ex) => {
|
|
164
|
-
assert.ifError(err);
|
|
165
|
-
ch.bindQueue(q.queue, ex.exchange, '', {}, done);
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
channel_test('bind exchange', (_ch, done) => {
|
|
171
|
-
ch = _ch;
|
|
172
|
-
ch.assertExchange('test.cb.bindex1', 'fanout', {}, (err, ex1) => {
|
|
173
|
-
assert.ifError(err);
|
|
174
|
-
ch.assertExchange('test.cb.bindex2', 'fanout', {}, (err, ex2) => {
|
|
175
|
-
assert.ifError(err);
|
|
176
|
-
ch.bindExchange(ex1.exchange, ex2.exchange, '', {}, done);
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
describe('sending messages', () => {
|
|
183
|
-
|
|
184
|
-
let ch;
|
|
185
|
-
|
|
186
|
-
afterEach((_t, done) => {
|
|
187
|
-
ch?.connection?.close(done);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
channel_test('send to queue and consume noAck', (_ch, done) => {
|
|
191
|
-
ch = _ch;
|
|
192
|
-
const msg = randomString();
|
|
193
|
-
ch.assertQueue('', { exclusive: true }, (err, { queue }) => {
|
|
194
|
-
assert.ifError(err);
|
|
195
|
-
ch.consume(queue, (m) => {
|
|
196
|
-
assert.strictEqual(m.content.toString(), msg);
|
|
197
|
-
done();
|
|
198
|
-
}, { noAck: true, exclusive: true });
|
|
199
|
-
ch.sendToQueue(queue, Buffer.from(msg));
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
channel_test('send to queue and consume ack', (_ch, done) => {
|
|
204
|
-
ch = _ch;
|
|
205
|
-
const msg = randomString();
|
|
206
|
-
ch.assertQueue('', { exclusive: true }, (err, { queue }) => {
|
|
207
|
-
assert.ifError(err);
|
|
208
|
-
ch.consume(queue, (m) => {
|
|
209
|
-
assert.strictEqual(m.content.toString(), msg);
|
|
210
|
-
ch.ack(m);
|
|
211
|
-
done();
|
|
212
|
-
}, { noAck: false, exclusive: true });
|
|
213
|
-
ch.sendToQueue(queue, Buffer.from(msg));
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
channel_test('send to and get from queue', (_ch, done) => {
|
|
218
|
-
ch = _ch;
|
|
219
|
-
ch.assertQueue('', { exclusive: true }, (err, { queue }) => {
|
|
220
|
-
assert.ifError(err);
|
|
221
|
-
const msg = randomString();
|
|
222
|
-
ch.sendToQueue(queue, Buffer.from(msg));
|
|
223
|
-
waitForMessages(ch, queue, (err, _) => {
|
|
224
|
-
assert.ifError(err);
|
|
225
|
-
ch.get(queue, { noAck: true }, (err, m) => {
|
|
226
|
-
assert.ifError(err);
|
|
227
|
-
assert.ok(m, 'Expected message, got empty/false');
|
|
228
|
-
assert.strictEqual(m.content.toString(), msg);
|
|
229
|
-
done();
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
const channelOptions = {};
|
|
236
|
-
|
|
237
|
-
channel_test('find high watermark', (_ch, done) => {
|
|
238
|
-
ch = _ch;
|
|
239
|
-
const msg = randomString();
|
|
240
|
-
let baseline = 0;
|
|
241
|
-
ch.assertQueue('', { exclusive: true }, (err, { queue }) => {
|
|
242
|
-
assert.ifError(err);
|
|
243
|
-
while (ch.sendToQueue(queue, Buffer.from(msg))) {
|
|
244
|
-
baseline++;
|
|
245
|
-
}
|
|
246
|
-
channelOptions.highWaterMark = baseline * 2;
|
|
247
|
-
done();
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
channel_test('set high watermark', channelOptions, (_ch, done) => {
|
|
252
|
-
ch = _ch;
|
|
253
|
-
const msg = randomString();
|
|
254
|
-
ch.assertQueue('', { exclusive: true }, (err, { queue }) => {
|
|
255
|
-
assert.ifError(err);
|
|
256
|
-
let ok;
|
|
257
|
-
for (let i = 0; i < channelOptions.highWaterMark; i++) {
|
|
258
|
-
ok = ch.sendToQueue(queue, Buffer.from(msg));
|
|
259
|
-
assert.equal(ok, true);
|
|
260
|
-
}
|
|
261
|
-
done();
|
|
262
|
-
});
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
describe('ConfirmChannel', () => {
|
|
267
|
-
|
|
268
|
-
let ch;
|
|
269
|
-
|
|
270
|
-
afterEach((_t, done) => {
|
|
271
|
-
ch?.connection?.close(done);
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
confirm_channel_test('Receive confirmation', (_ch, done) => {
|
|
275
|
-
ch = _ch;
|
|
276
|
-
// An unroutable message, on the basis that you're not allowed a
|
|
277
|
-
// queue with an empty name, and you can't make bindings to the
|
|
278
|
-
// default exchange. Tricky eh?
|
|
279
|
-
ch.publish('', '', Buffer.from('foo'), {}, done);
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
confirm_channel_test('Wait for confirms', (_ch, done) => {
|
|
283
|
-
ch = _ch;
|
|
284
|
-
for (let i = 0; i < 1000; i++) {
|
|
285
|
-
ch.publish('', '', Buffer.from('foo'), {});
|
|
286
|
-
}
|
|
287
|
-
ch.waitForConfirms(done);
|
|
288
|
-
});
|
|
289
|
-
|
|
290
|
-
const channelOptions = {};
|
|
291
|
-
|
|
292
|
-
confirm_channel_test('find high watermark', (_ch, done) => {
|
|
293
|
-
ch = _ch;
|
|
294
|
-
const msg = randomString();
|
|
295
|
-
let baseline = 0;
|
|
296
|
-
ch.assertQueue('', { exclusive: true }, (err, { queue }) => {
|
|
297
|
-
assert.ifError(err);
|
|
298
|
-
while (ch.sendToQueue(queue, Buffer.from(msg))) {
|
|
299
|
-
baseline++;
|
|
300
|
-
}
|
|
301
|
-
channelOptions.highWaterMark = baseline * 2;
|
|
302
|
-
done();
|
|
303
|
-
});
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
confirm_channel_test('set high watermark', channelOptions, (_ch, done) => {
|
|
307
|
-
ch = _ch;
|
|
308
|
-
const msg = randomString();
|
|
309
|
-
ch.assertQueue('', { exclusive: true }, (err, { queue }) => {
|
|
310
|
-
assert.ifError(err);
|
|
311
|
-
let ok;
|
|
312
|
-
for (let i = 0; i < channelOptions.highWaterMark; i++) {
|
|
313
|
-
ok = ch.sendToQueue(queue, Buffer.from(msg));
|
|
314
|
-
assert.equal(ok, true);
|
|
315
|
-
}
|
|
316
|
-
done();
|
|
317
|
-
});
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
confirm_channel_test('publish on closed channel does not leak callbacks', (_ch, done) => {
|
|
321
|
-
ch = _ch;
|
|
322
|
-
ch.close(() => {
|
|
323
|
-
for (let i = 0; i < 10; i++) {
|
|
324
|
-
try { ch.publish('', '', Buffer.from('x'), {}, () => {}); } catch (_) {}
|
|
325
|
-
}
|
|
326
|
-
assert.strictEqual(ch.unconfirmed.length, 0);
|
|
327
|
-
done();
|
|
328
|
-
});
|
|
329
|
-
});
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
describe('Error handling', () => {
|
|
333
|
-
|
|
334
|
-
let c;
|
|
335
|
-
|
|
336
|
-
afterEach((_t, done) => {
|
|
337
|
-
c?.close(() => done());
|
|
338
|
-
})
|
|
339
|
-
|
|
340
|
-
it('Throw error in connection open callback', (_t, done) => {
|
|
341
|
-
const dom = domain.createDomain();
|
|
342
|
-
dom.on('error', (err) => {
|
|
343
|
-
assert.match(err.message, /Spurious connection open callback error/);
|
|
344
|
-
done();
|
|
345
|
-
});
|
|
346
|
-
connect(dom.bind((_err, _c) => {
|
|
347
|
-
c = _c;
|
|
348
|
-
throw new Error('Spurious connection open callback error');
|
|
349
|
-
}));
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
function error_test(name, fun) {
|
|
353
|
-
it(name, (_t, done) => {
|
|
354
|
-
const dom = domain.createDomain();
|
|
355
|
-
dom.run(() => {
|
|
356
|
-
connect((err, _c) => {
|
|
357
|
-
assert.ifError(err);
|
|
358
|
-
c = _c;
|
|
359
|
-
// Seems like there were some unironed wrinkles in 0.8's
|
|
360
|
-
// implementation of domains; explicitly adding the connection
|
|
361
|
-
// to the domain makes sure any exception thrown in the course
|
|
362
|
-
// of processing frames is handled by the domain. For other
|
|
363
|
-
// versions of Node.JS, this ends up being belt-and-braces.
|
|
364
|
-
dom.add(c);
|
|
365
|
-
c.createChannel((_err, ch) => {
|
|
366
|
-
fun(ch, done, dom);
|
|
367
|
-
});
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
});
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
error_test('Channel open callback throws an error', (_ch, done, dom) => {
|
|
374
|
-
dom.on('error', (err) => {
|
|
375
|
-
assert.match(err.message, /Error in open callback/)
|
|
376
|
-
done();
|
|
377
|
-
});
|
|
378
|
-
throw new Error('Error in open callback');
|
|
379
|
-
});
|
|
380
|
-
|
|
381
|
-
error_test('RPC callback throws error', (ch, done, dom) => {
|
|
382
|
-
dom.on('error', (err) => {
|
|
383
|
-
assert.match(err.message, /Spurious callback error/)
|
|
384
|
-
done();
|
|
385
|
-
});
|
|
386
|
-
ch.prefetch(0, false, (_err, _ok) => {
|
|
387
|
-
throw new Error('Spurious callback error');
|
|
388
|
-
});
|
|
389
|
-
});
|
|
390
|
-
|
|
391
|
-
error_test('Get callback throws error', (ch, done, dom) => {
|
|
392
|
-
dom.on('error', (err) => {
|
|
393
|
-
assert.match(err.message, /Spurious callback error/)
|
|
394
|
-
done();
|
|
395
|
-
});
|
|
396
|
-
ch.assertQueue('test.cb.get-with-error', {}, (_err, _ok) => {
|
|
397
|
-
ch.get('test.cb.get-with-error', { noAck: true }, () => {
|
|
398
|
-
throw new Error('Spurious callback error');
|
|
399
|
-
});
|
|
400
|
-
});
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
error_test('Consume callback throws error', (ch, done, dom) => {
|
|
404
|
-
dom.on('error', (err) => {
|
|
405
|
-
assert.match(err.message, /Spurious callback error/)
|
|
406
|
-
done();
|
|
407
|
-
});
|
|
408
|
-
ch.assertQueue('test.cb.consume-with-error', {}, (_err, _ok) => {
|
|
409
|
-
ch.consume('test.cb.consume-with-error', () => { }, { noAck: true }, () => {
|
|
410
|
-
throw new Error('Spurious callback error');
|
|
411
|
-
});
|
|
412
|
-
});
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
error_test('Get from non-queue invokes error', (ch, done, dom) => {
|
|
416
|
-
const decrementLatch = latch(2, () => done());
|
|
417
|
-
dom.on('error', (err) => {
|
|
418
|
-
assert.match(err.message, /404 \(NOT-FOUND\)/);
|
|
419
|
-
decrementLatch();
|
|
420
|
-
});
|
|
421
|
-
ch.get('', {}, (err) => {
|
|
422
|
-
assert.match(err.message, /404 \(NOT-FOUND\)/)
|
|
423
|
-
decrementLatch()
|
|
424
|
-
});
|
|
425
|
-
});
|
|
426
|
-
|
|
427
|
-
error_test('Consume from non-queue invokes error', (ch, done, dom) => {
|
|
428
|
-
const decrementLatch = latch(2, done);
|
|
429
|
-
dom.on('error', (err) => {
|
|
430
|
-
assert.match(err.message, /404 \(NOT-FOUND\)/);
|
|
431
|
-
decrementLatch();
|
|
432
|
-
});
|
|
433
|
-
ch.consume('', () => { }, {}, (err) => {
|
|
434
|
-
assert.match(err.message, /404 \(NOT-FOUND\)/)
|
|
435
|
-
decrementLatch()
|
|
436
|
-
});
|
|
437
|
-
});
|
|
438
|
-
});
|
|
439
|
-
});
|