amqplib 0.5.2 → 0.5.6
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/.npmignore +8 -0
- package/CHANGELOG.md +68 -0
- package/Makefile +2 -1
- package/README.md +2 -2
- package/bin/generate-defs.js +723 -0
- package/examples/tutorials/package.json +1 -1
- package/lib/api_args.js +2 -0
- package/lib/channel.js +28 -10
- package/lib/connect.js +6 -16
- package/lib/connection.js +2 -1
- package/lib/credentials.js +14 -0
- package/lib/defs.js +129 -1
- package/lib/mux.js +6 -21
- package/package-lock.json +711 -0
- package/package.json +11 -10
- package/test/channel.js +73 -61
- package/test/channel_api.js +13 -0
- package/test/connect.js +32 -7
- package/test/connection.js +47 -47
- package/test/mux.js +44 -6
- package/test/util.js +2 -2
package/test/connection.js
CHANGED
|
@@ -19,12 +19,12 @@ var OPEN_OPTS = {
|
|
|
19
19
|
'mechanism': 'PLAIN',
|
|
20
20
|
'response': Buffer.from(['', 'guest', 'guest'].join(String.fromCharCode(0))),
|
|
21
21
|
'locale': 'en_US',
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
// tune-ok
|
|
24
24
|
'channelMax': 0,
|
|
25
25
|
'frameMax': 0,
|
|
26
26
|
'heartbeat': 0,
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
// open
|
|
29
29
|
'virtualHost': '/',
|
|
30
30
|
'capabilities': '',
|
|
@@ -32,7 +32,7 @@ var OPEN_OPTS = {
|
|
|
32
32
|
};
|
|
33
33
|
module.exports.OPEN_OPTS = OPEN_OPTS;
|
|
34
34
|
|
|
35
|
-
function happy_open(send,
|
|
35
|
+
function happy_open(send, wait) {
|
|
36
36
|
// kick it off
|
|
37
37
|
send(defs.ConnectionStart,
|
|
38
38
|
{versionMajor: 0,
|
|
@@ -40,15 +40,15 @@ function happy_open(send, await) {
|
|
|
40
40
|
serverProperties: {},
|
|
41
41
|
mechanisms: Buffer.from('PLAIN'),
|
|
42
42
|
locales: Buffer.from('en_US')});
|
|
43
|
-
return
|
|
43
|
+
return wait(defs.ConnectionStartOk)()
|
|
44
44
|
.then(function(f) {
|
|
45
45
|
send(defs.ConnectionTune,
|
|
46
46
|
{channelMax: 0,
|
|
47
47
|
heartbeat: 0,
|
|
48
48
|
frameMax: 0});
|
|
49
49
|
})
|
|
50
|
-
.then(
|
|
51
|
-
.then(
|
|
50
|
+
.then(wait(defs.ConnectionTuneOk))
|
|
51
|
+
.then(wait(defs.ConnectionOpen))
|
|
52
52
|
.then(function(f) {
|
|
53
53
|
send(defs.ConnectionOpenOk,
|
|
54
54
|
{knownHosts: ''});
|
|
@@ -69,8 +69,8 @@ function connectionTest(client, server) {
|
|
|
69
69
|
assert.deepEqual(Buffer.from("AMQP" + String.fromCharCode(0,0,9,1)),
|
|
70
70
|
protocolHeader);
|
|
71
71
|
|
|
72
|
-
var s = util.runServer(pair.server, function(send,
|
|
73
|
-
server(send,
|
|
72
|
+
var s = util.runServer(pair.server, function(send, wait) {
|
|
73
|
+
server(send, wait, bothDone, pair.server);
|
|
74
74
|
});
|
|
75
75
|
};
|
|
76
76
|
}
|
|
@@ -106,15 +106,15 @@ test("happy", connectionTest(
|
|
|
106
106
|
function(c, done) {
|
|
107
107
|
c.open(OPEN_OPTS, kCallback(succeed(done), fail(done)));
|
|
108
108
|
},
|
|
109
|
-
function(send,
|
|
110
|
-
happy_open(send,
|
|
109
|
+
function(send, wait, done) {
|
|
110
|
+
happy_open(send, wait).then(succeed(done), fail(done));
|
|
111
111
|
}));
|
|
112
112
|
|
|
113
113
|
test("wrong first frame", connectionTest(
|
|
114
114
|
function(c, done) {
|
|
115
115
|
c.open(OPEN_OPTS, kCallback(fail(done), succeed(done)));
|
|
116
116
|
},
|
|
117
|
-
function(send,
|
|
117
|
+
function(send, wait, done) {
|
|
118
118
|
// bad server! bad! whatever were you thinking?
|
|
119
119
|
completes(function() {
|
|
120
120
|
send(defs.ConnectionTune,
|
|
@@ -128,14 +128,14 @@ test("unexpected socket close", connectionTest(
|
|
|
128
128
|
function(c, done) {
|
|
129
129
|
c.open(OPEN_OPTS, kCallback(fail(done), succeed(done)));
|
|
130
130
|
},
|
|
131
|
-
function(send,
|
|
131
|
+
function(send, wait, done, socket) {
|
|
132
132
|
send(defs.ConnectionStart,
|
|
133
133
|
{versionMajor: 0,
|
|
134
134
|
versionMinor: 9,
|
|
135
135
|
serverProperties: {},
|
|
136
136
|
mechanisms: Buffer.from('PLAIN'),
|
|
137
137
|
locales: Buffer.from('en_US')});
|
|
138
|
-
return
|
|
138
|
+
return wait(defs.ConnectionStartOk)()
|
|
139
139
|
.then(function() {
|
|
140
140
|
socket.end();
|
|
141
141
|
})
|
|
@@ -151,15 +151,15 @@ test("wrong frame on channel 0", connectionTest(
|
|
|
151
151
|
c.on('error', succeed(done));
|
|
152
152
|
c.open(OPEN_OPTS);
|
|
153
153
|
},
|
|
154
|
-
function(send,
|
|
155
|
-
happy_open(send,
|
|
154
|
+
function(send, wait, done) {
|
|
155
|
+
happy_open(send, wait)
|
|
156
156
|
.then(function() {
|
|
157
157
|
// there's actually nothing that would plausibly be sent to a
|
|
158
158
|
// just opened connection, so this is violating more than one
|
|
159
159
|
// rule. Nonetheless.
|
|
160
160
|
send(defs.ChannelOpenOk, {channelId: Buffer.from('')}, 0);
|
|
161
161
|
})
|
|
162
|
-
.then(
|
|
162
|
+
.then(wait(defs.ConnectionClose))
|
|
163
163
|
.then(function(close) {
|
|
164
164
|
send(defs.ConnectionCloseOk, {}, 0);
|
|
165
165
|
}).then(succeed(done), fail(done));
|
|
@@ -170,15 +170,15 @@ test("unopened channel", connectionTest(
|
|
|
170
170
|
c.on('error', succeed(done));
|
|
171
171
|
c.open(OPEN_OPTS);
|
|
172
172
|
},
|
|
173
|
-
function(send,
|
|
174
|
-
happy_open(send,
|
|
173
|
+
function(send, wait, done) {
|
|
174
|
+
happy_open(send, wait)
|
|
175
175
|
.then(function() {
|
|
176
176
|
// there's actually nothing that would plausibly be sent to a
|
|
177
177
|
// just opened connection, so this is violating more than one
|
|
178
178
|
// rule. Nonetheless.
|
|
179
179
|
send(defs.ChannelOpenOk, {channelId: Buffer.from('')}, 3);
|
|
180
180
|
})
|
|
181
|
-
.then(
|
|
181
|
+
.then(wait(defs.ConnectionClose))
|
|
182
182
|
.then(function(close) {
|
|
183
183
|
send(defs.ConnectionCloseOk, {}, 0);
|
|
184
184
|
}).then(succeed(done), fail(done));
|
|
@@ -193,9 +193,9 @@ test("unexpected socket close", connectionTest(
|
|
|
193
193
|
c.sendHeartbeat();
|
|
194
194
|
}, fail(errorAndClosed)));
|
|
195
195
|
},
|
|
196
|
-
function(send,
|
|
197
|
-
happy_open(send,
|
|
198
|
-
.then(
|
|
196
|
+
function(send, wait, done, socket) {
|
|
197
|
+
happy_open(send, wait)
|
|
198
|
+
.then(wait())
|
|
199
199
|
.then(function() {
|
|
200
200
|
socket.end();
|
|
201
201
|
}).then(succeed(done));
|
|
@@ -206,8 +206,8 @@ test("connection.blocked", connectionTest(
|
|
|
206
206
|
c.on('blocked', succeed(done));
|
|
207
207
|
c.open(OPEN_OPTS);
|
|
208
208
|
},
|
|
209
|
-
function(send,
|
|
210
|
-
happy_open(send,
|
|
209
|
+
function(send, wait, done, socket) {
|
|
210
|
+
happy_open(send, wait)
|
|
211
211
|
.then(function() {
|
|
212
212
|
send(defs.ConnectionBlocked, {reason: 'felt like it'}, 0);
|
|
213
213
|
})
|
|
@@ -219,8 +219,8 @@ test("connection.unblocked", connectionTest(
|
|
|
219
219
|
c.on('unblocked', succeed(done));
|
|
220
220
|
c.open(OPEN_OPTS);
|
|
221
221
|
},
|
|
222
|
-
function(send,
|
|
223
|
-
happy_open(send,
|
|
222
|
+
function(send, wait, done, socket) {
|
|
223
|
+
happy_open(send, wait)
|
|
224
224
|
.then(function() {
|
|
225
225
|
send(defs.ConnectionUnblocked, {}, 0);
|
|
226
226
|
})
|
|
@@ -240,9 +240,9 @@ test("happy", connectionTest(
|
|
|
240
240
|
c.close(kCallback(succeed(done), fail(done)));
|
|
241
241
|
}, function() {}));
|
|
242
242
|
},
|
|
243
|
-
function(send,
|
|
244
|
-
happy_open(send,
|
|
245
|
-
.then(
|
|
243
|
+
function(send, wait, done) {
|
|
244
|
+
happy_open(send, wait)
|
|
245
|
+
.then(wait(defs.ConnectionClose))
|
|
246
246
|
.then(function(close) {
|
|
247
247
|
send(defs.ConnectionCloseOk, {});
|
|
248
248
|
})
|
|
@@ -257,9 +257,9 @@ test("interleaved close frames", connectionTest(
|
|
|
257
257
|
c.close(kCallback(succeed(done), fail(done)));
|
|
258
258
|
}, done));
|
|
259
259
|
},
|
|
260
|
-
function(send,
|
|
261
|
-
happy_open(send,
|
|
262
|
-
.then(
|
|
260
|
+
function(send, wait, done) {
|
|
261
|
+
happy_open(send, wait)
|
|
262
|
+
.then(wait(defs.ConnectionClose))
|
|
263
263
|
.then(function(f) {
|
|
264
264
|
send(defs.ConnectionClose, {
|
|
265
265
|
replyText: "Ha!",
|
|
@@ -267,7 +267,7 @@ test("interleaved close frames", connectionTest(
|
|
|
267
267
|
methodId: 0, classId: 0
|
|
268
268
|
});
|
|
269
269
|
})
|
|
270
|
-
.then(
|
|
270
|
+
.then(wait(defs.ConnectionCloseOk))
|
|
271
271
|
.then(function(f) {
|
|
272
272
|
send(defs.ConnectionCloseOk, {});
|
|
273
273
|
})
|
|
@@ -281,8 +281,8 @@ test("server error close", connectionTest(
|
|
|
281
281
|
c.on('error', succeed(done));
|
|
282
282
|
c.open(OPEN_OPTS);
|
|
283
283
|
},
|
|
284
|
-
function(send,
|
|
285
|
-
happy_open(send,
|
|
284
|
+
function(send, wait, done) {
|
|
285
|
+
happy_open(send, wait)
|
|
286
286
|
.then(function(f) {
|
|
287
287
|
send(defs.ConnectionClose, {
|
|
288
288
|
replyText: "Begone",
|
|
@@ -290,7 +290,7 @@ test("server error close", connectionTest(
|
|
|
290
290
|
methodId: 0, classId: 0
|
|
291
291
|
});
|
|
292
292
|
})
|
|
293
|
-
.then(
|
|
293
|
+
.then(wait(defs.ConnectionCloseOk))
|
|
294
294
|
.then(succeed(done), fail(done));
|
|
295
295
|
}));
|
|
296
296
|
|
|
@@ -300,8 +300,8 @@ test("operator-intiated close", connectionTest(
|
|
|
300
300
|
c.on('error', fail(done));
|
|
301
301
|
c.open(OPEN_OPTS);
|
|
302
302
|
},
|
|
303
|
-
function(send,
|
|
304
|
-
happy_open(send,
|
|
303
|
+
function(send, wait, done) {
|
|
304
|
+
happy_open(send, wait)
|
|
305
305
|
.then(function(f) {
|
|
306
306
|
send(defs.ConnectionClose, {
|
|
307
307
|
replyText: "Begone",
|
|
@@ -309,7 +309,7 @@ test("operator-intiated close", connectionTest(
|
|
|
309
309
|
methodId: 0, classId: 0
|
|
310
310
|
});
|
|
311
311
|
})
|
|
312
|
-
.then(
|
|
312
|
+
.then(wait(defs.ConnectionCloseOk))
|
|
313
313
|
.then(succeed(done), fail(done));
|
|
314
314
|
}));
|
|
315
315
|
|
|
@@ -325,9 +325,9 @@ test("double close", connectionTest(
|
|
|
325
325
|
done();
|
|
326
326
|
}, done));
|
|
327
327
|
},
|
|
328
|
-
function(send,
|
|
329
|
-
happy_open(send,
|
|
330
|
-
.then(
|
|
328
|
+
function(send, wait, done) {
|
|
329
|
+
happy_open(send, wait)
|
|
330
|
+
.then(wait(defs.ConnectionClose))
|
|
331
331
|
.then(function() {
|
|
332
332
|
send(defs.ConnectionCloseOk, {});
|
|
333
333
|
})
|
|
@@ -359,15 +359,15 @@ test("send heartbeat after open", connectionTest(
|
|
|
359
359
|
c.open(opts);
|
|
360
360
|
}, done);
|
|
361
361
|
},
|
|
362
|
-
function(send,
|
|
362
|
+
function(send, wait, done, socket) {
|
|
363
363
|
var timer;
|
|
364
|
-
happy_open(send,
|
|
364
|
+
happy_open(send, wait)
|
|
365
365
|
.then(function() {
|
|
366
366
|
timer = setInterval(function() {
|
|
367
367
|
socket.write(HB_BUF);
|
|
368
368
|
}, heartbeat.UNITS_TO_MS);
|
|
369
369
|
})
|
|
370
|
-
.then(
|
|
370
|
+
.then(wait())
|
|
371
371
|
.then(function(hb) {
|
|
372
372
|
if (hb === HEARTBEAT) done();
|
|
373
373
|
else done("Next frame after silence not a heartbeat");
|
|
@@ -382,8 +382,8 @@ test("detect lack of heartbeats", connectionTest(
|
|
|
382
382
|
c.on('error', succeed(done));
|
|
383
383
|
c.open(opts);
|
|
384
384
|
},
|
|
385
|
-
function(send,
|
|
386
|
-
happy_open(send,
|
|
385
|
+
function(send, wait, done, socket) {
|
|
386
|
+
happy_open(send, wait)
|
|
387
387
|
.then(succeed(done), fail(done));
|
|
388
388
|
// conspicuously not sending anything ...
|
|
389
389
|
}));
|
package/test/mux.js
CHANGED
|
@@ -37,7 +37,7 @@ test("single input", function(done) {
|
|
|
37
37
|
var mux = new Mux(output);
|
|
38
38
|
mux.pipeFrom(input);
|
|
39
39
|
|
|
40
|
-
var data = [1,2,3,4,5,6,7,8,9];
|
|
40
|
+
var data = [1,2,3,4,5,6,7,8,9];
|
|
41
41
|
// not 0, it's treated specially by PassThrough for some reason. By
|
|
42
42
|
// 'specially' I mean it breaks the stream. See e.g.,
|
|
43
43
|
// https://github.com/isaacs/readable-stream/pull/55
|
|
@@ -51,6 +51,40 @@ test("single input", function(done) {
|
|
|
51
51
|
input.end();
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
+
test("single input, resuming stream", function(done) {
|
|
55
|
+
var input = stream();
|
|
56
|
+
var output = stream();
|
|
57
|
+
input.on('end', function() { output.end() });
|
|
58
|
+
|
|
59
|
+
var mux = new Mux(output);
|
|
60
|
+
mux.pipeFrom(input);
|
|
61
|
+
|
|
62
|
+
// Streams might be blocked and become readable again, simulate this
|
|
63
|
+
// using a special read function and a marker
|
|
64
|
+
var data = [1,2,3,4,'skip',6,7,8,9];
|
|
65
|
+
|
|
66
|
+
var oldRead = input.read;
|
|
67
|
+
input.read = function(size) {
|
|
68
|
+
var val = oldRead.call(input, size)
|
|
69
|
+
|
|
70
|
+
if (val === 'skip') {
|
|
71
|
+
input.emit('readable');
|
|
72
|
+
return null
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return val;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
data.forEach(input.write.bind(input));
|
|
79
|
+
|
|
80
|
+
readAllObjects(output, function(vals) {
|
|
81
|
+
assert.deepEqual([1,2,3,4,6,7,8,9], vals);
|
|
82
|
+
done();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
input.end();
|
|
86
|
+
});
|
|
87
|
+
|
|
54
88
|
test("two sequential inputs", function(done) {
|
|
55
89
|
var input1 = stream();
|
|
56
90
|
var input2 = stream();
|
|
@@ -112,16 +146,20 @@ test("unpipe", function(done) {
|
|
|
112
146
|
|
|
113
147
|
schedule(function() {
|
|
114
148
|
pipedData.forEach(input.write.bind(input));
|
|
115
|
-
mux.unpipeFrom(input);
|
|
116
149
|
|
|
117
150
|
schedule(function() {
|
|
118
|
-
|
|
119
|
-
|
|
151
|
+
mux.unpipeFrom(input);
|
|
152
|
+
|
|
120
153
|
schedule(function() {
|
|
121
|
-
|
|
122
|
-
|
|
154
|
+
unpipedData.forEach(input.write.bind(input));
|
|
155
|
+
input.end();
|
|
156
|
+
schedule(function() {
|
|
157
|
+
// exhaust so that 'end' fires
|
|
158
|
+
var v; while (v = input.read());
|
|
159
|
+
});
|
|
123
160
|
});
|
|
124
161
|
});
|
|
162
|
+
|
|
125
163
|
});
|
|
126
164
|
|
|
127
165
|
input.on('end', function() {
|
package/test/util.js
CHANGED
|
@@ -76,7 +76,7 @@ function runServer(socket, run) {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
function
|
|
79
|
+
function wait(method) {
|
|
80
80
|
return function() {
|
|
81
81
|
return new Promise(function(resolve, reject) {
|
|
82
82
|
if (method) {
|
|
@@ -98,7 +98,7 @@ function runServer(socket, run) {
|
|
|
98
98
|
});
|
|
99
99
|
};
|
|
100
100
|
}
|
|
101
|
-
run(send,
|
|
101
|
+
run(send, wait);
|
|
102
102
|
return frames;
|
|
103
103
|
}
|
|
104
104
|
|