amqplib 0.4.2 → 0.5.3

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 (54) hide show
  1. package/CHANGELOG.md +88 -0
  2. package/Makefile +2 -1
  3. package/README.md +4 -4
  4. package/callback_api.js +1 -0
  5. package/channel_api.js +7 -6
  6. package/examples/headers.js +2 -2
  7. package/examples/receive_generator.js +39 -0
  8. package/examples/send_generators.js +42 -0
  9. package/examples/ssl.js +1 -1
  10. package/examples/tutorials/README.md +1 -1
  11. package/examples/tutorials/callback_api/emit_log.js +1 -1
  12. package/examples/tutorials/callback_api/emit_log_direct.js +1 -1
  13. package/examples/tutorials/callback_api/emit_log_topic.js +1 -1
  14. package/examples/tutorials/callback_api/new_task.js +1 -1
  15. package/examples/tutorials/callback_api/rpc_client.js +1 -1
  16. package/examples/tutorials/callback_api/rpc_server.js +1 -1
  17. package/examples/tutorials/callback_api/send.js +1 -1
  18. package/examples/tutorials/emit_log.js +4 -5
  19. package/examples/tutorials/emit_log_direct.js +4 -5
  20. package/examples/tutorials/emit_log_topic.js +4 -5
  21. package/examples/tutorials/new_task.js +5 -6
  22. package/examples/tutorials/package.json +2 -3
  23. package/examples/tutorials/receive.js +4 -4
  24. package/examples/tutorials/receive_logs.js +1 -1
  25. package/examples/tutorials/receive_logs_direct.js +2 -2
  26. package/examples/tutorials/receive_logs_topic.js +6 -6
  27. package/examples/tutorials/rpc_client.js +25 -26
  28. package/examples/tutorials/rpc_server.js +2 -2
  29. package/examples/tutorials/send.js +4 -5
  30. package/examples/tutorials/worker.js +1 -1
  31. package/examples/waitForConfirms.js +2 -2
  32. package/lib/api_args.js +2 -0
  33. package/lib/callback_model.js +11 -10
  34. package/lib/channel.js +24 -12
  35. package/lib/channel_model.js +57 -65
  36. package/lib/codec.js +64 -38
  37. package/lib/connect.js +26 -15
  38. package/lib/connection.js +6 -4
  39. package/lib/credentials.js +20 -3
  40. package/lib/defs.js +203 -75
  41. package/lib/frame.js +2 -1
  42. package/lib/heartbeat.js +1 -1
  43. package/package.json +10 -8
  44. package/test/callback_api.js +6 -5
  45. package/test/channel.js +125 -107
  46. package/test/channel_api.js +125 -136
  47. package/test/codec.js +48 -9
  48. package/test/connect.js +88 -3
  49. package/test/connection.js +57 -56
  50. package/test/data.js +32 -9
  51. package/test/frame.js +4 -4
  52. package/test/mux.js +10 -6
  53. package/test/util.js +35 -21
  54. package/.npmignore +0 -9
package/lib/frame.js CHANGED
@@ -7,6 +7,7 @@
7
7
  var defs = require('./defs');
8
8
  var constants = defs.constants;
9
9
  var decode = defs.decode;
10
+ var Buffer = require('safe-buffer').Buffer
10
11
 
11
12
  var Bits = require('bitsyntax');
12
13
 
@@ -105,7 +106,7 @@ module.exports.decodeFrame = function(frame) {
105
106
  }
106
107
 
107
108
  // encoded heartbeat
