typespeed 2.0.13 → 2.0.16
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/dist/core.decorator.js +0 -1
- package/dist/database.decorator.js +0 -1
- package/dist/default/express-server.class.js +0 -1
- package/dist/default/log-default.class.js +0 -1
- package/dist/default/node-cache.class.js +0 -1
- package/dist/default/rabbitmq.class.js +0 -1
- package/dist/default/read-write-db.class.js +0 -1
- package/dist/default/redis.class.js +0 -1
- package/dist/factory/cache-factory.class.js +0 -1
- package/dist/factory/data-source-factory.class.js +0 -1
- package/dist/factory/log-factory.class.js +0 -1
- package/dist/factory/server-factory.class.js +0 -1
- package/dist/route.decorator.js +0 -1
- package/dist/scaffold/command.js +0 -1
- package/dist/typespeed.d.ts +133 -12
- package/dist/typespeed.js +1 -1
- package/package.json +2 -2
- package/src/typespeed.d.ts +133 -0
- package/src/typespeed.ts +2 -1
- package/test/node_modules/.package-lock.json +112 -4
- package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-ci.yml +17 -0
- package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-publish.yml +30 -0
- package/test/node_modules/@acuminous/bitsyntax/LICENSE +6 -0
- package/test/node_modules/@acuminous/bitsyntax/LICENSE-MIT +21 -0
- package/test/node_modules/@acuminous/bitsyntax/Makefile +15 -0
- package/test/node_modules/@acuminous/bitsyntax/README.md +308 -0
- package/test/node_modules/@acuminous/bitsyntax/index.js +10 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/compile.js +303 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/constructor.js +142 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/grammar.pegjs +67 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/interp.js +232 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/parse.js +32 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/parser.js +1173 -0
- package/test/node_modules/@acuminous/bitsyntax/lib/pattern.js +119 -0
- package/test/node_modules/@acuminous/bitsyntax/package.json +36 -0
- package/test/node_modules/@acuminous/bitsyntax/test/consing.test.js +50 -0
- package/test/node_modules/@acuminous/bitsyntax/test/matching.test.js +193 -0
- package/test/node_modules/@types/node/README.md +1 -1
- package/test/node_modules/@types/node/buffer.d.ts +5 -2
- package/test/node_modules/@types/node/child_process.d.ts +27 -0
- package/test/node_modules/@types/node/globals.d.ts +1 -0
- package/test/node_modules/@types/node/package.json +2 -2
- package/test/node_modules/@types/node/test.d.ts +43 -20
- package/test/node_modules/@types/node/ts4.8/buffer.d.ts +5 -2
- package/test/node_modules/@types/node/ts4.8/child_process.d.ts +27 -0
- package/test/node_modules/@types/node/ts4.8/globals.d.ts +1 -0
- package/test/node_modules/@types/node/ts4.8/test.d.ts +43 -19
- package/test/node_modules/@types/node/ts4.8/url.d.ts +3 -3
- package/test/node_modules/@types/node/ts4.8/util.d.ts +1 -1
- package/test/node_modules/@types/node/url.d.ts +3 -3
- package/test/node_modules/@types/node/util.d.ts +1 -1
- package/test/node_modules/amqplib/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/test/node_modules/amqplib/.github/workflows/test.yml +38 -0
- package/test/node_modules/amqplib/CHANGELOG.md +430 -0
- package/test/node_modules/amqplib/LICENSE +6 -0
- package/test/node_modules/amqplib/LICENSE-MIT +21 -0
- package/test/node_modules/amqplib/Makefile +47 -0
- package/test/node_modules/amqplib/README.md +157 -0
- package/test/node_modules/amqplib/bin/generate-defs.js +722 -0
- package/test/node_modules/amqplib/callback_api.js +22 -0
- package/test/node_modules/amqplib/channel_api.js +16 -0
- package/test/node_modules/amqplib/examples/headers.js +42 -0
- package/test/node_modules/amqplib/examples/receive_generator.js +39 -0
- package/test/node_modules/amqplib/examples/send_generators.js +42 -0
- package/test/node_modules/amqplib/examples/ssl.js +64 -0
- package/test/node_modules/amqplib/examples/tutorials/README.md +93 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log.js +28 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_direct.js +30 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_topic.js +27 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/new_task.js +27 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive.js +30 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs.js +36 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_direct.js +56 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_topic.js +55 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_client.js +49 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_server.js +45 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/send.js +29 -0
- package/test/node_modules/amqplib/examples/tutorials/callback_api/worker.js +35 -0
- package/test/node_modules/amqplib/examples/tutorials/emit_log.js +19 -0
- package/test/node_modules/amqplib/examples/tutorials/emit_log_direct.js +20 -0
- package/test/node_modules/amqplib/examples/tutorials/emit_log_topic.js +19 -0
- package/test/node_modules/amqplib/examples/tutorials/new_task.js +18 -0
- package/test/node_modules/amqplib/examples/tutorials/package.json +16 -0
- package/test/node_modules/amqplib/examples/tutorials/receive.js +21 -0
- package/test/node_modules/amqplib/examples/tutorials/receive_logs.js +28 -0
- package/test/node_modules/amqplib/examples/tutorials/receive_logs_direct.js +44 -0
- package/test/node_modules/amqplib/examples/tutorials/receive_logs_topic.js +43 -0
- package/test/node_modules/amqplib/examples/tutorials/rpc_client.js +52 -0
- package/test/node_modules/amqplib/examples/tutorials/rpc_server.js +39 -0
- package/test/node_modules/amqplib/examples/tutorials/send.js +23 -0
- package/test/node_modules/amqplib/examples/tutorials/worker.js +28 -0
- package/test/node_modules/amqplib/examples/waitForConfirms.js +22 -0
- package/test/node_modules/amqplib/lib/api_args.js +314 -0
- package/test/node_modules/amqplib/lib/bitset.js +130 -0
- package/test/node_modules/amqplib/lib/callback_model.js +327 -0
- package/test/node_modules/amqplib/lib/channel.js +499 -0
- package/test/node_modules/amqplib/lib/channel_model.js +302 -0
- package/test/node_modules/amqplib/lib/codec.js +321 -0
- package/test/node_modules/amqplib/lib/connect.js +189 -0
- package/test/node_modules/amqplib/lib/connection.js +663 -0
- package/test/node_modules/amqplib/lib/credentials.js +42 -0
- package/test/node_modules/amqplib/lib/defs.js +4966 -0
- package/test/node_modules/amqplib/lib/error.js +24 -0
- package/test/node_modules/amqplib/lib/format.js +40 -0
- package/test/node_modules/amqplib/lib/frame.js +113 -0
- package/test/node_modules/amqplib/lib/heartbeat.js +89 -0
- package/test/node_modules/amqplib/lib/mux.js +129 -0
- package/test/node_modules/amqplib/package.json +37 -0
- package/test/node_modules/amqplib/test/bitset.js +69 -0
- package/test/node_modules/amqplib/test/callback_api.js +312 -0
- package/test/node_modules/amqplib/test/channel.js +621 -0
- package/test/node_modules/amqplib/test/channel_api.js +596 -0
- package/test/node_modules/amqplib/test/codec.js +237 -0
- package/test/node_modules/amqplib/test/connect.js +197 -0
- package/test/node_modules/amqplib/test/connection.js +390 -0
- package/test/node_modules/amqplib/test/data.js +254 -0
- package/test/node_modules/amqplib/test/frame.js +198 -0
- package/test/node_modules/amqplib/test/mux.js +204 -0
- package/test/node_modules/amqplib/test/util.js +219 -0
- package/test/node_modules/buffer-more-ints/.travis.yml +6 -0
- package/test/node_modules/buffer-more-ints/LICENSE +19 -0
- package/test/node_modules/buffer-more-ints/README.md +69 -0
- package/test/node_modules/buffer-more-ints/buffer-more-ints-tests.js +183 -0
- package/test/node_modules/buffer-more-ints/buffer-more-ints.js +432 -0
- package/test/node_modules/buffer-more-ints/package.json +19 -0
- package/test/node_modules/buffer-more-ints/polyfill.js +71 -0
- package/test/node_modules/core-util-is/LICENSE +19 -0
- package/test/node_modules/core-util-is/README.md +3 -0
- package/test/node_modules/core-util-is/lib/util.js +107 -0
- package/test/node_modules/core-util-is/package.json +38 -0
- package/test/node_modules/debug/LICENSE +20 -0
- package/test/node_modules/debug/README.md +481 -0
- package/test/node_modules/debug/package.json +59 -0
- package/test/node_modules/debug/src/browser.js +269 -0
- package/test/node_modules/debug/src/common.js +274 -0
- package/test/node_modules/debug/src/index.js +10 -0
- package/test/node_modules/debug/src/node.js +263 -0
- package/test/node_modules/inherits/LICENSE +16 -0
- package/test/node_modules/inherits/README.md +42 -0
- package/test/node_modules/inherits/inherits.js +9 -0
- package/test/node_modules/inherits/inherits_browser.js +27 -0
- package/test/node_modules/inherits/package.json +29 -0
- package/test/node_modules/isarray/README.md +54 -0
- package/test/node_modules/isarray/build/build.js +209 -0
- package/test/node_modules/isarray/component.json +19 -0
- package/test/node_modules/isarray/index.js +3 -0
- package/test/node_modules/isarray/package.json +25 -0
- package/test/node_modules/ms/index.js +162 -0
- package/test/node_modules/ms/license.md +21 -0
- package/test/node_modules/ms/package.json +37 -0
- package/test/node_modules/ms/readme.md +60 -0
- package/test/node_modules/querystringify/LICENSE +22 -0
- package/test/node_modules/querystringify/README.md +61 -0
- package/test/node_modules/querystringify/index.js +118 -0
- package/test/node_modules/querystringify/package.json +38 -0
- package/test/node_modules/readable-stream/LICENSE +18 -0
- package/test/node_modules/readable-stream/README.md +15 -0
- package/test/node_modules/readable-stream/duplex.js +1 -0
- package/test/node_modules/readable-stream/float.patch +923 -0
- package/test/node_modules/readable-stream/lib/_stream_duplex.js +89 -0
- package/test/node_modules/readable-stream/lib/_stream_passthrough.js +46 -0
- package/test/node_modules/readable-stream/lib/_stream_readable.js +951 -0
- package/test/node_modules/readable-stream/lib/_stream_transform.js +209 -0
- package/test/node_modules/readable-stream/lib/_stream_writable.js +477 -0
- package/test/node_modules/readable-stream/package.json +32 -0
- package/test/node_modules/readable-stream/passthrough.js +1 -0
- package/test/node_modules/readable-stream/readable.js +10 -0
- package/test/node_modules/readable-stream/transform.js +1 -0
- package/test/node_modules/readable-stream/writable.js +1 -0
- package/test/node_modules/requires-port/.travis.yml +19 -0
- package/test/node_modules/requires-port/LICENSE +22 -0
- package/test/node_modules/requires-port/README.md +47 -0
- package/test/node_modules/requires-port/index.js +38 -0
- package/test/node_modules/requires-port/package.json +47 -0
- package/test/node_modules/requires-port/test.js +98 -0
- package/test/node_modules/safe-buffer/LICENSE +21 -0
- package/test/node_modules/safe-buffer/README.md +584 -0
- package/test/node_modules/safe-buffer/index.d.ts +187 -0
- package/test/node_modules/safe-buffer/index.js +62 -0
- package/test/node_modules/safe-buffer/package.json +37 -0
- package/test/node_modules/string_decoder/LICENSE +20 -0
- package/test/node_modules/string_decoder/README.md +7 -0
- package/test/node_modules/string_decoder/index.js +221 -0
- package/test/node_modules/string_decoder/package.json +25 -0
- package/test/node_modules/url-parse/LICENSE +22 -0
- package/test/node_modules/url-parse/README.md +153 -0
- package/test/node_modules/url-parse/dist/url-parse.js +755 -0
- package/test/node_modules/url-parse/dist/url-parse.min.js +1 -0
- package/test/node_modules/url-parse/dist/url-parse.min.js.map +1 -0
- package/test/node_modules/url-parse/index.js +589 -0
- package/test/node_modules/url-parse/package.json +49 -0
- package/test/src/test-mq.class.ts +1 -2
- package/tsconfig.json +4 -3
- package/dist/core.decorator.d.ts +0 -18
- package/dist/core.decorator.js.map +0 -1
- package/dist/database.decorator.d.ts +0 -24
- package/dist/database.decorator.js.map +0 -1
- package/dist/default/express-server.class.d.ts +0 -15
- package/dist/default/express-server.class.js.map +0 -1
- package/dist/default/log-default.class.d.ts +0 -6
- package/dist/default/log-default.class.js.map +0 -1
- package/dist/default/node-cache.class.d.ts +0 -13
- package/dist/default/node-cache.class.js.map +0 -1
- package/dist/default/rabbitmq.class.d.ts +0 -9
- package/dist/default/rabbitmq.class.js.map +0 -1
- package/dist/default/read-write-db.class.d.ts +0 -10
- package/dist/default/read-write-db.class.js.map +0 -1
- package/dist/default/redis.class.d.ts +0 -5
- package/dist/default/redis.class.js.map +0 -1
- package/dist/factory/cache-factory.class.d.ts +0 -7
- package/dist/factory/cache-factory.class.js.map +0 -1
- package/dist/factory/data-source-factory.class.d.ts +0 -4
- package/dist/factory/data-source-factory.class.js.map +0 -1
- package/dist/factory/log-factory.class.d.ts +0 -4
- package/dist/factory/log-factory.class.js.map +0 -1
- package/dist/factory/server-factory.class.d.ts +0 -6
- package/dist/factory/server-factory.class.js.map +0 -1
- package/dist/route.decorator.d.ts +0 -8
- package/dist/route.decorator.js.map +0 -1
- package/dist/scaffold/command.d.ts +0 -2
- package/dist/scaffold/command.js.map +0 -1
- package/dist/typespeed.js.map +0 -1
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
// Test the channel machinery
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
var assert = require('assert');
|
|
6
|
+
var promisify = require('util').promisify;
|
|
7
|
+
var Channel = require('../lib/channel').Channel;
|
|
8
|
+
var Connection = require('../lib/connection').Connection;
|
|
9
|
+
var util = require('./util');
|
|
10
|
+
var succeed = util.succeed, fail = util.fail, latch = util.latch;
|
|
11
|
+
var completes = util.completes;
|
|
12
|
+
var defs = require('../lib/defs');
|
|
13
|
+
var conn_handshake = require('./connection').connection_handshake;
|
|
14
|
+
var OPEN_OPTS = require('./connection').OPEN_OPTS;
|
|
15
|
+
|
|
16
|
+
var LOG_ERRORS = process.env.LOG_ERRORS;
|
|
17
|
+
|
|
18
|
+
function baseChannelTest(client, server) {
|
|
19
|
+
return function(done) {
|
|
20
|
+
var bothDone = latch(2, done);
|
|
21
|
+
var pair = util.socketPair();
|
|
22
|
+
var c = new Connection(pair.client);
|
|
23
|
+
|
|
24
|
+
if (LOG_ERRORS) c.on('error', console.warn);
|
|
25
|
+
|
|
26
|
+
c.open(OPEN_OPTS, function(err, ok) {
|
|
27
|
+
if (err === null) client(c, bothDone);
|
|
28
|
+
else fail(bothDone);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
pair.server.read(8); // discard the protocol header
|
|
32
|
+
var s = util.runServer(pair.server, function(send, wait) {
|
|
33
|
+
conn_handshake(send, wait)
|
|
34
|
+
.then(function() {
|
|
35
|
+
server(send, wait, bothDone);
|
|
36
|
+
}, fail(bothDone));
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function channelTest(client, server) {
|
|
42
|
+
return baseChannelTest(
|
|
43
|
+
function(conn, done) {
|
|
44
|
+
var ch = new Channel(conn);
|
|
45
|
+
if (LOG_ERRORS) ch.on('error', console.warn);
|
|
46
|
+
client(ch, done, conn);
|
|
47
|
+
},
|
|
48
|
+
function(send, wait, done) {
|
|
49
|
+
channel_handshake(send, wait)
|
|
50
|
+
.then(function(ch) {
|
|
51
|
+
return server(send, wait, done, ch);
|
|
52
|
+
}).then(null, fail(done)); // so you can return a promise to let
|
|
53
|
+
// errors bubble out
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
function channel_handshake(send, wait) {
|
|
59
|
+
return wait(defs.ChannelOpen)()
|
|
60
|
+
.then(function(open) {
|
|
61
|
+
assert.notEqual(0, open.channel);
|
|
62
|
+
send(defs.ChannelOpenOk, {channelId: Buffer.from('')}, open.channel);
|
|
63
|
+
return open.channel;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// fields for deliver and publish and get-ok
|
|
68
|
+
var DELIVER_FIELDS = {
|
|
69
|
+
consumerTag: 'fake',
|
|
70
|
+
deliveryTag: 1,
|
|
71
|
+
redelivered: false,
|
|
72
|
+
exchange: 'foo',
|
|
73
|
+
routingKey: 'bar',
|
|
74
|
+
replyCode: defs.constants.NO_ROUTE,
|
|
75
|
+
replyText: 'derp',
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
function open(ch) {
|
|
79
|
+
ch.allocate();
|
|
80
|
+
return promisify(function(cb) {
|
|
81
|
+
ch._rpc(defs.ChannelOpen, {outOfBand: ''}, defs.ChannelOpenOk, cb);
|
|
82
|
+
})();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
suite("channel open and close", function() {
|
|
86
|
+
|
|
87
|
+
test("open", channelTest(
|
|
88
|
+
function(ch, done) {
|
|
89
|
+
open(ch).then(succeed(done), fail(done));
|
|
90
|
+
},
|
|
91
|
+
function(send, wait, done) {
|
|
92
|
+
done();
|
|
93
|
+
}));
|
|
94
|
+
|
|
95
|
+
test("bad server", baseChannelTest(
|
|
96
|
+
function(c, done) {
|
|
97
|
+
var ch = new Channel(c);
|
|
98
|
+
open(ch).then(fail(done), succeed(done));
|
|
99
|
+
},
|
|
100
|
+
function(send, wait, done) {
|
|
101
|
+
return wait(defs.ChannelOpen)()
|
|
102
|
+
.then(function(open) {
|
|
103
|
+
send(defs.ChannelCloseOk, {}, open.channel);
|
|
104
|
+
}).then(succeed(done), fail(done));
|
|
105
|
+
}));
|
|
106
|
+
|
|
107
|
+
test("open, close", channelTest(
|
|
108
|
+
function(ch, done) {
|
|
109
|
+
open(ch)
|
|
110
|
+
.then(function() {
|
|
111
|
+
return new Promise(function(resolve) {
|
|
112
|
+
ch.closeBecause("Bye", defs.constants.REPLY_SUCCESS, resolve);
|
|
113
|
+
});
|
|
114
|
+
})
|
|
115
|
+
.then(succeed(done), fail(done));
|
|
116
|
+
},
|
|
117
|
+
function(send, wait, done, ch) {
|
|
118
|
+
return wait(defs.ChannelClose)()
|
|
119
|
+
.then(function(close) {
|
|
120
|
+
send(defs.ChannelCloseOk, {}, ch);
|
|
121
|
+
}).then(succeed(done), fail(done));
|
|
122
|
+
}));
|
|
123
|
+
|
|
124
|
+
test("server close", channelTest(
|
|
125
|
+
function(ch, done) {
|
|
126
|
+
ch.on('error', function(error) {
|
|
127
|
+
assert.strictEqual(504, error.code);
|
|
128
|
+
assert.strictEqual(0, error.classId);
|
|
129
|
+
assert.strictEqual(0, error.methodId);
|
|
130
|
+
succeed(done)();
|
|
131
|
+
});
|
|
132
|
+
open(ch);
|
|
133
|
+
},
|
|
134
|
+
function(send, wait, done, ch) {
|
|
135
|
+
send(defs.ChannelClose, {
|
|
136
|
+
replyText: 'Forced close',
|
|
137
|
+
replyCode: defs.constants.CHANNEL_ERROR,
|
|
138
|
+
classId: 0, methodId: 0
|
|
139
|
+
}, ch);
|
|
140
|
+
wait(defs.ChannelCloseOk)()
|
|
141
|
+
.then(succeed(done), fail(done));
|
|
142
|
+
}));
|
|
143
|
+
|
|
144
|
+
test("overlapping channel/server close", channelTest(
|
|
145
|
+
function(ch, done, conn) {
|
|
146
|
+
var both = latch(2, done);
|
|
147
|
+
conn.on('error', succeed(both));
|
|
148
|
+
ch.on('close', succeed(both));
|
|
149
|
+
open(ch).then(function() {
|
|
150
|
+
ch.closeBecause("Bye", defs.constants.REPLY_SUCCESS);
|
|
151
|
+
}, fail(both));
|
|
152
|
+
},
|
|
153
|
+
function(send, wait, done, ch) {
|
|
154
|
+
wait(defs.ChannelClose)()
|
|
155
|
+
.then(function() {
|
|
156
|
+
send(defs.ConnectionClose, {
|
|
157
|
+
replyText: 'Got there first',
|
|
158
|
+
replyCode: defs.constants.INTERNAL_ERROR,
|
|
159
|
+
classId: 0, methodId: 0
|
|
160
|
+
}, 0);
|
|
161
|
+
})
|
|
162
|
+
.then(wait(defs.ConnectionCloseOk))
|
|
163
|
+
.then(succeed(done), fail(done));
|
|
164
|
+
}));
|
|
165
|
+
|
|
166
|
+
test("double close", channelTest(
|
|
167
|
+
function(ch, done) {
|
|
168
|
+
open(ch).then(function() {
|
|
169
|
+
ch.closeBecause("First close", defs.constants.REPLY_SUCCESS);
|
|
170
|
+
// NB no synchronisation, we do this straight away
|
|
171
|
+
assert.throws(function() {
|
|
172
|
+
ch.closeBecause("Second close", defs.constants.REPLY_SUCCESS);
|
|
173
|
+
});
|
|
174
|
+
}).then(succeed(done), fail(done));
|
|
175
|
+
},
|
|
176
|
+
function(send, wait, done, ch) {
|
|
177
|
+
wait(defs.ChannelClose)()
|
|
178
|
+
.then(function() {
|
|
179
|
+
send(defs.ChannelCloseOk, {
|
|
180
|
+
}, ch);
|
|
181
|
+
})
|
|
182
|
+
.then(succeed(done), fail(done));
|
|
183
|
+
}));
|
|
184
|
+
|
|
185
|
+
}); //suite
|
|
186
|
+
|
|
187
|
+
suite("channel machinery", function() {
|
|
188
|
+
|
|
189
|
+
test("RPC", channelTest(
|
|
190
|
+
function(ch, done) {
|
|
191
|
+
var rpcLatch = latch(3, done);
|
|
192
|
+
open(ch).then(function() {
|
|
193
|
+
|
|
194
|
+
function wheeboom(err, f) {
|
|
195
|
+
if (err !== null) rpcLatch(err);
|
|
196
|
+
else rpcLatch();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
var fields = {
|
|
200
|
+
prefetchCount: 10,
|
|
201
|
+
prefetchSize: 0,
|
|
202
|
+
global: false
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
ch._rpc(defs.BasicQos, fields, defs.BasicQosOk, wheeboom);
|
|
206
|
+
ch._rpc(defs.BasicQos, fields, defs.BasicQosOk, wheeboom);
|
|
207
|
+
ch._rpc(defs.BasicQos, fields, defs.BasicQosOk, wheeboom);
|
|
208
|
+
}).then(null, fail(rpcLatch));
|
|
209
|
+
},
|
|
210
|
+
function(send, wait, done, ch) {
|
|
211
|
+
function sendOk(f) {
|
|
212
|
+
send(defs.BasicQosOk, {}, ch);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return wait(defs.BasicQos)()
|
|
216
|
+
.then(sendOk)
|
|
217
|
+
.then(wait(defs.BasicQos))
|
|
218
|
+
.then(sendOk)
|
|
219
|
+
.then(wait(defs.BasicQos))
|
|
220
|
+
.then(sendOk)
|
|
221
|
+
.then(succeed(done), fail(done));
|
|
222
|
+
}));
|
|
223
|
+
|
|
224
|
+
test("Bad RPC", channelTest(
|
|
225
|
+
function(ch, done) {
|
|
226
|
+
// We want to see the RPC rejected and the channel closed (with an
|
|
227
|
+
// error)
|
|
228
|
+
var errLatch = latch(2, done);
|
|
229
|
+
ch.on('error', function(error) {
|
|
230
|
+
assert.strictEqual(505, error.code);
|
|
231
|
+
assert.strictEqual(60, error.classId);
|
|
232
|
+
assert.strictEqual(72, error.methodId);
|
|
233
|
+
succeed(errLatch)();
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
open(ch)
|
|
237
|
+
.then(function() {
|
|
238
|
+
ch._rpc(defs.BasicRecover, {requeue: true}, defs.BasicRecoverOk,
|
|
239
|
+
function(err) {
|
|
240
|
+
if (err !== null) errLatch();
|
|
241
|
+
else errLatch(new Error('Expected RPC failure'));
|
|
242
|
+
});
|
|
243
|
+
}, fail(errLatch));
|
|
244
|
+
},
|
|
245
|
+
function(send, wait, done, ch) {
|
|
246
|
+
return wait()()
|
|
247
|
+
.then(function() {
|
|
248
|
+
send(defs.BasicGetEmpty, {clusterId: ''}, ch);
|
|
249
|
+
}) // oh wait! that was wrong! expect a channel close
|
|
250
|
+
.then(wait(defs.ChannelClose))
|
|
251
|
+
.then(function() {
|
|
252
|
+
send(defs.ChannelCloseOk, {}, ch);
|
|
253
|
+
}).then(succeed(done), fail(done));
|
|
254
|
+
}));
|
|
255
|
+
|
|
256
|
+
test("RPC on closed channel", channelTest(
|
|
257
|
+
function(ch, done) {
|
|
258
|
+
open(ch);
|
|
259
|
+
|
|
260
|
+
var close = new Promise(function(resolve) {
|
|
261
|
+
ch.on('error', function(error) {
|
|
262
|
+
assert.strictEqual(504, error.code);
|
|
263
|
+
assert.strictEqual(0, error.classId);
|
|
264
|
+
assert.strictEqual(0, error.methodId);
|
|
265
|
+
resolve();
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
function failureCb(resolve, reject) {
|
|
270
|
+
return function(err) {
|
|
271
|
+
if (err !== null) resolve();
|
|
272
|
+
else reject();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
var fail1 = new Promise(function(resolve, reject) {
|
|
277
|
+
return ch._rpc(defs.BasicRecover, {requeue:true}, defs.BasicRecoverOk,
|
|
278
|
+
failureCb(resolve, reject));
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
var fail2 = new Promise(function(resolve, reject) {
|
|
282
|
+
return ch._rpc(defs.BasicRecover, {requeue:true}, defs.BasicRecoverOk,
|
|
283
|
+
failureCb(resolve, reject));
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
Promise.all([close, fail1, fail2])
|
|
287
|
+
.then(succeed(done))
|
|
288
|
+
.catch(fail(done));
|
|
289
|
+
},
|
|
290
|
+
function(send, wait, done, ch) {
|
|
291
|
+
wait(defs.BasicRecover)()
|
|
292
|
+
.then(function() {
|
|
293
|
+
send(defs.ChannelClose, {
|
|
294
|
+
replyText: 'Nuh-uh!',
|
|
295
|
+
replyCode: defs.constants.CHANNEL_ERROR,
|
|
296
|
+
methodId: 0, classId: 0
|
|
297
|
+
}, ch);
|
|
298
|
+
return wait(defs.ChannelCloseOk);
|
|
299
|
+
})
|
|
300
|
+
.then(succeed(done))
|
|
301
|
+
.catch(fail(done));
|
|
302
|
+
}));
|
|
303
|
+
|
|
304
|
+
test("publish all < single chunk threshold", channelTest(
|
|
305
|
+
function(ch, done) {
|
|
306
|
+
open(ch)
|
|
307
|
+
.then(function() {
|
|
308
|
+
ch.sendMessage({
|
|
309
|
+
exchange: 'foo', routingKey: 'bar',
|
|
310
|
+
mandatory: false, immediate: false, ticket: 0
|
|
311
|
+
}, {}, Buffer.from('foobar'));
|
|
312
|
+
})
|
|
313
|
+
.then(succeed(done), fail(done));
|
|
314
|
+
},
|
|
315
|
+
function(send, wait, done, ch) {
|
|
316
|
+
wait(defs.BasicPublish)()
|
|
317
|
+
.then(wait(defs.BasicProperties))
|
|
318
|
+
.then(wait(undefined)) // content frame
|
|
319
|
+
.then(function(f) {
|
|
320
|
+
assert.equal('foobar', f.content.toString());
|
|
321
|
+
}).then(succeed(done), fail(done));
|
|
322
|
+
}));
|
|
323
|
+
|
|
324
|
+
test("publish content > single chunk threshold", channelTest(
|
|
325
|
+
function(ch, done) {
|
|
326
|
+
open(ch);
|
|
327
|
+
completes(function() {
|
|
328
|
+
ch.sendMessage({
|
|
329
|
+
exchange: 'foo', routingKey: 'bar',
|
|
330
|
+
mandatory: false, immediate: false, ticket: 0
|
|
331
|
+
}, {}, Buffer.alloc(3000));
|
|
332
|
+
}, done);
|
|
333
|
+
},
|
|
334
|
+
function(send, wait, done, ch) {
|
|
335
|
+
wait(defs.BasicPublish)()
|
|
336
|
+
.then(wait(defs.BasicProperties))
|
|
337
|
+
.then(wait(undefined)) // content frame
|
|
338
|
+
.then(function(f) {
|
|
339
|
+
assert.equal(3000, f.content.length);
|
|
340
|
+
}).then(succeed(done), fail(done));
|
|
341
|
+
}));
|
|
342
|
+
|
|
343
|
+
test("publish method & headers > threshold", channelTest(
|
|
344
|
+
function(ch, done) {
|
|
345
|
+
open(ch);
|
|
346
|
+
completes(function() {
|
|
347
|
+
ch.sendMessage({
|
|
348
|
+
exchange: 'foo', routingKey: 'bar',
|
|
349
|
+
mandatory: false, immediate: false, ticket: 0
|
|
350
|
+
}, {
|
|
351
|
+
headers: {foo: Buffer.alloc(3000)}
|
|
352
|
+
}, Buffer.from('foobar'));
|
|
353
|
+
}, done);
|
|
354
|
+
},
|
|
355
|
+
function(send, wait, done, ch) {
|
|
356
|
+
wait(defs.BasicPublish)()
|
|
357
|
+
.then(wait(defs.BasicProperties))
|
|
358
|
+
.then(wait(undefined)) // content frame
|
|
359
|
+
.then(function(f) {
|
|
360
|
+
assert.equal('foobar', f.content.toString());
|
|
361
|
+
}).then(succeed(done), fail(done));
|
|
362
|
+
}));
|
|
363
|
+
|
|
364
|
+
test("publish zero-length message", channelTest(
|
|
365
|
+
function(ch, done) {
|
|
366
|
+
open(ch);
|
|
367
|
+
completes(function() {
|
|
368
|
+
ch.sendMessage({
|
|
369
|
+
exchange: 'foo', routingKey: 'bar',
|
|
370
|
+
mandatory: false, immediate: false, ticket: 0
|
|
371
|
+
}, {}, Buffer.alloc(0));
|
|
372
|
+
ch.sendMessage({
|
|
373
|
+
exchange: 'foo', routingKey: 'bar',
|
|
374
|
+
mandatory: false, immediate: false, ticket: 0
|
|
375
|
+
}, {}, Buffer.alloc(0));
|
|
376
|
+
}, done);
|
|
377
|
+
},
|
|
378
|
+
function(send, wait, done, ch) {
|
|
379
|
+
wait(defs.BasicPublish)()
|
|
380
|
+
.then(wait(defs.BasicProperties))
|
|
381
|
+
// no content frame for a zero-length message
|
|
382
|
+
.then(wait(defs.BasicPublish))
|
|
383
|
+
.then(succeed(done), fail(done));
|
|
384
|
+
}));
|
|
385
|
+
|
|
386
|
+
test("delivery", channelTest(
|
|
387
|
+
function(ch, done) {
|
|
388
|
+
open(ch);
|
|
389
|
+
ch.on('delivery', function(m) {
|
|
390
|
+
completes(function() {
|
|
391
|
+
assert.equal('barfoo', m.content.toString());
|
|
392
|
+
}, done);
|
|
393
|
+
});
|
|
394
|
+
},
|
|
395
|
+
function(send, wait, done, ch) {
|
|
396
|
+
completes(function() {
|
|
397
|
+
send(defs.BasicDeliver, DELIVER_FIELDS, ch, Buffer.from('barfoo'));
|
|
398
|
+
}, done);
|
|
399
|
+
}));
|
|
400
|
+
|
|
401
|
+
test("zero byte msg", channelTest(
|
|
402
|
+
function(ch, done) {
|
|
403
|
+
open(ch);
|
|
404
|
+
ch.on('delivery', function(m) {
|
|
405
|
+
completes(function() {
|
|
406
|
+
assert.deepEqual(Buffer.alloc(0), m.content);
|
|
407
|
+
}, done);
|
|
408
|
+
});
|
|
409
|
+
},
|
|
410
|
+
function(send, wait, done, ch) {
|
|
411
|
+
completes(function() {
|
|
412
|
+
send(defs.BasicDeliver, DELIVER_FIELDS, ch, Buffer.from(''));
|
|
413
|
+
}, done);
|
|
414
|
+
}));
|
|
415
|
+
|
|
416
|
+
test("bad delivery", channelTest(
|
|
417
|
+
function(ch, done) {
|
|
418
|
+
var errorAndClose = latch(2, done);
|
|
419
|
+
ch.on('error', function(error) {
|
|
420
|
+
assert.strictEqual(505, error.code);
|
|
421
|
+
assert.strictEqual(60, error.classId);
|
|
422
|
+
assert.strictEqual(60, error.methodId);
|
|
423
|
+
succeed(errorAndClose)();
|
|
424
|
+
});
|
|
425
|
+
ch.on('close', succeed(errorAndClose));
|
|
426
|
+
open(ch);
|
|
427
|
+
},
|
|
428
|
+
function(send, wait, done, ch) {
|
|
429
|
+
send(defs.BasicDeliver, DELIVER_FIELDS, ch);
|
|
430
|
+
// now send another deliver without having sent the content
|
|
431
|
+
send(defs.BasicDeliver, DELIVER_FIELDS, ch);
|
|
432
|
+
return wait(defs.ChannelClose)()
|
|
433
|
+
.then(function() {
|
|
434
|
+
send(defs.ChannelCloseOk, {}, ch);
|
|
435
|
+
}).then(succeed(done), fail(done));
|
|
436
|
+
}));
|
|
437
|
+
|
|
438
|
+
test("bad content send", channelTest(
|
|
439
|
+
function(ch, done) {
|
|
440
|
+
completes(function() {
|
|
441
|
+
open(ch);
|
|
442
|
+
assert.throws(function() {
|
|
443
|
+
ch.sendMessage({routingKey: 'foo',
|
|
444
|
+
exchange: 'amq.direct'},
|
|
445
|
+
{}, null);
|
|
446
|
+
});
|
|
447
|
+
}, done);
|
|
448
|
+
},
|
|
449
|
+
function(send, wait, done, ch) {
|
|
450
|
+
done();
|
|
451
|
+
}));
|
|
452
|
+
|
|
453
|
+
test("bad properties send", channelTest(
|
|
454
|
+
function(ch, done) {
|
|
455
|
+
completes(function() {
|
|
456
|
+
open(ch);
|
|
457
|
+
assert.throws(function() {
|
|
458
|
+
ch.sendMessage({routingKey: 'foo',
|
|
459
|
+
exchange: 'amq.direct'},
|
|
460
|
+
{contentEncoding: 7},
|
|
461
|
+
Buffer.from('foobar'));
|
|
462
|
+
});
|
|
463
|
+
}, done);
|
|
464
|
+
},
|
|
465
|
+
function(send, wait, done, ch) {
|
|
466
|
+
done();
|
|
467
|
+
}));
|
|
468
|
+
|
|
469
|
+
test("bad consumer", channelTest(
|
|
470
|
+
function(ch, done) {
|
|
471
|
+
var errorAndClose = latch(2, done);
|
|
472
|
+
ch.on('delivery', function() {
|
|
473
|
+
throw new Error("I am a bad consumer");
|
|
474
|
+
});
|
|
475
|
+
ch.on('error', function(error) {
|
|
476
|
+
assert.strictEqual(541, error.code);
|
|
477
|
+
assert.strictEqual(undefined, error.classId);
|
|
478
|
+
assert.strictEqual(undefined, error.methodId);
|
|
479
|
+
succeed(errorAndClose)();
|
|
480
|
+
});
|
|
481
|
+
ch.on('close', succeed(errorAndClose));
|
|
482
|
+
open(ch);
|
|
483
|
+
},
|
|
484
|
+
function(send, wait, done, ch) {
|
|
485
|
+
send(defs.BasicDeliver, DELIVER_FIELDS, ch, Buffer.from('barfoo'));
|
|
486
|
+
return wait(defs.ChannelClose)()
|
|
487
|
+
.then(function() {
|
|
488
|
+
send(defs.ChannelCloseOk, {}, ch);
|
|
489
|
+
}).then(succeed(done), fail(done));
|
|
490
|
+
}));
|
|
491
|
+
|
|
492
|
+
test("bad send in consumer", channelTest(
|
|
493
|
+
function(ch, done) {
|
|
494
|
+
var errorAndClose = latch(2, done);
|
|
495
|
+
ch.on('close', succeed(errorAndClose));
|
|
496
|
+
ch.on('error', function(error) {
|
|
497
|
+
assert.strictEqual(541, error.code);
|
|
498
|
+
assert.strictEqual(undefined, error.classId);
|
|
499
|
+
assert.strictEqual(undefined, error.methodId);
|
|
500
|
+
succeed(errorAndClose)();
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
ch.on('delivery', function() {
|
|
504
|
+
ch.sendMessage({routingKey: 'foo',
|
|
505
|
+
exchange: 'amq.direct'},
|
|
506
|
+
{}, null); // can't send null
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
open(ch);
|
|
510
|
+
},
|
|
511
|
+
function(send, wait, done, ch) {
|
|
512
|
+
completes(function() {
|
|
513
|
+
send(defs.BasicDeliver, DELIVER_FIELDS, ch,
|
|
514
|
+
Buffer.from('barfoo'));
|
|
515
|
+
}, done);
|
|
516
|
+
return wait(defs.ChannelClose)()
|
|
517
|
+
.then(function() {
|
|
518
|
+
send(defs.ChannelCloseOk, {}, ch);
|
|
519
|
+
}).then(succeed(done), fail(done));
|
|
520
|
+
}));
|
|
521
|
+
|
|
522
|
+
test("return", channelTest(
|
|
523
|
+
function(ch, done) {
|
|
524
|
+
ch.on('return', function(m) {
|
|
525
|
+
completes(function() {
|
|
526
|
+
assert.equal('barfoo', m.content.toString());
|
|
527
|
+
}, done);
|
|
528
|
+
});
|
|
529
|
+
open(ch);
|
|
530
|
+
},
|
|
531
|
+
function(send, wait, done, ch) {
|
|
532
|
+
completes(function() {
|
|
533
|
+
send(defs.BasicReturn, DELIVER_FIELDS, ch, Buffer.from('barfoo'));
|
|
534
|
+
}, done);
|
|
535
|
+
}));
|
|
536
|
+
|
|
537
|
+
test("cancel", channelTest(
|
|
538
|
+
function(ch, done) {
|
|
539
|
+
ch.on('cancel', function(f) {
|
|
540
|
+
completes(function() {
|
|
541
|
+
assert.equal('product of society', f.consumerTag);
|
|
542
|
+
}, done);
|
|
543
|
+
});
|
|
544
|
+
open(ch);
|
|
545
|
+
},
|
|
546
|
+
function(send, wait, done, ch) {
|
|
547
|
+
completes(function() {
|
|
548
|
+
send(defs.BasicCancel, {
|
|
549
|
+
consumerTag: 'product of society',
|
|
550
|
+
nowait: false
|
|
551
|
+
}, ch);
|
|
552
|
+
}, done);
|
|
553
|
+
}));
|
|
554
|
+
|
|
555
|
+
function confirmTest(variety, Method) {
|
|
556
|
+
return test('confirm ' + variety, channelTest(
|
|
557
|
+
function(ch, done) {
|
|
558
|
+
ch.on(variety, function(f) {
|
|
559
|
+
completes(function() {
|
|
560
|
+
assert.equal(1, f.deliveryTag);
|
|
561
|
+
}, done);
|
|
562
|
+
});
|
|
563
|
+
open(ch);
|
|
564
|
+
},
|
|
565
|
+
function(send, wait, done, ch) {
|
|
566
|
+
completes(function() {
|
|
567
|
+
send(Method, {
|
|
568
|
+
deliveryTag: 1,
|
|
569
|
+
multiple: false
|
|
570
|
+
}, ch);
|
|
571
|
+
}, done);
|
|
572
|
+
}));
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
confirmTest("ack", defs.BasicAck);
|
|
576
|
+
confirmTest("nack", defs.BasicNack);
|
|
577
|
+
|
|
578
|
+
test("out-of-order acks", channelTest(
|
|
579
|
+
function(ch, done) {
|
|
580
|
+
var allConfirms = latch(3, function() {
|
|
581
|
+
completes(function() {
|
|
582
|
+
assert.equal(0, ch.unconfirmed.length);
|
|
583
|
+
assert.equal(4, ch.lwm);
|
|
584
|
+
}, done);
|
|
585
|
+
});
|
|
586
|
+
ch.pushConfirmCallback(allConfirms);
|
|
587
|
+
ch.pushConfirmCallback(allConfirms);
|
|
588
|
+
ch.pushConfirmCallback(allConfirms);
|
|
589
|
+
open(ch);
|
|
590
|
+
},
|
|
591
|
+
function(send, wait, done, ch) {
|
|
592
|
+
completes(function() {
|
|
593
|
+
send(defs.BasicAck, {deliveryTag: 2, multiple: false}, ch);
|
|
594
|
+
send(defs.BasicAck, {deliveryTag: 3, multiple: false}, ch);
|
|
595
|
+
send(defs.BasicAck, {deliveryTag: 1, multiple: false}, ch);
|
|
596
|
+
}, done);
|
|
597
|
+
}));
|
|
598
|
+
|
|
599
|
+
test("not all out-of-order acks", channelTest(
|
|
600
|
+
function(ch, done) {
|
|
601
|
+
var allConfirms = latch(2, function() {
|
|
602
|
+
completes(function() {
|
|
603
|
+
assert.equal(1, ch.unconfirmed.length);
|
|
604
|
+
assert.equal(3, ch.lwm);
|
|
605
|
+
}, done);
|
|
606
|
+
});
|
|
607
|
+
ch.pushConfirmCallback(allConfirms); // tag = 1
|
|
608
|
+
ch.pushConfirmCallback(allConfirms); // tag = 2
|
|
609
|
+
ch.pushConfirmCallback(function() {
|
|
610
|
+
done(new Error('Confirm callback should not be called'));
|
|
611
|
+
});
|
|
612
|
+
open(ch);
|
|
613
|
+
},
|
|
614
|
+
function(send, wait, done, ch) {
|
|
615
|
+
completes(function() {
|
|
616
|
+
send(defs.BasicAck, {deliveryTag: 2, multiple: false}, ch);
|
|
617
|
+
send(defs.BasicAck, {deliveryTag: 1, multiple: false}, ch);
|
|
618
|
+
}, done);
|
|
619
|
+
}));
|
|
620
|
+
|
|
621
|
+
});
|