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
@@ -0,0 +1,215 @@
1
+ const { describe, it } = require('node:test');
2
+ const assert = require('node:assert');
3
+ const Mux = require('../lib/mux').Mux;
4
+ const PassThrough = require('node:stream').PassThrough;
5
+
6
+ const latch = require('./lib/util').latch;
7
+ const schedule = require('./lib/util').schedule;
8
+
9
+ function stream() {
10
+ return new PassThrough({ objectMode: true });
11
+ }
12
+
13
+ function readAllObjects(s, cb) {
14
+ const objs = [];
15
+
16
+ function read() {
17
+ let v = s.read();
18
+ while (v !== null) {
19
+ objs.push(v);
20
+ v = s.read();
21
+ }
22
+ }
23
+
24
+ s.on('end', () => {
25
+ cb(objs);
26
+ });
27
+ s.on('readable', read);
28
+
29
+ read();
30
+ }
31
+
32
+ describe('mux', () => {
33
+
34
+ it('single input', (_t, done) => {
35
+ const input = stream();
36
+ const output = stream();
37
+ input.on('end', () => output.end());
38
+
39
+ const mux = new Mux(output);
40
+ mux.pipeFrom(input);
41
+
42
+ const data = [1, 2, 3, 4, 5, 6, 7, 8, 9];
43
+ // not 0, it's treated specially by PassThrough for some reason. By
44
+ // 'specially' I mean it breaks the stream. See e.g.,
45
+ // https://github.com/isaacs/readable-stream/pull/55
46
+ data.forEach((chunk) => input.write(chunk));
47
+
48
+ readAllObjects(output, (vals) => {
49
+ assert.deepEqual(data, vals);
50
+ done();
51
+ });
52
+
53
+ input.end();
54
+ });
55
+
56
+ it('single input, resuming stream', (_t, done) => {
57
+ const input = stream();
58
+ const output = stream();
59
+ input.on('end', () => output.end());
60
+
61
+ const mux = new Mux(output);
62
+ mux.pipeFrom(input);
63
+
64
+ // Streams might be blocked and become readable again, simulate this
65
+ // using a special read function and a marker
66
+ const data = [1, 2, 3, 4, 'skip', 6, 7, 8, 9];
67
+
68
+ const oldRead = input.read;
69
+ input.read = (size) => {
70
+ const val = oldRead.call(input, size);
71
+
72
+ if (val === 'skip') {
73
+ input.emit('readable');
74
+ return null;
75
+ }
76
+
77
+ return val;
78
+ };
79
+
80
+ data.forEach((chunk) => input.write(chunk));
81
+
82
+ readAllObjects(output, (vals) => {
83
+ assert.deepEqual([1, 2, 3, 4, 6, 7, 8, 9], vals);
84
+ done();
85
+ });
86
+
87
+ input.end();
88
+ });
89
+
90
+ it('two sequential inputs', (_t, done) => {
91
+ const input1 = stream();
92
+ const input2 = stream();
93
+ const output = stream();
94
+ const mux = new Mux(output);
95
+ mux.pipeFrom(input1);
96
+ mux.pipeFrom(input2);
97
+
98
+ const data = [1, 2, 3, 4, 5, 6, 7, 8, 9];
99
+ data.forEach((v) => {
100
+ input1.write(v);
101
+ });
102
+
103
+ input1.on('end', () => {
104
+ data.forEach((v) => {
105
+ input2.write(v);
106
+ });
107
+ input2.end();
108
+ });
109
+ input2.on('end', () => output.end());
110
+
111
+ input1.end();
112
+ readAllObjects(output, (vs) => {
113
+ assert.equal(2 * data.length, vs.length);
114
+ done();
115
+ });
116
+ });
117
+
118
+ it('two interleaved inputs', (_t, done) => {
119
+ const input1 = stream();
120
+ const input2 = stream();
121
+ const output = stream();
122
+ const mux = new Mux(output);
123
+ mux.pipeFrom(input1);
124
+ mux.pipeFrom(input2);
125
+
126
+ const decrementLatch = latch(2, () => output.end());
127
+ input1.on('end', decrementLatch);
128
+ input2.on('end', decrementLatch);
129
+
130
+ const data = [1, 2, 3, 4, 5, 6, 7, 8, 9];
131
+ data.forEach((v) => {
132
+ input1.write(v);
133
+ });
134
+ input1.end();
135
+
136
+ data.forEach((v) => input2.write(v));
137
+ input2.end();
138
+
139
+ readAllObjects(output, (vs) => {
140
+ assert.equal(2 * data.length, vs.length);
141
+ done();
142
+ });
143
+ });
144
+
145
+ it('unpipe', (_t, done) => {
146
+ const input = stream();
147
+ const output = stream();
148
+ const mux = new Mux(output);
149
+
150
+ const pipedData = [1, 2, 3, 4, 5];
151
+ const unpipedData = [6, 7, 8, 9];
152
+
153
+ mux.pipeFrom(input);
154
+
155
+ schedule(() => {
156
+ pipedData.forEach((chunk) => input.write(chunk));
157
+
158
+ schedule(() => {
159
+ mux.unpipeFrom(input);
160
+
161
+ schedule(() => {
162
+ unpipedData.forEach((chunk) => input.write(chunk));
163
+ input.end();
164
+ schedule(() => {
165
+ // exhaust so that 'end' fires
166
+ let v;
167
+ do {
168
+ v = input.read();
169
+ } while (v);
170
+ });
171
+ });
172
+ });
173
+ });
174
+
175
+ input.on('end', () => output.end());
176
+
177
+ readAllObjects(output, (vals) => {
178
+ try {
179
+ assert.deepEqual(pipedData, vals);
180
+ done();
181
+ } catch (e) {
182
+ done(e);
183
+ }
184
+ });
185
+ });
186
+
187
+ it('roundrobin', (_t, done) => {
188
+ const input1 = stream();
189
+ const input2 = stream();
190
+ const output = stream();
191
+ const mux = new Mux(output);
192
+
193
+ mux.pipeFrom(input1);
194
+ mux.pipeFrom(input2);
195
+
196
+ const decrementLatch = latch(2, () => output.end());
197
+ input1.on('end', decrementLatch);
198
+ input2.on('end', decrementLatch);
199
+
200
+ const ones = [1, 1, 1, 1, 1];
201
+ ones.forEach((v) => {
202
+ input1.write(v);
203
+ });
204
+ input1.end();
205
+
206
+ const twos = [2, 2, 2, 2, 2];
207
+ twos.forEach((v) => input2.write(v));
208
+ input2.end();
209
+
210
+ readAllObjects(output, (vs) => {
211
+ assert.deepEqual([1, 2, 1, 2, 1, 2, 1, 2, 1, 2], vs);
212
+ done();
213
+ });
214
+ });
215
+ });
package/test/bitset.js DELETED
@@ -1,69 +0,0 @@
1
- 'use strict';
2
-
3
- const claire = require('claire');
4
- const {BitSet} = require('../lib/bitset');
5
-
6
- const {
7
- forAll,
8
- data: arb,
9
- label,
10
- choice,
11
- transform
12
- } = claire;
13
-
14
- const PosInt = transform(Math.floor, arb.Positive);
15
-
16
- const EmptyBitSet = label('bitset', transform(
17
- size => {
18
- return new BitSet(size);
19
- },
20
- choice(arb.Nothing, PosInt)));
21
-
22
- suite('BitSet', () => {
23
-
24
- test('get bit', forAll(EmptyBitSet, PosInt)
25
- .satisfy((b, bit) => {
26
- b.set(bit);
27
- return b.get(bit);
28
- }).asTest());
29
-
30
- test('clear bit', forAll(EmptyBitSet, PosInt)
31
- .satisfy((b, bit) => {
32
- b.set(bit);
33
- b.clear(bit);
34
- return !b.get(bit);
35
- }).asTest());
36
-
37
- test('next set of empty', forAll(EmptyBitSet)
38
- .satisfy(b => {
39
- return b.nextSetBit(0) === -1;
40
- }).asTest());
41
-
42
- test('next set of one bit', forAll(EmptyBitSet, PosInt)
43
- .satisfy((b, bit) => {
44
- b.set(bit);
45
- return b.nextSetBit(0) === bit;
46
- }).asTest());
47
-
48
- test('next set same bit', forAll(EmptyBitSet, PosInt)
49
- .satisfy((b, bit) => {
50
- b.set(bit);
51
- return b.nextSetBit(bit) === bit;
52
- }).asTest());
53
-
54
- test('next set following bit', forAll(EmptyBitSet, PosInt)
55
- .satisfy((b, bit) => {
56
- b.set(bit);
57
- return b.nextSetBit(bit+1) === -1;
58
- }).asTest());
59
-
60
- test('next clear of empty', forAll(EmptyBitSet, PosInt)
61
- .satisfy((b, bit) => { return b.nextClearBit(bit) === bit; })
62
- .asTest());
63
-
64
- test('next clear of one set', forAll(EmptyBitSet, PosInt)
65
- .satisfy((b, bit) => {
66
- b.set(bit);
67
- return b.nextClearBit(bit) === bit + 1;
68
- }).asTest());
69
- });
@@ -1,379 +0,0 @@
1
- 'use strict';
2
-
3
- var assert = require('assert');
4
- var crypto = require('crypto');
5
- var api = require('../callback_api');
6
- var util = require('./util');
7
- var schedule = util.schedule;
8
- var randomString = util.randomString;
9
- var kCallback = util.kCallback;
10
- var domain = require('domain');
11
-
12
- var URL = process.env.URL || 'amqp://localhost';
13
-
14
- function connect(cb) {
15
- api.connect(URL, {}, cb);
16
- }
17
-
18
- // Construct a node-style callback from a `done` function
19
- function doneCallback(done) {
20
- return function(err, _) {
21
- if (err == null) done();
22
- else done(err);
23
- };
24
- }
25
-
26
- function ignore() {}
27
-
28
- function twice(done) {
29
- var first = function(err) {
30
- if (err == undefined) second = done;
31
- else second = ignore, done(err);
32
- };
33
- var second = function(err) {
34
- if (err == undefined) first = done;
35
- else first = ignore, done(err);
36
- };
37
- return {first: function(err) { first(err); },
38
- second: function(err) { second(err); }};
39
- }
40
-
41
- // Adapt 'done' to a callback that's expected to fail
42
- function failCallback(done) {
43
- return function(err, _) {
44
- if (err == null) done(new Error('Expected failure, got ' + val));
45
- else done();
46
- };
47
- }
48
-
49
- function waitForMessages(ch, q, k) {
50
- ch.checkQueue(q, function(e, ok) {
51
- if (e != null) return k(e);
52
- else if (ok.messageCount > 0) return k(null, ok);
53
- else schedule(waitForMessages.bind(null, ch, q, k));
54
- });
55
- }
56
-
57
-
58
- suite('connect', function() {
59
-
60
- test('at all', function(done) {
61
- connect(doneCallback(done));
62
- });
63
-
64
- });
65
-
66
- suite('updateSecret', function() {
67
- test('updateSecret', function(done) {
68
- connect(kCallback(function(c) {
69
- c.updateSecret(Buffer.from('new secret'), 'no reason', doneCallback(done));
70
- }));
71
- });
72
- });
73
-
74
- function channel_test_fn(method) {
75
- return function(name, options, chfun) {
76
- if (arguments.length === 2) {
77
- chfun = options;
78
- options = {};
79
- }
80
- test(name, function(done) {
81
- connect(kCallback(function(c) {
82
- c[method](options, kCallback(function(ch) {
83
- chfun(ch, done);
84
- }, done));
85
- }, done));
86
- });
87
- };
88
- }
89
- var channel_test = channel_test_fn('createChannel');
90
- var confirm_channel_test = channel_test_fn('createConfirmChannel');
91
-
92
- suite('channel open', function() {
93
-
94
- channel_test('at all', function(ch, done) {
95
- done();
96
- });
97
-
98
- channel_test('open and close', function(ch, done) {
99
- ch.close(doneCallback(done));
100
- });
101
-
102
- });
103
-
104
- suite('assert, check, delete', function() {
105
-
106
- channel_test('assert, check, delete queue', function(ch, done) {
107
- ch.assertQueue('test.cb.queue', {}, kCallback(function(q) {
108
- ch.checkQueue('test.cb.queue', kCallback(function(ok) {
109
- ch.deleteQueue('test.cb.queue', {}, doneCallback(done));
110
- }, done));
111
- }, done));
112
- });
113
-
114
- channel_test('assert, check, delete exchange', function(ch, done) {
115
- ch.assertExchange(
116
- 'test.cb.exchange', 'topic', {}, kCallback(function(ex) {
117
- ch.checkExchange('test.cb.exchange', kCallback(function(ok) {
118
- ch.deleteExchange('test.cb.exchange', {}, doneCallback(done));
119
- }, done));
120
- }, done));
121
- });
122
-
123
- channel_test('fail on check non-queue', function(ch, done) {
124
- var both = twice(done);
125
- ch.on('error', failCallback(both.first));
126
- ch.checkQueue('test.cb.nothere', failCallback(both.second));
127
- });
128
-
129
- channel_test('fail on check non-exchange', function(ch, done) {
130
- var both = twice(done);
131
- ch.on('error', failCallback(both.first));
132
- ch.checkExchange('test.cb.nothere', failCallback(both.second));
133
- });
134
-
135
- });
136
-
137
- suite('bindings', function() {
138
-
139
- channel_test('bind queue', function(ch, done) {
140
- ch.assertQueue('test.cb.bindq', {}, kCallback(function(q) {
141
- ch.assertExchange(
142
- 'test.cb.bindex', 'fanout', {}, kCallback(function(ex) {
143
- ch.bindQueue(q.queue, ex.exchange, '', {},
144
- doneCallback(done));
145
- }, done));
146
- }, done));
147
- });
148
-
149
- channel_test('bind exchange', function(ch, done) {
150
- ch.assertExchange(
151
- 'test.cb.bindex1', 'fanout', {}, kCallback(function(ex1) {
152
- ch.assertExchange(
153
- 'test.cb.bindex2', 'fanout', {}, kCallback(function(ex2) {
154
- ch.bindExchange(ex1.exchange,
155
- ex2.exchange, '', {},
156
- doneCallback(done));
157
- }, done));
158
- }, done));
159
- });
160
-
161
- });
162
-
163
- suite('sending messages', function() {
164
-
165
- channel_test('send to queue and consume noAck', function(ch, done) {
166
- var msg = randomString();
167
- ch.assertQueue('', {exclusive: true}, function(e, q) {
168
- if (e !== null) return done(e);
169
- ch.consume(q.queue, function(m) {
170
- if (m.content.toString() == msg) done();
171
- else done(new Error("message content doesn't match:" +
172
- msg + " =/= " + m.content.toString()));
173
- }, {noAck: true, exclusive: true});
174
- ch.sendToQueue(q.queue, Buffer.from(msg));
175
- });
176
- });
177
-
178
- channel_test('send to queue and consume ack', function(ch, done) {
179
- var msg = randomString();
180
- ch.assertQueue('', {exclusive: true}, function(e, q) {
181
- if (e !== null) return done(e);
182
- ch.consume(q.queue, function(m) {
183
- if (m.content.toString() == msg) {
184
- ch.ack(m);
185
- done();
186
- }
187
- else done(new Error("message content doesn't match:" +
188
- msg + " =/= " + m.content.toString()));
189
- }, {noAck: false, exclusive: true});
190
- ch.sendToQueue(q.queue, Buffer.from(msg));
191
- });
192
- });
193
-
194
- channel_test('send to and get from queue', function(ch, done) {
195
- ch.assertQueue('', {exclusive: true}, function(e, q) {
196
- if (e != null) return done(e);
197
- var msg = randomString();
198
- ch.sendToQueue(q.queue, Buffer.from(msg));
199
- waitForMessages(ch, q.queue, function(e, _) {
200
- if (e != null) return done(e);
201
- ch.get(q.queue, {noAck: true}, function(e, m) {
202
- if (e != null)
203
- return done(e);
204
- else if (!m)
205
- return done(new Error('Empty (false) not expected'));
206
- else if (m.content.toString() == msg)
207
- return done();
208
- else
209
- return done(
210
- new Error('Messages do not match: ' +
211
- msg + ' =/= ' + m.content.toString()));
212
- });
213
- });
214
- });
215
- });
216
-
217
- var channelOptions = {};
218
-
219
- channel_test('find high watermark', function(ch, done) {
220
- var msg = randomString();
221
- var baseline = 0;
222
- ch.assertQueue('', {exclusive: true}, function(e, q) {
223
- if (e !== null) return done(e);
224
- while (ch.sendToQueue(q.queue, Buffer.from(msg))) {
225
- baseline++;
226
- };
227
- channelOptions.highWaterMark = baseline * 2;
228
- done();
229
- })
230
- });
231
-
232
- channel_test('set high watermark', channelOptions, function(ch, done) {
233
- var msg = randomString();
234
- ch.assertQueue('', {exclusive: true}, function(e, q) {
235
- if (e !== null) return done(e);
236
- var ok;
237
- for (var i = 0; i < channelOptions.highWaterMark; i++) {
238
- ok = ch.sendToQueue(q.queue, Buffer.from(msg));
239
- assert.equal(ok, true);
240
- }
241
- done();
242
- });
243
- });
244
- });
245
-
246
- suite('ConfirmChannel', function() {
247
-
248
- confirm_channel_test('Receive confirmation', function(ch, done) {
249
- // An unroutable message, on the basis that you're not allowed a
250
- // queue with an empty name, and you can't make bindings to the
251
- // default exchange. Tricky eh?
252
- ch.publish('', '', Buffer.from('foo'), {}, done);
253
- });
254
-
255
- confirm_channel_test('Wait for confirms', function(ch, done) {
256
- for (var i=0; i < 1000; i++) {
257
- ch.publish('', '', Buffer.from('foo'), {});
258
- }
259
- ch.waitForConfirms(done);
260
- });
261
-
262
- var channelOptions = {};
263
-
264
- confirm_channel_test('find high watermark', function(ch, done) {
265
- var msg = randomString();
266
- var baseline = 0;
267
- ch.assertQueue('', {exclusive: true}, function(e, q) {
268
- if (e !== null) return done(e);
269
- while (ch.sendToQueue(q.queue, Buffer.from(msg))) {
270
- baseline++;
271
- };
272
- channelOptions.highWaterMark = baseline * 2;
273
- done();
274
- })
275
- });
276
-
277
- confirm_channel_test('set high watermark', channelOptions, function(ch, done) {
278
- var msg = randomString();
279
- ch.assertQueue('', {exclusive: true}, function(e, q) {
280
- if (e !== null) return done(e);
281
- var ok;
282
- for (var i = 0; i < channelOptions.highWaterMark; i++) {
283
- ok = ch.sendToQueue(q.queue, Buffer.from(msg));
284
- assert.equal(ok, true);
285
- }
286
- done();
287
- });
288
- });
289
-
290
- });
291
-
292
- suite("Error handling", function() {
293
-
294
- /*
295
- I don't like having to do this, but there appears to be something
296
- broken about domains in Node.JS v0.8 and mocha. Apparently it has to
297
- do with how mocha and domains hook into error propogation:
298
- https://github.com/visionmedia/mocha/issues/513 (summary: domains in
299
- Node.JS v0.8 don't prevent uncaughtException from firing, and that's
300
- what mocha uses to detect .. an uncaught exception).
301
-
302
- Using domains with amqplib *does* work in practice in Node.JS v0.8:
303
- that is, it's possible to throw an exception in a callback and deal
304
- with it in the active domain, and thereby avoid it crashing the
305
- program.
306
- */
307
- if (util.versionGreaterThan(process.versions.node, '0.8')) {
308
- test('Throw error in connection open callback', function(done) {
309
- var dom = domain.createDomain();
310
- dom.on('error', failCallback(done));
311
- connect(dom.bind(function(err, conn) {
312
- throw new Error('Spurious connection open callback error');
313
- }));
314
- });
315
- }
316
-
317
- // TODO: refactor {error_test, channel_test}
318
- function error_test(name, fun) {
319
- test(name, function(done) {
320
- var dom = domain.createDomain();
321
- dom.run(function() {
322
- connect(kCallback(function(c) {
323
- // Seems like there were some unironed wrinkles in 0.8's
324
- // implementation of domains; explicitly adding the connection
325
- // to the domain makes sure any exception thrown in the course
326
- // of processing frames is handled by the domain. For other
327
- // versions of Node.JS, this ends up being belt-and-braces.
328
- dom.add(c);
329
- c.createChannel(kCallback(function(ch) {
330
- fun(ch, done, dom);
331
- }, done));
332
- }, done));
333
- });
334
- });
335
- }
336
-
337
- error_test('Channel open callback throws an error', function(ch, done, dom) {
338
- dom.on('error', failCallback(done));
339
- throw new Error('Error in open callback');
340
- });
341
-
342
- error_test('RPC callback throws error', function(ch, done, dom) {
343
- dom.on('error', failCallback(done));
344
- ch.prefetch(0, false, function(err, ok) {
345
- throw new Error('Spurious callback error');
346
- });
347
- });
348
-
349
- error_test('Get callback throws error', function(ch, done, dom) {
350
- dom.on('error', failCallback(done));
351
- ch.assertQueue('test.cb.get-with-error', {}, function(err, ok) {
352
- ch.get('test.cb.get-with-error', {noAck: true}, function() {
353
- throw new Error('Spurious callback error');
354
- });
355
- });
356
- });
357
-
358
- error_test('Consume callback throws error', function(ch, done, dom) {
359
- dom.on('error', failCallback(done));
360
- ch.assertQueue('test.cb.consume-with-error', {}, function(err, ok) {
361
- ch.consume('test.cb.consume-with-error', ignore, {noAck: true}, function() {
362
- throw new Error('Spurious callback error');
363
- });
364
- });
365
- });
366
-
367
- error_test('Get from non-queue invokes error k', function(ch, done, dom) {
368
- var both = twice(failCallback(done));
369
- dom.on('error', both.first);
370
- ch.get('', {}, both.second);
371
- });
372
-
373
- error_test('Consume from non-queue invokes error k', function(ch, done, dom) {
374
- var both = twice(failCallback(done));
375
- dom.on('error', both.first);
376
- ch.consume('', both.second);
377
- });
378
-
379
- });