108
- module.exports.HEARTBEAT_BUF = new Buffer([constants.FRAME_HEARTBEAT,
109
+ module.exports.HEARTBEAT_BUF = Buffer.from([constants.FRAME_HEARTBEAT,
109
110
  0, 0, 0, 0, // size = 0
110
111
  0, 0, // channel = 0
111
112
  constants.FRAME_END]);
package/lib/heartbeat.js CHANGED
@@ -40,7 +40,7 @@
40
40
  // at least twice before sending another)
41
41
  //
42
42
  // This design is based largely on RabbitMQ's heartbeating:
43
- // https://github.com/rabbitmq/rabbitmq-server/blob/master/src/rabbit_heartbeat.erl
43
+ // https://github.com/rabbitmq/rabbitmq-common/blob/master/src/rabbit_heartbeat.erl
44
44
 
45
45
  // %% Yes, I could apply the same 'actually passage of time' thing to
46
46
  // %% send as well as to recv.
package/package.json CHANGED
@@ -2,26 +2,28 @@
2
2
  "name": "amqplib",
3
3
  "homepage": "http://squaremo.github.io/amqp.node/",
4
4
  "main": "./channel_api.js",
5
- "version": "0.4.2",
5
+ "version": "0.5.3",
6
6
  "description": "An AMQP 0-9-1 (e.g., RabbitMQ) library and client.",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "https://github.com/squaremo/amqp.node.git"
10
10
  },
11
11
  "engines": {
12
- "node": ">=0.8 <6 || ^6"
12
+ "node": ">=0.8 <=9"
13
13
  },
14
14
  "dependencies": {
15
- "bitsyntax": "~0.0.4",
16
- "buffer-more-ints": "0.0.2",
15
+ "bitsyntax": "~0.1.0",
16
+ "bluebird": "^3.5.2",
17
+ "buffer-more-ints": "~1.0.0",
17
18
  "readable-stream": "1.x >=1.1.9",
18
- "when": "~3.6.2"
19
+ "safe-buffer": "~5.1.2",
20
+ "url-parse": "~1.4.3"
19
21
  },
20
22
  "devDependencies": {
21
- "mocha": "~1",
22
23
  "claire": "0.4.1",
23
- "uglify-js": "2.4.x",
24
- "istanbul": "0.1.x"
24
+ "istanbul": "0.1.x",
25
+ "mocha": "^3.5.3",
26
+ "uglify-js": "2.6.x"
25
27
  },
26
28
  "scripts": {
27
29
  "test": "make test",
@@ -8,6 +8,7 @@ var schedule = util.schedule;
8
8
  var randomString = util.randomString;
9
9
  var kCallback = util.kCallback;
10
10
  var domain = require('domain');
11
+ var Buffer = require('safe-buffer').Buffer;
11
12
 
12
13
  var URL = process.env.URL || 'amqp://localhost';
13
14
 
@@ -159,7 +160,7 @@ channel_test('send to queue and consume noAck', function(ch, done) {
159
160
  else done(new Error("message content doesn't match:" +
160
161
  msg + " =/= " + m.content.toString()));
161
162
  }, {noAck: true, exclusive: true});
162
- ch.sendToQueue(q.queue, new Buffer(msg));
163
+ ch.sendToQueue(q.queue, Buffer.from(msg));
163
164
  });
164
165
  });
165
166
 
@@ -175,7 +176,7 @@ channel_test('send to queue and consume ack', function(ch, done) {
175
176
  else done(new Error("message content doesn't match:" +
176
177
  msg + " =/= " + m.content.toString()));
177
178
  }, {noAck: false, exclusive: true});
178
- ch.sendToQueue(q.queue, new Buffer(msg));
179
+ ch.sendToQueue(q.queue, Buffer.from(msg));
179
180
  });
180
181
  });
181
182
 
