amqplib 0.10.8 → 1.0.0

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.
Files changed (85) hide show
  1. package/.claude/commands/lint-disable.md +9 -0
  2. package/.claude/commands/lint-enable.md +12 -0
  3. package/.claude/settings.local.json +16 -0
  4. package/.github/workflows/publish.yml +1 -1
  5. package/.github/workflows/test.yml +1 -1
  6. package/CHANGELOG.md +34 -0
  7. package/CLAUDE.md +12 -0
  8. package/Makefile +5 -12
  9. package/bin/generate-defs.js +382 -369
  10. package/biome.json +51 -0
  11. package/callback_api.js +12 -8
  12. package/channel_api.js +5 -10
  13. package/examples/direct_reply_to_client.js +9 -5
  14. package/examples/direct_reply_to_server.js +8 -6
  15. package/examples/headers.js +13 -10
  16. package/examples/receive_generator.js +13 -20
  17. package/examples/send_generators.js +2 -9
  18. package/examples/ssl.js +2 -3
  19. package/examples/stream_queues/receive_stream.js +39 -36
  20. package/examples/stream_queues/send_stream.js +26 -29
  21. package/examples/tutorials/callback_api/emit_log.js +4 -3
  22. package/examples/tutorials/callback_api/emit_log_direct.js +5 -4
  23. package/examples/tutorials/callback_api/emit_log_topic.js +5 -4
  24. package/examples/tutorials/callback_api/new_task.js +5 -4
  25. package/examples/tutorials/callback_api/receive.js +16 -10
  26. package/examples/tutorials/callback_api/receive_logs.js +17 -11
  27. package/examples/tutorials/callback_api/receive_logs_direct.js +19 -13
  28. package/examples/tutorials/callback_api/receive_logs_topic.js +19 -14
  29. package/examples/tutorials/callback_api/rpc_client.js +20 -16
  30. package/examples/tutorials/callback_api/rpc_server.js +27 -21
  31. package/examples/tutorials/callback_api/send.js +4 -3
  32. package/examples/tutorials/callback_api/worker.js +18 -13
  33. package/examples/tutorials/emit_log.js +4 -6
  34. package/examples/tutorials/emit_log_direct.js +5 -7
  35. package/examples/tutorials/emit_log_topic.js +5 -7
  36. package/examples/tutorials/new_task.js +4 -6
  37. package/examples/tutorials/receive.js +8 -4
  38. package/examples/tutorials/receive_logs.js +10 -6
  39. package/examples/tutorials/receive_logs_direct.js +16 -10
  40. package/examples/tutorials/receive_logs_topic.js +16 -11
  41. package/examples/tutorials/rpc_client.js +17 -15
  42. package/examples/tutorials/rpc_server.js +9 -8
  43. package/examples/tutorials/send.js +4 -6
  44. package/examples/tutorials/worker.js +17 -14
  45. package/examples/waitForConfirms.js +2 -2
  46. package/lefthook.yml +14 -0
  47. package/lib/api_args.js +124 -149
  48. package/lib/bitset.js +28 -18
  49. package/lib/callback_model.js +134 -190
  50. package/lib/channel.js +175 -213
  51. package/lib/channel_model.js +41 -85
  52. package/lib/codec.js +257 -228
  53. package/lib/connect.js +74 -82
  54. package/lib/connection.js +204 -240
  55. package/lib/credentials.js +21 -29
  56. package/lib/defs.js +2559 -1927
  57. package/lib/error.js +5 -6
  58. package/lib/format.js +15 -33
  59. package/lib/frame.js +66 -66
  60. package/lib/heartbeat.js +17 -24
  61. package/lib/mux.js +32 -41
  62. package/package.json +8 -5
  63. package/test/bitset.test.js +65 -0
  64. package/test/callback_api.test.js +438 -0
  65. package/test/channel.test.js +592 -0
  66. package/test/channel_api.test.js +537 -0
  67. package/test/codec.test.js +172 -0
  68. package/test/connect.test.js +196 -0
  69. package/test/connection.test.js +330 -0
  70. package/test/data.test.js +33 -0
  71. package/test/frame.test.js +180 -0
  72. package/test/lib/data.js +249 -0
  73. package/test/lib/util.js +223 -0
  74. package/test/mux.test.js +215 -0
  75. package/test/bitset.js +0 -69
  76. package/test/callback_api.js +0 -379
  77. package/test/channel.js +0 -621
  78. package/test/channel_api.js +0 -606
  79. package/test/codec.js +0 -237
  80. package/test/connect.js +0 -197
  81. package/test/connection.js +0 -390
  82. package/test/data.js +0 -269
  83. package/test/frame.js +0 -191
  84. package/test/mux.js +0 -203
  85. package/test/util.js +0 -217