@@ -183,7 +184,7 @@ channel_test('send to and get from queue', function(ch, done) {
183
184
  ch.assertQueue('', {exclusive: true}, function(e, q) {
184
185
  if (e != null) return done(e);
185
186
  var msg = randomString();
186
- ch.sendToQueue(q.queue, new Buffer(msg));
187
+ ch.sendToQueue(q.queue, Buffer.from(msg));
187
188
  waitForMessages(ch, q.queue, function(e, _) {
188
189
  if (e != null) return done(e);
189
190
  ch.get(q.queue, {noAck: true}, function(e, m) {
@@ -210,12 +211,12 @@ confirm_channel_test('Receive confirmation', function(ch, done) {
210
211
  // An unroutable message, on the basis that you're not allowed a
211
212
  // queue with an empty name, and you can't make bindings to the
212
213
  // default exchange. Tricky eh?
213
- ch.publish('', '', new Buffer('foo'), {}, done);
214
+ ch.publish('', '', Buffer.from('foo'), {}, done);
214
215
  });
215
216
 
216
217
  confirm_channel_test('Wait for confirms', function(ch, done) {
217
218
  for (var i=0; i < 1000; i++) {
218
- ch.publish('', '', new Buffer('foo'), {});
219
+ ch.publish('', '', Buffer.from('foo'), {});
219
220
  }
220
221
  ch.waitForConfirms(done);
221
222
  });
package/test/channel.js CHANGED
@@ -3,7 +3,7 @@
3
3
  'use strict';
4
4
 
5
5
  var assert = require('assert');
6
- var defer = require('when').defer;
6
+ var Promise = require('bluebird');
7
7
  var Channel = require('../lib/channel').Channel;
8
8
  var Connection = require('../lib/connection').Connection;
9
9
  var util = require('./util');
@@ -12,6 +12,7 @@ var completes = util.completes;
12
12
  var defs = require('../lib/defs');
13
13
  var conn_handshake = require('./connection').connection_handshake;
14
14
  var OPEN_OPTS = require('./connection').OPEN_OPTS;
15
+ var Buffer = require('safe-buffer').Buffer;
15
16
 
16
17
  var LOG_ERRORS = process.env.LOG_ERRORS;
17
18
 
@@ -29,10 +30,10 @@ function baseChannelTest(client, server) {
29
30
  });
30
31
 
31
32
  pair.server.read(8); // discard the protocol header
32
- var s = util.runServer(pair.server, function(send, await) {
33
- conn_handshake(send, await)
33
+ var s = util.runServer(pair.server, function(send, wait) {
34
+ conn_handshake(send, wait)
34
35
  .then(function() {
35
- server(send, await, bothDone);
36
+ server(send, wait, bothDone);
36
37
  }, fail(bothDone));
37
38
  });
38
39
  };
@@ -45,21 +46,21 @@ function channelTest(client, server) {
45
46
  if (LOG_ERRORS) ch.on('error', console.warn);
46
47
  client(ch, done, conn);
47
48
  },
48
- function(send, await, done) {
49
- channel_handshake(send, await)
49
+ function(send, wait, done) {
50
+ channel_handshake(send, wait)
50
51
  .then(function(ch) {
51
- return server(send, await, done, ch);
52
+ return server(send, wait, done, ch);
52
53
  }).then(null, fail(done)); // so you can return a promise to let
53
54
  // errors bubble out
54
55
  }
55
56
  );
56
57
  };
57
58
 
58
- function channel_handshake(send, await) {
59
- return await(defs.ChannelOpen)()
59
+ function channel_handshake(send, wait) {
60
+ return wait(defs.ChannelOpen)()
60
61
  .then(function(open) {
61
62
  assert.notEqual(0, open.channel);
62
- send(defs.ChannelOpenOk, {channelId: new Buffer('')}, open.channel);
63
+ send(defs.ChannelOpenOk, {channelId: Buffer.from('')}, open.channel);
63
64
  return open.channel;
64
65
  });
65
66
  }
@@ -76,14 +77,12 @@ var DELIVER_FIELDS = {
76
77
  };
77
78
 
78
79
  function open(ch) {
79
- var opened = defer();
80
- ch.allocate();
81
- ch._rpc(defs.ChannelOpen, {outOfBand: ''}, defs.ChannelOpenOk,
82
- function(err, _) {
83
- if (err === null) opened.resolve();
84
- else opened.reject(err);
85
- });
86
- return opened.promise;
80
+ return Promise.try(function() {
81
+ ch.allocate();
82
+ return Promise.fromCallback(function(cb) {
83
+ ch._rpc(defs.ChannelOpen, {outOfBand: ''}, defs.ChannelOpenOk, cb);
84
+ });
85
+ });
87
86
  }
88
87
 
89
88
  suite("channel open and close", function() {
@@ -92,7 +91,7 @@ test("open", channelTest(
92
91
  function(ch, done) {
93
92
  open(ch).then(succeed(done), fail(done));
94
93
  },
95
- function(send, await, done) {
94
+ function(send, wait, done) {
96
95
  done();
97
96
  }));
98
97
 
@@ -101,8 +100,8 @@ test("bad server", baseChannelTest(
101
100
  var ch = new Channel(c);
102
101
  open(ch).then(fail(done), succeed(done));
103
102
  },
104
- function(send, await, done) {
105
- return await(defs.ChannelOpen)()
103
+ function(send, wait, done) {
104
+ return wait(defs.ChannelOpen)()
106
105
  .then(function(open) {
107
106
  send(defs.ChannelCloseOk, {}, open.channel);
108
107
  }).then(succeed(done), fail(done));
@@ -112,15 +111,14 @@ test("open, close", channelTest(
112
111
  function(ch, done) {
113
112
  open(ch)
114
113
  .then(function() {
115
- var closed = defer();
116
- ch.closeBecause("Bye", defs.constants.REPLY_SUCCESS,
117
- closed.resolve);
118
- return closed.promise;
114
+ return new Promise(function(resolve) {
115
+ ch.closeBecause("Bye", defs.constants.REPLY_SUCCESS, resolve);
116
+ });
119
117
  })
120
118
  .then(succeed(done), fail(done));
121
119
  },
122
- function(send, await, done, ch) {
123
- return await(defs.ChannelClose)()
120
+ function(send, wait, done, ch) {
121
+ return wait(defs.ChannelClose)()
124
122
  .then(function(close) {
125
123
  send(defs.ChannelCloseOk, {}, ch);
126
124
  }).then(succeed(done), fail(done));
@@ -130,17 +128,19 @@ test("server close", channelTest(
130
128
  function(ch, done) {
131
129
  ch.on('error', function(error) {
132
130
  assert.strictEqual(504, error.code);
131
+ assert.strictEqual(0, error.classId);
132
+ assert.strictEqual(0, error.methodId);
133
133
  succeed(done)();
134
134
  });
135
135
  open(ch);
136
136
  },
137
- function(send, await, done, ch) {
137
+ function(send, wait, done, ch) {
138
138
  send(defs.ChannelClose, {
139
139
  replyText: 'Forced close',
140
140
  replyCode: defs.constants.CHANNEL_ERROR,
141
141
  classId: 0, methodId: 0
142
142
  }, ch);
143
- await(defs.ChannelCloseOk)()
143
+ wait(defs.ChannelCloseOk)()
144
144
  .then(succeed(done), fail(done));
145
145
  }));
146
146
 
@@ -153,8 +153,8 @@ test("overlapping channel/server close", channelTest(
153
153
  ch.closeBecause("Bye", defs.constants.REPLY_SUCCESS);
154
154
  }, fail(both));
155
155
  },
156
- function(send, await, done, ch) {
157
- await(defs.ChannelClose)()
156
+ function(send, wait, done, ch) {
157
+ wait(defs.ChannelClose)()
158
158
  .then(function() {
159
159
  send(defs.ConnectionClose, {
160
160
  replyText: 'Got there first',
@@ -162,7 +162,7 @@ test("overlapping channel/server close", channelTest(
162
162
  classId: 0, methodId: 0
163
163
  }, 0);
164
164
  })
165
- .then(await(defs.ConnectionCloseOk))
165
+ .then(wait(defs.ConnectionCloseOk))
166
166
  .then(succeed(done), fail(done));
167
167
  }));
168
168
 
@@ -176,8 +176,8 @@ test("double close", channelTest(
176
176
  });
177
177
  }).then(succeed(done), fail(done));
178
178
  },
179
- function(send, await, done, ch) {
180
- await(defs.ChannelClose)()
179
+ function(send, wait, done, ch) {
180
+ wait(defs.ChannelClose)()
181
181
  .then(function() {
182
182
  send(defs.ChannelCloseOk, {
183
183
  }, ch);
@@ -204,22 +204,22 @@ test("RPC", channelTest(
204
204
  prefetchSize: 0,
205
205
  global: false
206
206
  };
207
-
207
+
208
208
  ch._rpc(defs.BasicQos, fields, defs.BasicQosOk, wheeboom);
209
209
  ch._rpc(defs.BasicQos, fields, defs.BasicQosOk, wheeboom);
210
210
  ch._rpc(defs.BasicQos, fields, defs.BasicQosOk, wheeboom);
211
211
  }).then(null, fail(rpcLatch));
212
212
  },
213
- function(send, await, done, ch) {
213
+ function(send, wait, done, ch) {
214
214
  function sendOk(f) {
215
215
  send(defs.BasicQosOk, {}, ch);
216
216
  }
217
217
 
218
- return await(defs.BasicQos)()
218
+ return wait(defs.BasicQos)()
219
219
  .then(sendOk)
220
- .then(await(defs.BasicQos))
220
+ .then(wait(defs.BasicQos))
221
221
  .then(sendOk)
222
- .then(await(defs.BasicQos))
222
+ .then(wait(defs.BasicQos))
223
223
  .then(sendOk)
224
224
  .then(succeed(done), fail(done));
225
225
  }));
@@ -231,9 +231,11 @@ test("Bad RPC", channelTest(
231
231
  var errLatch = latch(2, done);
232
232
  ch.on('error', function(error) {
233
233
  assert.strictEqual(505, error.code);
234
+ assert.strictEqual(60, error.classId);
235
+ assert.strictEqual(72, error.methodId);
234
236
  succeed(errLatch)();
235
237
  });
236
-
238
+
237
239
  open(ch)
238
240
  .then(function() {
239
241
  ch._rpc(defs.BasicRecover, {requeue: true}, defs.BasicRecoverOk,
@@ -243,12 +245,12 @@ test("Bad RPC", channelTest(
243
245
  });
244
246
  }, fail(errLatch));
245
247
  },
246
- function(send, await, done, ch) {
247
- return await()()
248
+ function(send, wait, done, ch) {
249
+ return wait()()
248
250
  .then(function() {
249
251
  send(defs.BasicGetEmpty, {clusterId: ''}, ch);
250
252
  }) // oh wait! that was wrong! expect a channel close
251
- .then(await(defs.ChannelClose))
253
+ .then(wait(defs.ChannelClose))
252
254
  .then(function() {
253
255
  send(defs.ChannelCloseOk, {}, ch);
254
256
  }).then(succeed(done), fail(done));
@@ -257,39 +259,49 @@ test("Bad RPC", channelTest(
257
259
  test("RPC on closed channel", channelTest(
258
260
  function(ch, done) {
259
261
  open(ch);
260
- var close = defer(), fail1 = defer(), fail2 = defer();
261
- ch.on('error', function(error) {
262
- assert.strictEqual(504, error.code);
263
- close.resolve();
262
+
263
+ var close = new Promise(function(resolve) {
264
+ ch.on('error', function(error) {
265
+ assert.strictEqual(504, error.code);
266
+ assert.strictEqual(0, error.classId);
267
+ assert.strictEqual(0, error.methodId);
268
+ resolve();
269
+ });
264
270
  });
265
271
 
266
- function failureCb(d) {
272
+ function failureCb(resolve, reject) {
267
273
  return function(err) {
268
- if (err !== null) d.resolve();
269
- else d.reject();
274
+ if (err !== null) resolve();
275
+ else reject();
270
276
  }
271
277
  }
272
278
 
273
- ch._rpc(defs.BasicRecover, {requeue:true}, defs.BasicRecoverOk,
274
- failureCb(fail1));
275
- ch._rpc(defs.BasicRecover, {requeue:true}, defs.BasicRecoverOk,
276
- failureCb(fail2));
277
- close.promise
278
- .then(function() { return fail1.promise; })
279
- .then(function() { return fail2.promise; })
280
- .then(succeed(done), fail(done));
279
+ var fail1 = new Promise(function(resolve, reject) {
280
+ return ch._rpc(defs.BasicRecover, {requeue:true}, defs.BasicRecoverOk,
281
+ failureCb(resolve, reject));
282
+ });
283
+
284
+ var fail2 = new Promise(function(resolve, reject) {
285
+ return ch._rpc(defs.BasicRecover, {requeue:true}, defs.BasicRecoverOk,
286
+ failureCb(resolve, reject));
287
+ });
288
+
289
+ Promise.join(close, fail1, fail2)
290
+ .then(succeed(done))
291
+ .catch(fail(done));
281
292
  },
282
- function(send, await, done, ch) {
283
- await(defs.BasicRecover)()
293
+ function(send, wait, done, ch) {
294
+ wait(defs.BasicRecover)()
284
295
  .then(function() {
285
296
  send(defs.ChannelClose, {
286
297
  replyText: 'Nuh-uh!',
287
298
  replyCode: defs.constants.CHANNEL_ERROR,
288
299
  methodId: 0, classId: 0
289
300
  }, ch);
290
- return await(defs.ChannelCloseOk);
301
+ return wait(defs.ChannelCloseOk);
291
302
  })
292
- .then(succeed(done), fail(done));
303
+ .then(succeed(done))
304
+ .catch(fail(done));
293
305
  }));
294
306
 
295
307
  test("publish all < single chunk threshold", channelTest(
@@ -299,14 +311,14 @@ test("publish all < single chunk threshold", channelTest(
299
311
  ch.sendMessage({
300
312
  exchange: 'foo', routingKey: 'bar',
301
313
  mandatory: false, immediate: false, ticket: 0
302
- }, {}, new Buffer('foobar'));
314
+ }, {}, Buffer.from('foobar'));
303
315
  })
304
316
  .then(succeed(done), fail(done));
305
317
  },
306
- function(send, await, done, ch) {
307
- await(defs.BasicPublish)()
308
- .then(await(defs.BasicProperties))
309
- .then(await(undefined)) // content frame
318
+ function(send, wait, done, ch) {
319
+ wait(defs.BasicPublish)()
320
+ .then(wait(defs.BasicProperties))
321
+ .then(wait(undefined)) // content frame
310
322
  .then(function(f) {
311
323
  assert.equal('foobar', f.content.toString());
312
324
  }).then(succeed(done), fail(done));
@@ -319,13 +331,13 @@ test("publish content > single chunk threshold", channelTest(
319
331
  ch.sendMessage({
320
332
  exchange: 'foo', routingKey: 'bar',
321
333
  mandatory: false, immediate: false, ticket: 0
322
- }, {}, new Buffer(3000));
334
+ }, {}, Buffer.alloc(3000));
323
335
  }, done);
324
336
  },
325
- function(send, await, done, ch) {
326
- await(defs.BasicPublish)()
327
- .then(await(defs.BasicProperties))
328
- .then(await(undefined)) // content frame
337
+ function(send, wait, done, ch) {
338
+ wait(defs.BasicPublish)()
339
+ .then(wait(defs.BasicProperties))
340
+ .then(wait(undefined)) // content frame
329
341
  .then(function(f) {
330
342
  assert.equal(3000, f.content.length);
331
343
  }).then(succeed(done), fail(done));
@@ -339,14 +351,14 @@ test("publish method & headers > threshold", channelTest(
339
351
  exchange: 'foo', routingKey: 'bar',
340
352
  mandatory: false, immediate: false, ticket: 0
341
353
  }, {
342
- headers: {foo: new Buffer(3000)}
343
- }, new Buffer('foobar'));
354
+ headers: {foo: Buffer.alloc(3000)}
355
+ }, Buffer.from('foobar'));
344
356
  }, done);
345
357
  },
346
- function(send, await, done, ch) {
347
- await(defs.BasicPublish)()
348
- .then(await(defs.BasicProperties))
349
- .then(await(undefined)) // content frame
358
+ function(send, wait, done, ch) {
359
+ wait(defs.BasicPublish)()
360
+ .then(wait(defs.BasicProperties))
361
+ .then(wait(undefined)) // content frame
350
362
  .then(function(f) {
351
363
  assert.equal('foobar', f.content.toString());
352
364
  }).then(succeed(done), fail(done));
@@ -359,18 +371,18 @@ test("publish zero-length message", channelTest(
359
371
  ch.sendMessage({
360
372
  exchange: 'foo', routingKey: 'bar',
361
373
  mandatory: false, immediate: false, ticket: 0
362
- }, {}, new Buffer(0));
374
+ }, {}, Buffer.alloc(0));
363
375
  ch.sendMessage({
364
376
  exchange: 'foo', routingKey: 'bar',
365
377
  mandatory: false, immediate: false, ticket: 0
366
- }, {}, new Buffer(0));
378
+ }, {}, Buffer.alloc(0));
367
379
  }, done);
368
380
  },
369
- function(send, await, done, ch) {
370
- await(defs.BasicPublish)()
371
- .then(await(defs.BasicProperties))
381
+ function(send, wait, done, ch) {
382
+ wait(defs.BasicPublish)()
383
+ .then(wait(defs.BasicProperties))
372
384
  // no content frame for a zero-length message
373
- .then(await(defs.BasicPublish))
385
+ .then(wait(defs.BasicPublish))
374
386
  .then(succeed(done), fail(done));
375
387
  }));
376
388
 
@@ -383,9 +395,9 @@ test("delivery", channelTest(
383
395
  }, done);
384
396
  });
385
397
  },
386
- function(send, await, done, ch) {
398
+ function(send, wait, done, ch) {
387
399
  completes(function() {
388
- send(defs.BasicDeliver, DELIVER_FIELDS, ch, new Buffer('barfoo'));
400
+ send(defs.BasicDeliver, DELIVER_FIELDS, ch, Buffer.from('barfoo'));
389
401
  }, done);
390
402
  }));
391
403
 
@@ -394,13 +406,13 @@ test("zero byte msg", channelTest(
394
406
  open(ch);
395
407
  ch.on('delivery', function(m) {
396
408
  completes(function() {
397
- assert.deepEqual(new Buffer(0), m.content);
409
+ assert.deepEqual(Buffer.alloc(0), m.content);
398
410
  }, done);
399
411
  });
400
412
  },
401
- function(send, await, done, ch) {
413
+ function(send, wait, done, ch) {
402
414
  completes(function() {
403
- send(defs.BasicDeliver, DELIVER_FIELDS, ch, new Buffer(''));
415
+ send(defs.BasicDeliver, DELIVER_FIELDS, ch, Buffer.from(''));
404
416
  }, done);
405
417
  }));
406
418
 
@@ -409,16 +421,18 @@ test("bad delivery", channelTest(
409
421
  var errorAndClose = latch(2, done);
410
422
  ch.on('error', function(error) {
411
423
  assert.strictEqual(505, error.code);
424
+ assert.strictEqual(60, error.classId);
425
+ assert.strictEqual(60, error.methodId);
412
426
  succeed(errorAndClose)();
413
427
  });
414
428
  ch.on('close', succeed(errorAndClose));
415
429
  open(ch);
416
430
  },
417
- function(send, await, done, ch) {
431
+ function(send, wait, done, ch) {
418
432
  send(defs.BasicDeliver, DELIVER_FIELDS, ch);
419
433
  // now send another deliver without having sent the content
420
434
  send(defs.BasicDeliver, DELIVER_FIELDS, ch);
421
- return await(defs.ChannelClose)()
435
+ return wait(defs.ChannelClose)()
422
436
  .then(function() {
423
437
  send(defs.ChannelCloseOk, {}, ch);
424
438
  }).then(succeed(done), fail(done));
@@ -435,7 +449,7 @@ test("bad content send", channelTest(
435
449
  });
436
450
  }, done);
437
451
  },
438
- function(send, await, done, ch) {
452
+ function(send, wait, done, ch) {
439
453
  done();
440
454
  }));
441
455
 
@@ -447,13 +461,13 @@ test("bad properties send", channelTest(
447
461
  ch.sendMessage({routingKey: 'foo',
448
462
  exchange: 'amq.direct'},
449
463
  {contentEncoding: 7},
450
- new Buffer('foobar'));
464
+ Buffer.from('foobar'));
451
465
  });
452
466
  }, done);
453
467
  },
454
- function(send, await, done, ch) {
468
+ function(send, wait, done, ch) {
455
469
  done();
456
- }));
470
+ }));
457
471
 
458
472
  test("bad consumer", channelTest(
459
473
  function(ch, done) {
@@ -463,14 +477,16 @@ test("bad consumer", channelTest(
463
477
  });
464
478
  ch.on('error', function(error) {
465
479
  assert.strictEqual(541, error.code);
480
+ assert.strictEqual(undefined, error.classId);
481
+ assert.strictEqual(undefined, error.methodId);
466
482
  succeed(errorAndClose)();
467
483
  });
468
484
  ch.on('close', succeed(errorAndClose));
469
485
  open(ch);
470
486
  },
471
- function(send, await, done, ch) {
472
- send(defs.BasicDeliver, DELIVER_FIELDS, ch, new Buffer('barfoo'));
473
- return await(defs.ChannelClose)()
487
+ function(send, wait, done, ch) {
488
+ send(defs.BasicDeliver, DELIVER_FIELDS, ch, Buffer.from('barfoo'));
489
+ return wait(defs.ChannelClose)()
474
490
  .then(function() {
475
491
  send(defs.ChannelCloseOk, {}, ch);
476
492
  }).then(succeed(done), fail(done));
@@ -482,6 +498,8 @@ test("bad send in consumer", channelTest(
482
498
  ch.on('close', succeed(errorAndClose));
483
499
  ch.on('error', function(error) {
484
500
  assert.strictEqual(541, error.code);
501
+ assert.strictEqual(undefined, error.classId);
502
+ assert.strictEqual(undefined, error.methodId);
485
503
  succeed(errorAndClose)();
486
504
  });
487
505
 
@@ -493,12 +511,12 @@ test("bad send in consumer", channelTest(
493
511
 
494
512
  open(ch);
495
513
  },
496
- function(send, await, done, ch) {
514
+ function(send, wait, done, ch) {
497
515
  completes(function() {
498
516
  send(defs.BasicDeliver, DELIVER_FIELDS, ch,
499
- new Buffer('barfoo'));
517
+ Buffer.from('barfoo'));
500
518
  }, done);
501
- return await(defs.ChannelClose)()
519
+ return wait(defs.ChannelClose)()
502
520
  .then(function() {
503
521
  send(defs.ChannelCloseOk, {}, ch);
504
522
  }).then(succeed(done), fail(done));
@@ -513,9 +531,9 @@ test("return", channelTest(
513
531
  });
514
532
  open(ch);
515
533
  },
516
- function(send, await, done, ch) {
534
+ function(send, wait, done, ch) {
517
535
  completes(function() {
518
- send(defs.BasicReturn, DELIVER_FIELDS, ch, new Buffer('barfoo'));
536
+ send(defs.BasicReturn, DELIVER_FIELDS, ch, Buffer.from('barfoo'));
519
537
  }, done);
520
538
  }));
521
539
 
@@ -528,7 +546,7 @@ test("cancel", channelTest(
528
546
  });
529
547
  open(ch);
530
548
  },
531
- function(send, await, done, ch) {
549
+ function(send, wait, done, ch) {
532
550
  completes(function() {
533
551
  send(defs.BasicCancel, {
534
552
  consumerTag: 'product of society',
@@ -547,7 +565,7 @@ function confirmTest(variety, Method) {
547
565
  });
548
566
  open(ch);
549
567
  },
550
- function(send, await, done, ch) {
568
+ function(send, wait, done, ch) {
551
569
  completes(function() {
552
570
  send(Method, {
553
571
  deliveryTag: 1,
@@ -573,7 +591,7 @@ test("out-of-order acks", channelTest(
573
591
  ch.pushConfirmCallback(allConfirms);
574
592
  open(ch);
575
593
  },
576
- function(send, await, done, ch) {
594
+ function(send, wait, done, ch) {
577
595
  completes(function() {
578
596
  send(defs.BasicAck, {deliveryTag: 2, multiple: false}, ch);
579
597
  send(defs.BasicAck, {deliveryTag: 3, multiple: false}, ch);
@@ -596,7 +614,7 @@ test("not all out-of-order acks", channelTest(
596
614
  });
597
615
  open(ch);
598
616
  },
599
- function(send, await, done, ch) {
617
+ function(send, wait, done, ch) {
600
618
  completes(function() {
601
619
  send(defs.BasicAck, {deliveryTag: 2, multiple: false}, ch);
602
620
  send(defs.BasicAck, {deliveryTag: 1, multiple: false}, ch);