@@ -1,606 +0,0 @@
1
- 'use strict';
2
-
3
- var assert = require('assert');
4
- var api = require('../channel_api');
5
- var util = require('./util');
6
- var succeed = util.succeed, fail = util.fail;
7
- var schedule = util.schedule;
8
- var randomString = util.randomString;
9
- var promisify = require('util').promisify;
10
-
11
- var URL = process.env.URL || 'amqp://localhost';
12
-
13
- function connect() {
14
- return api.connect(URL);
15
- }
16
-
17
- // Expect this promise to fail, and flip the results accordingly.
18
- function expectFail(promise) {
19
- return new Promise(function(resolve, reject) {
20
- return promise.then(reject).catch(resolve);
21
- });
22
- }
23
-
24
- // I'll rely on operations being rejected, rather than the channel
25
- // close error, to detect failure.
26
- function ignore () {}
27
- function ignoreErrors(c) {
28
- c.on('error', ignore); return c;
29
- }
30
- function logErrors(c) {
31
- c.on('error', console.warn); return c;
32
- }
33
-
34
- // Run a test with `name`, given a function that takes an open
35
- // channel, and returns a promise that is resolved on test success or
36
- // rejected on test failure.
37
- function channel_test(chmethod, name, chfun) {
38
- test(name, function(done) {
39
- connect(URL).then(logErrors).then(function(c) {
40
- c[chmethod]().then(ignoreErrors).then(chfun)
41
- .then(succeed(done), fail(done))
42
- // close the connection regardless of what happens with the test
43
- .finally(function() {c.close();});
44
- });
45
- });
46
- }
47
-
48
- var chtest = channel_test.bind(null, 'createChannel');
49
-
50
- suite("connect", function() {
51
-
52
- test("at all", function(done) {
53
- connect(URL).then(function(c) {
54
- return c.close()
55
- ;}).then(succeed(done), fail(done));
56
- });
57
-
58
- chtest("create channel", ignore); // i.e., just don't bork
59
-
60
- });
61
-
62
- suite("updateSecret", function() {
63
- test("updateSecret", function(done) {
64
- connect().then(function(c) {
65
- c.updateSecret(Buffer.from("new secret"), "no reason")
66
- .then(succeed(done), fail(done))
67
- .finally(function() { c.close(); });
68
- });
69
- });
70
- });
71
-
72
- var QUEUE_OPTS = {durable: false};
73
- var EX_OPTS = {durable: false};
74
-
75
- suite("assert, check, delete", function() {
76
-
77
- chtest("assert and check queue", function(ch) {
78
- return ch.assertQueue('test.check-queue', QUEUE_OPTS)
79
- .then(function(qok) {
80
- return ch.checkQueue('test.check-queue');
81
- });
82
- });
83
-
84
- chtest("assert and check exchange", function(ch) {
85
- return ch.assertExchange('test.check-exchange', 'direct', EX_OPTS)
86
- .then(function(eok) {
87
- assert.equal('test.check-exchange', eok.exchange);
88
- return ch.checkExchange('test.check-exchange');
89
- });
90
- });
91
-
92
- chtest("fail on reasserting queue with different options",
93
- function(ch) {
94
- var q = 'test.reassert-queue';
95
- return ch.assertQueue(
96
- q, {durable: false, autoDelete: true})
97
- .then(function() {
98
- return expectFail(
99
- ch.assertQueue(q, {durable: false,
100
- autoDelete: false}));
101
- });
102
- });
103
-
104
- chtest("fail on checking a queue that's not there", function(ch) {
105
- return expectFail(ch.checkQueue('test.random-' + randomString()));
106
- });
107
-
108
- chtest("fail on checking an exchange that's not there", function(ch) {
109
- return expectFail(ch.checkExchange('test.random-' + randomString()));
110
- });
111
-
112
- chtest("fail on reasserting exchange with different type",
113
- function(ch) {
114
- var ex = 'test.reassert-ex';
115
- return ch.assertExchange(ex, 'fanout', EX_OPTS)
116
- .then(function() {
117
- return expectFail(
118
- ch.assertExchange(ex, 'direct', EX_OPTS));
119
- });
120
- });
121
-
122
- chtest("channel break on publishing to non-exchange", function(ch) {
123
- return new Promise(function(resolve) {
124
- ch.on('error', resolve);
125
- ch.publish(randomString(), '', Buffer.from('foobar'));
126
- });
127
- });
128
-
129
- chtest("delete queue", function(ch) {
130
- var q = 'test.delete-queue';
131
- return Promise.all([
132
- ch.assertQueue(q, QUEUE_OPTS),
133
- ch.checkQueue(q)])
134
- .then(function() {
135
- return ch.deleteQueue(q);})
136
- .then(function() {
137
- return expectFail(ch.checkQueue(q));});
138
- });
139
-
140
- chtest("delete exchange", function(ch) {
141
- var ex = 'test.delete-exchange';
142
- return Promise.all([
143
- ch.assertExchange(ex, 'fanout', EX_OPTS),
144
- ch.checkExchange(ex)])
145
- .then(function() {
146
- return ch.deleteExchange(ex);})
147
- .then(function() {
148
- return expectFail(ch.checkExchange(ex));});
149
- });
150
-
151
- });
152
-
153
- // Wait for the queue to meet the condition; useful for waiting for
154
- // messages to arrive, for example.
155
- function waitForQueue(q, condition) {
156
- return connect(URL).then(function(c) {
157
- return c.createChannel()
158
- .then(function(ch) {
159
- return ch.checkQueue(q).then(function(qok) {
160
- function check() {
161
- return ch.checkQueue(q).then(function(qok) {
162
- if (condition(qok)) {
163
- c.close();
164
- return qok;
165
- }
166
- else schedule(check);
167
- });
168
- }
169
- return check();
170
- });
171
- });
172
- });
173
- }
174
-
175
- // Return a promise that resolves when the queue has at least `num`
176
- // messages. If num is not supplied its assumed to be 1.
177
- function waitForMessages(q, num) {
178
- var min = (num === undefined) ? 1 : num;
179
- return waitForQueue(q, function(qok) {
180
- return qok.messageCount >= min;
181
- });
182
- }
183
-
184
- suite("sendMessage", function() {
185
-
186
- // publish different size messages
187
- chtest("send to queue and get from queue", function(ch) {
188
- var q = 'test.send-to-q';
189
- var msg = randomString();
190
- return Promise.all([ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)])
191
- .then(function() {
192
- ch.sendToQueue(q, Buffer.from(msg));
193
- return waitForMessages(q);
194
- })
195
- .then(function() {
196
- return ch.get(q, {noAck: true});
197
- })
198
- .then(function(m) {
199
- assert(m);
200
- assert.equal(msg, m.content.toString());
201
- });
202
- });
203
-
204
- chtest("send (and get) zero content to queue", function(ch) {
205
- var q = 'test.send-to-q';
206
- var msg = Buffer.alloc(0);
207
- return Promise.all([
208
- ch.assertQueue(q, QUEUE_OPTS),
209
- ch.purgeQueue(q)])
210
- .then(function() {
211
- ch.sendToQueue(q, msg);
212
- return waitForMessages(q);})
213
- .then(function() {
214
- return ch.get(q, {noAck: true});})
215
- .then(function(m) {
216
- assert(m);
217
- assert.deepEqual(msg, m.content);
218
- });
219
- });
220
-
221
- });
222
-
223
- suite("binding, consuming", function() {
224
-
225
- // bind, publish, get
226
- chtest("route message", function(ch) {
227
- var ex = 'test.route-message';
228
- var q = 'test.route-message-q';
229
- var msg = randomString();
230
-
231
- return Promise.all([
232
- ch.assertExchange(ex, 'fanout', EX_OPTS),
233
- ch.assertQueue(q, QUEUE_OPTS),
234
- ch.purgeQueue(q),
235
- ch.bindQueue(q, ex, '', {})])
236
- .then(function() {
237
- ch.publish(ex, '', Buffer.from(msg));
238
- return waitForMessages(q);})
239
- .then(function() {
240
- return ch.get(q, {noAck: true});})
241
- .then(function(m) {
242
- assert(m);
243
- assert.equal(msg, m.content.toString());
244
- });
245
- });
246
-
247
- // send to queue, purge, get-empty
248
- chtest("purge queue", function(ch) {
249
- var q = 'test.purge-queue';
250
- return ch.assertQueue(q, {durable: false})
251
- .then(function() {
252
- ch.sendToQueue(q, Buffer.from('foobar'));
253
- return waitForMessages(q);})
254
- .then(function() {
255
- ch.purgeQueue(q);
256
- return ch.get(q, {noAck: true});})
257
- .then(function(m) {
258
- assert(!m); // get-empty
259
- });
260
- });
261
-
262
- // bind again, unbind, publish, get-empty
263
- chtest("unbind queue", function(ch) {
264
- var ex = 'test.unbind-queue-ex';
265
- var q = 'test.unbind-queue';
266
- var viabinding = randomString();
267
- var direct = randomString();
268
-
269
- return Promise.all([
270
- ch.assertExchange(ex, 'fanout', EX_OPTS),
271
- ch.assertQueue(q, QUEUE_OPTS),
272
- ch.purgeQueue(q),
273
- ch.bindQueue(q, ex, '', {})])
274
- .then(function() {
275
- ch.publish(ex, '', Buffer.from('foobar'));
276
- return waitForMessages(q);})
277
- .then(function() { // message got through!
278
- return ch.get(q, {noAck:true})
279
- .then(function(m) {assert(m);});})
280
- .then(function() {
281
- return ch.unbindQueue(q, ex, '', {});})
282
- .then(function() {
283
- // via the no-longer-existing binding
284
- ch.publish(ex, '', Buffer.from(viabinding));
285
- // direct to the queue
286
- ch.sendToQueue(q, Buffer.from(direct));
287
- return waitForMessages(q);})
288
- .then(function() {return ch.get(q)})
289
- .then(function(m) {
290
- // the direct to queue message got through, the via-binding
291
- // message (sent first) did not
292
- assert.equal(direct, m.content.toString());
293
- });
294
- });
295
-
296
- // To some extent this is now just testing semantics of the server,
297
- // but we can at least try out a few settings, and consume.
298
- chtest("consume via exchange-exchange binding", function(ch) {
299
- var ex1 = 'test.ex-ex-binding1', ex2 = 'test.ex-ex-binding2';
300
- var q = 'test.ex-ex-binding-q';
301
- var rk = 'test.routing.key', msg = randomString();
302
- return Promise.all([
303
- ch.assertExchange(ex1, 'direct', EX_OPTS),
304
- ch.assertExchange(ex2, 'fanout',
305
- {durable: false, internal: true}),
306
- ch.assertQueue(q, QUEUE_OPTS),
307
- ch.purgeQueue(q),
308
- ch.bindExchange(ex2, ex1, rk, {}),
309
- ch.bindQueue(q, ex2, '', {})])
310
- .then(function() {
311
- return new Promise(function(resolve, reject) {
312
- function delivery(m) {
313
- if (m.content.toString() === msg) resolve();
314
- else reject(new Error("Wrong message"));
315
- }
316
- ch.consume(q, delivery, {noAck: true})
317
- .then(function() {
318
- ch.publish(ex1, rk, Buffer.from(msg));
319
- });
320
- });
321
- });
322
- });
323
-
324
- // bind again, unbind, publish, get-empty
325
- chtest("unbind exchange", function(ch) {
326
- var source = 'test.unbind-ex-source';
327
- var dest = 'test.unbind-ex-dest';
328
- var q = 'test.unbind-ex-queue';
329
- var viabinding = randomString();
330
- var direct = randomString();
331
-
332
- return Promise.all([
333
- ch.assertExchange(source, 'fanout', EX_OPTS),
334
- ch.assertExchange(dest, 'fanout', EX_OPTS),
335
- ch.assertQueue(q, QUEUE_OPTS),
336
- ch.purgeQueue(q),
337
- ch.bindExchange(dest, source, '', {}),
338
- ch.bindQueue(q, dest, '', {})])
339
- .then(function() {
340
- ch.publish(source, '', Buffer.from('foobar'));
341
- return waitForMessages(q);})
342
- .then(function() { // message got through!
343
- return ch.get(q, {noAck:true})
344
- .then(function(m) {assert(m);});})
345
- .then(function() {
346
- return ch.unbindExchange(dest, source, '', {});})
347
- .then(function() {
348
- // via the no-longer-existing binding
349
- ch.publish(source, '', Buffer.from(viabinding));
350
- // direct to the queue
351
- ch.sendToQueue(q, Buffer.from(direct));
352
- return waitForMessages(q);})
353
- .then(function() {return ch.get(q)})
354
- .then(function(m) {
355
- // the direct to queue message got through, the via-binding
356
- // message (sent first) did not
357
- assert.equal(direct, m.content.toString());
358
- });
359
- });
360
-
361
- // This is a bit convoluted. Sorry.
362
- chtest("cancel consumer", function(ch) {
363
- var q = 'test.consumer-cancel';
364
- var ctag;
365
- var recv1 = new Promise(function (resolve, reject) {
366
- Promise.all([
367
- ch.assertQueue(q, QUEUE_OPTS),
368
- ch.purgeQueue(q),
369
- // My callback is 'resolve the promise in `arrived`'
370
- ch.consume(q, resolve, {noAck:true})
371
- .then(function(ok) {
372
- ctag = ok.consumerTag;
373
- ch.sendToQueue(q, Buffer.from('foo'));
374
- })]);
375
- });
376
-
377
- // A message should arrive because of the consume
378
- return recv1.then(function() {
379
- var recv2 = Promise.all([
380
- ch.cancel(ctag).then(function() {
381
- return ch.sendToQueue(q, Buffer.from('bar'));
382
- }),
383
- // but check a message did arrive in the queue
384
- waitForMessages(q)])
385
- .then(function() {
386
- return ch.get(q, {noAck:true});
387
- })
388
- .then(function(m) {
389
- // I'm going to reject it, because I flip succeed/fail
390
- // just below
391
- if (m.content.toString() === 'bar') {
392
- throw new Error();
393
- }
394
- });
395
-
396
- return expectFail(recv2);
397
- });
398
- });
399
-
400
- chtest("cancelled consumer", function(ch) {
401
- var q = 'test.cancelled-consumer';
402
- return new Promise(function(resolve, reject) {
403
- return Promise.all([
404
- ch.assertQueue(q),
405
- ch.purgeQueue(q),
406
- ch.consume(q, function(msg) {
407
- if (msg === null) resolve();
408
- else reject(new Error('Message not expected'));
409
- })])
410
- .then(function() {
411
- return ch.deleteQueue(q);
412
- });
413
- });
414
- });
415
-
416
- // ack, by default, removes a single message from the queue
417
- chtest("ack", function(ch) {
418
- var q = 'test.ack';
419
- var msg1 = randomString(), msg2 = randomString();
420
-
421
- return Promise.all([
422
- ch.assertQueue(q, QUEUE_OPTS),
423
- ch.purgeQueue(q)])
424
- .then(function() {
425
- ch.sendToQueue(q, Buffer.from(msg1));
426
- ch.sendToQueue(q, Buffer.from(msg2));
427
- return waitForMessages(q, 2);
428
- })
429
- .then(function() {
430
- return ch.get(q, {noAck: false})
431
- })
432
- .then(function(m) {
433
- assert.equal(msg1, m.content.toString());
434
- ch.ack(m);
435
- // %%% is there a race here? may depend on
436
- // rabbitmq-sepcific semantics
437
- return ch.get(q);
438
- })
439
- .then(function(m) {
440
- assert(m);
441
- assert.equal(msg2, m.content.toString());
442
- });
443
- });
444
-
445
- // Nack, by default, puts a message back on the queue (where in the
446
- // queue is up to the server)
447
- chtest("nack", function(ch) {
448
- var q = 'test.nack';
449
- var msg1 = randomString();
450
-
451
- return Promise.all([
452
- ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)])
453
- .then(function() {
454
- ch.sendToQueue(q, Buffer.from(msg1));
455
- return waitForMessages(q);})
456
- .then(function() {
457
- return ch.get(q, {noAck: false})})
458
- .then(function(m) {
459
- assert.equal(msg1, m.content.toString());
460
- ch.nack(m);
461
- return waitForMessages(q);})
462
- .then(function() {
463
- return ch.get(q);})
464
- .then(function(m) {
465
- assert(m);
466
- assert.equal(msg1, m.content.toString());
467
- });
468
- });
469
-
470
- // reject is a near-synonym for nack, the latter of which is not
471
- // available in earlier RabbitMQ (or in AMQP proper).
472
- chtest("reject", function(ch) {
473
- var q = 'test.reject';
474
- var msg1 = randomString();
475
-
476
- return Promise.all([
477
- ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)])
478
- .then(function() {
479
- ch.sendToQueue(q, Buffer.from(msg1));
480
- return waitForMessages(q);})
481
- .then(function() {
482
- return ch.get(q, {noAck: false})})
483
- .then(function(m) {
484
- assert.equal(msg1, m.content.toString());
485
- ch.reject(m);
486
- return waitForMessages(q);})
487
- .then(function() {
488
- return ch.get(q);})
489
- .then(function(m) {
490
- assert(m);
491
- assert.equal(msg1, m.content.toString());
492
- });
493
- });
494
-
495
- chtest("prefetch", function(ch) {
496
- var q = 'test.prefetch';
497
- return Promise.all([
498
- ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q),
499
- ch.prefetch(1)])
500
- .then(function() {
501
- ch.sendToQueue(q, Buffer.from('foobar'));
502
- ch.sendToQueue(q, Buffer.from('foobar'));
503
- return waitForMessages(q, 2);
504
- })
505
- .then(function() {
506
- return new Promise(function(resolve) {
507
- var messageCount = 0;
508
- function receive(msg) {
509
- ch.ack(msg);
510
- if (++messageCount > 1) {
511
- resolve(messageCount);
512
- }
513
- }
514
- return ch.consume(q, receive, {noAck: false})
515
- });
516
- })
517
- .then(function(c) {
518
- return assert.equal(2, c);
519
- });
520
- });
521
-
522
- chtest('close', function(ch) {
523
- // Resolving promise guarantees
524
- // channel is closed
525
- return ch.close();
526
- });
527
-
528
- });
529
-
530
- var confirmtest = channel_test.bind(null, 'createConfirmChannel');
531
-
532
- suite("confirms", function() {
533
-
534
- confirmtest('message is confirmed', function(ch) {
535
- var q = 'test.confirm-message';
536
- return Promise.all([
537
- ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)])
538
- .then(function() {
539
- return ch.sendToQueue(q, Buffer.from('bleep'));
540
- });
541
- });
542
-
543
- // Usually one can provoke the server into confirming more than one
544
- // message in an ack by simply sending a few messages in quick
545
- // succession; a bit unscientific I know. Luckily we can eavesdrop on
546
- // the acknowledgements coming through to see if we really did get a
547
- // multi-ack.
548
- confirmtest('multiple confirms', function(ch) {
549
- var q = 'test.multiple-confirms';
550
- return Promise.all([
551
- ch.assertQueue(q, QUEUE_OPTS), ch.purgeQueue(q)])
552
- .then(function() {
553
- var multipleRainbows = false;
554
- ch.on('ack', function(a) {
555
- if (a.multiple) multipleRainbows = true;
556
- });
557
-
558
- function prod(num) {
559
- var cs = [];
560
-
561
- function sendAndPushPromise() {
562
- var conf = promisify(function(cb) {
563
- return ch.sendToQueue(q, Buffer.from('bleep'), {}, cb);
564
- })();
565
- cs.push(conf);
566
- }
567
-
568
- for (var i=0; i < num; i++) sendAndPushPromise();
569
-
570
- return Promise.all(cs).then(function() {
571
- if (multipleRainbows) return true;
572
- else if (num > 500) throw new Error(
573
- "Couldn't provoke the server" +
574
- " into multi-acking with " + num +
575
- " messages; giving up");
576
- else {
577
- //console.warn("Failed with " + num + "; trying " + num * 2);
578
- return prod(num * 2);
579
- }
580
- });
581
- }
582
- return prod(5);
583
- });
584
- });
585
-
586
- confirmtest('wait for confirms', function(ch) {
587
- for (var i=0; i < 1000; i++) {
588
- ch.publish('', '', Buffer.from('foobar'), {});
589
- }
590
- return ch.waitForConfirms();
591
- })
592
-
593
- confirmtest('works when channel is closed', function(ch) {
594
- for (var i=0; i < 1000; i++) {
595
- ch.publish('', '', Buffer.from('foobar'), {});
596
- }
597
- return ch.close().then(function () {
598
- return ch.waitForConfirms()
599
- }).then(function () {
600
- assert.strictEqual(true, false, 'Wait should have failed.')
601
- }, function (e) {
602
- assert.strictEqual(e.message, 'channel closed')
603
- });
604
- });
605
-
606
- });