typespeed 2.0.21 → 2.0.22

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 (219) hide show
  1. package/dist/core.decorator.js +1 -30
  2. package/dist/default/default-authentication.class.js +25 -0
  3. package/dist/default/express-server.class.js +11 -4
  4. package/dist/default/log-default.class.js +0 -6
  5. package/dist/factory/authentication-factory.class.js +11 -0
  6. package/dist/factory/log-factory.class.js +9 -0
  7. package/dist/route.decorator.js +92 -2
  8. package/dist/typespeed.d.ts +25 -3
  9. package/dist/typespeed.js +3 -1
  10. package/package.json +1 -1
  11. package/src/core.decorator.ts +1 -29
  12. package/src/default/default-authentication.class.ts +10 -0
  13. package/src/default/express-server.class.ts +12 -5
  14. package/src/default/log-default.class.ts +0 -10
  15. package/src/factory/authentication-factory.class.ts +9 -0
  16. package/src/factory/log-factory.class.ts +9 -2
  17. package/src/route.decorator.ts +91 -3
  18. package/src/typespeed.d.ts +25 -3
  19. package/src/typespeed.ts +1 -0
  20. package/test/node_modules/.package-lock.json +65 -101
  21. package/test/node_modules/@types/body-parser/LICENSE +21 -0
  22. package/test/node_modules/@types/body-parser/README.md +16 -0
  23. package/test/node_modules/@types/body-parser/index.d.ts +107 -0
  24. package/test/node_modules/@types/body-parser/package.json +58 -0
  25. package/test/node_modules/@types/connect/LICENSE +21 -0
  26. package/test/node_modules/@types/connect/README.md +16 -0
  27. package/test/node_modules/@types/connect/index.d.ts +93 -0
  28. package/test/node_modules/@types/connect/package.json +32 -0
  29. package/test/node_modules/@types/express/LICENSE +21 -0
  30. package/test/node_modules/@types/express/README.md +16 -0
  31. package/test/node_modules/@types/express/index.d.ts +136 -0
  32. package/test/node_modules/@types/express/package.json +45 -0
  33. package/test/node_modules/@types/express-serve-static-core/LICENSE +21 -0
  34. package/test/node_modules/@types/express-serve-static-core/README.md +16 -0
  35. package/test/node_modules/@types/express-serve-static-core/index.d.ts +1281 -0
  36. package/test/node_modules/@types/express-serve-static-core/package.json +55 -0
  37. package/test/node_modules/@types/mime/LICENSE +21 -0
  38. package/test/node_modules/@types/mime/Mime.d.ts +10 -0
  39. package/test/node_modules/@types/mime/README.md +16 -0
  40. package/test/node_modules/@types/mime/index.d.ts +35 -0
  41. package/test/node_modules/@types/mime/lite.d.ts +7 -0
  42. package/test/node_modules/@types/mime/package.json +29 -0
  43. package/test/node_modules/@types/qs/LICENSE +21 -0
  44. package/test/node_modules/@types/qs/README.md +16 -0
  45. package/test/node_modules/@types/qs/index.d.ts +62 -0
  46. package/test/node_modules/@types/qs/package.json +65 -0
  47. package/test/node_modules/@types/range-parser/LICENSE +21 -0
  48. package/test/node_modules/@types/range-parser/README.md +55 -0
  49. package/test/node_modules/@types/range-parser/index.d.ts +35 -0
  50. package/test/node_modules/@types/range-parser/package.json +25 -0
  51. package/test/node_modules/@types/send/LICENSE +21 -0
  52. package/test/node_modules/@types/send/README.md +16 -0
  53. package/test/node_modules/@types/send/index.d.ts +231 -0
  54. package/test/node_modules/@types/send/package.json +33 -0
  55. package/test/node_modules/@types/serve-static/LICENSE +21 -0
  56. package/test/node_modules/@types/serve-static/README.md +16 -0
  57. package/test/node_modules/@types/serve-static/index.d.ts +113 -0
  58. package/test/node_modules/@types/serve-static/package.json +38 -0
  59. package/test/src/config.json +5 -0
  60. package/test/src/custom-log.class.ts +6 -0
  61. package/test/src/jwt-authentication.class.ts +29 -0
  62. package/test/src/test-request.class.ts +36 -0
  63. package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-ci.yml +0 -17
  64. package/test/node_modules/@acuminous/bitsyntax/.github/workflows/node-js-publish.yml +0 -30
  65. package/test/node_modules/@acuminous/bitsyntax/LICENSE +0 -6
  66. package/test/node_modules/@acuminous/bitsyntax/LICENSE-MIT +0 -21
  67. package/test/node_modules/@acuminous/bitsyntax/Makefile +0 -15
  68. package/test/node_modules/@acuminous/bitsyntax/README.md +0 -308
  69. package/test/node_modules/@acuminous/bitsyntax/index.js +0 -10
  70. package/test/node_modules/@acuminous/bitsyntax/lib/compile.js +0 -303
  71. package/test/node_modules/@acuminous/bitsyntax/lib/constructor.js +0 -142
  72. package/test/node_modules/@acuminous/bitsyntax/lib/grammar.pegjs +0 -67
  73. package/test/node_modules/@acuminous/bitsyntax/lib/interp.js +0 -232
  74. package/test/node_modules/@acuminous/bitsyntax/lib/parse.js +0 -32
  75. package/test/node_modules/@acuminous/bitsyntax/lib/parser.js +0 -1173
  76. package/test/node_modules/@acuminous/bitsyntax/lib/pattern.js +0 -119
  77. package/test/node_modules/@acuminous/bitsyntax/package.json +0 -36
  78. package/test/node_modules/@acuminous/bitsyntax/test/consing.test.js +0 -50
  79. package/test/node_modules/@acuminous/bitsyntax/test/matching.test.js +0 -193
  80. package/test/node_modules/amqplib/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
  81. package/test/node_modules/amqplib/.github/workflows/test.yml +0 -38
  82. package/test/node_modules/amqplib/CHANGELOG.md +0 -430
  83. package/test/node_modules/amqplib/LICENSE +0 -6
  84. package/test/node_modules/amqplib/LICENSE-MIT +0 -21
  85. package/test/node_modules/amqplib/Makefile +0 -47
  86. package/test/node_modules/amqplib/README.md +0 -157
  87. package/test/node_modules/amqplib/bin/generate-defs.js +0 -722
  88. package/test/node_modules/amqplib/callback_api.js +0 -22
  89. package/test/node_modules/amqplib/channel_api.js +0 -16
  90. package/test/node_modules/amqplib/examples/headers.js +0 -42
  91. package/test/node_modules/amqplib/examples/receive_generator.js +0 -39
  92. package/test/node_modules/amqplib/examples/send_generators.js +0 -42
  93. package/test/node_modules/amqplib/examples/ssl.js +0 -64
  94. package/test/node_modules/amqplib/examples/tutorials/README.md +0 -93
  95. package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log.js +0 -28
  96. package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_direct.js +0 -30
  97. package/test/node_modules/amqplib/examples/tutorials/callback_api/emit_log_topic.js +0 -27
  98. package/test/node_modules/amqplib/examples/tutorials/callback_api/new_task.js +0 -27
  99. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive.js +0 -30
  100. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs.js +0 -36
  101. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_direct.js +0 -56
  102. package/test/node_modules/amqplib/examples/tutorials/callback_api/receive_logs_topic.js +0 -55
  103. package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_client.js +0 -49
  104. package/test/node_modules/amqplib/examples/tutorials/callback_api/rpc_server.js +0 -45
  105. package/test/node_modules/amqplib/examples/tutorials/callback_api/send.js +0 -29
  106. package/test/node_modules/amqplib/examples/tutorials/callback_api/worker.js +0 -35
  107. package/test/node_modules/amqplib/examples/tutorials/emit_log.js +0 -19
  108. package/test/node_modules/amqplib/examples/tutorials/emit_log_direct.js +0 -20
  109. package/test/node_modules/amqplib/examples/tutorials/emit_log_topic.js +0 -19
  110. package/test/node_modules/amqplib/examples/tutorials/new_task.js +0 -18
  111. package/test/node_modules/amqplib/examples/tutorials/package.json +0 -16
  112. package/test/node_modules/amqplib/examples/tutorials/receive.js +0 -21
  113. package/test/node_modules/amqplib/examples/tutorials/receive_logs.js +0 -28
  114. package/test/node_modules/amqplib/examples/tutorials/receive_logs_direct.js +0 -44
  115. package/test/node_modules/amqplib/examples/tutorials/receive_logs_topic.js +0 -43
  116. package/test/node_modules/amqplib/examples/tutorials/rpc_client.js +0 -52
  117. package/test/node_modules/amqplib/examples/tutorials/rpc_server.js +0 -39
  118. package/test/node_modules/amqplib/examples/tutorials/send.js +0 -23
  119. package/test/node_modules/amqplib/examples/tutorials/worker.js +0 -28
  120. package/test/node_modules/amqplib/examples/waitForConfirms.js +0 -22
  121. package/test/node_modules/amqplib/lib/api_args.js +0 -314
  122. package/test/node_modules/amqplib/lib/bitset.js +0 -130
  123. package/test/node_modules/amqplib/lib/callback_model.js +0 -327
  124. package/test/node_modules/amqplib/lib/channel.js +0 -499
  125. package/test/node_modules/amqplib/lib/channel_model.js +0 -302
  126. package/test/node_modules/amqplib/lib/codec.js +0 -321
  127. package/test/node_modules/amqplib/lib/connect.js +0 -189
  128. package/test/node_modules/amqplib/lib/connection.js +0 -663
  129. package/test/node_modules/amqplib/lib/credentials.js +0 -42
  130. package/test/node_modules/amqplib/lib/defs.js +0 -4966
  131. package/test/node_modules/amqplib/lib/error.js +0 -24
  132. package/test/node_modules/amqplib/lib/format.js +0 -40
  133. package/test/node_modules/amqplib/lib/frame.js +0 -113
  134. package/test/node_modules/amqplib/lib/heartbeat.js +0 -89
  135. package/test/node_modules/amqplib/lib/mux.js +0 -129
  136. package/test/node_modules/amqplib/package.json +0 -37
  137. package/test/node_modules/amqplib/test/bitset.js +0 -69
  138. package/test/node_modules/amqplib/test/callback_api.js +0 -312
  139. package/test/node_modules/amqplib/test/channel.js +0 -621
  140. package/test/node_modules/amqplib/test/channel_api.js +0 -596
  141. package/test/node_modules/amqplib/test/codec.js +0 -237
  142. package/test/node_modules/amqplib/test/connect.js +0 -197
  143. package/test/node_modules/amqplib/test/connection.js +0 -390
  144. package/test/node_modules/amqplib/test/data.js +0 -254
  145. package/test/node_modules/amqplib/test/frame.js +0 -198
  146. package/test/node_modules/amqplib/test/mux.js +0 -204
  147. package/test/node_modules/amqplib/test/util.js +0 -219
  148. package/test/node_modules/buffer-more-ints/.travis.yml +0 -6
  149. package/test/node_modules/buffer-more-ints/LICENSE +0 -19
  150. package/test/node_modules/buffer-more-ints/README.md +0 -69
  151. package/test/node_modules/buffer-more-ints/buffer-more-ints-tests.js +0 -183
  152. package/test/node_modules/buffer-more-ints/buffer-more-ints.js +0 -432
  153. package/test/node_modules/buffer-more-ints/package.json +0 -19
  154. package/test/node_modules/buffer-more-ints/polyfill.js +0 -71
  155. package/test/node_modules/core-util-is/LICENSE +0 -19
  156. package/test/node_modules/core-util-is/README.md +0 -3
  157. package/test/node_modules/core-util-is/lib/util.js +0 -107
  158. package/test/node_modules/core-util-is/package.json +0 -38
  159. package/test/node_modules/debug/LICENSE +0 -20
  160. package/test/node_modules/debug/README.md +0 -481
  161. package/test/node_modules/debug/package.json +0 -59
  162. package/test/node_modules/debug/src/browser.js +0 -269
  163. package/test/node_modules/debug/src/common.js +0 -274
  164. package/test/node_modules/debug/src/index.js +0 -10
  165. package/test/node_modules/debug/src/node.js +0 -263
  166. package/test/node_modules/inherits/LICENSE +0 -16
  167. package/test/node_modules/inherits/README.md +0 -42
  168. package/test/node_modules/inherits/inherits.js +0 -9
  169. package/test/node_modules/inherits/inherits_browser.js +0 -27
  170. package/test/node_modules/inherits/package.json +0 -29
  171. package/test/node_modules/isarray/README.md +0 -54
  172. package/test/node_modules/isarray/build/build.js +0 -209
  173. package/test/node_modules/isarray/component.json +0 -19
  174. package/test/node_modules/isarray/index.js +0 -3
  175. package/test/node_modules/isarray/package.json +0 -25
  176. package/test/node_modules/ms/index.js +0 -162
  177. package/test/node_modules/ms/license.md +0 -21
  178. package/test/node_modules/ms/package.json +0 -37
  179. package/test/node_modules/ms/readme.md +0 -60
  180. package/test/node_modules/querystringify/LICENSE +0 -22
  181. package/test/node_modules/querystringify/README.md +0 -61
  182. package/test/node_modules/querystringify/index.js +0 -118
  183. package/test/node_modules/querystringify/package.json +0 -38
  184. package/test/node_modules/readable-stream/LICENSE +0 -18
  185. package/test/node_modules/readable-stream/README.md +0 -15
  186. package/test/node_modules/readable-stream/duplex.js +0 -1
  187. package/test/node_modules/readable-stream/float.patch +0 -923
  188. package/test/node_modules/readable-stream/lib/_stream_duplex.js +0 -89
  189. package/test/node_modules/readable-stream/lib/_stream_passthrough.js +0 -46
  190. package/test/node_modules/readable-stream/lib/_stream_readable.js +0 -951
  191. package/test/node_modules/readable-stream/lib/_stream_transform.js +0 -209
  192. package/test/node_modules/readable-stream/lib/_stream_writable.js +0 -477
  193. package/test/node_modules/readable-stream/package.json +0 -32
  194. package/test/node_modules/readable-stream/passthrough.js +0 -1
  195. package/test/node_modules/readable-stream/readable.js +0 -10
  196. package/test/node_modules/readable-stream/transform.js +0 -1
  197. package/test/node_modules/readable-stream/writable.js +0 -1
  198. package/test/node_modules/requires-port/.travis.yml +0 -19
  199. package/test/node_modules/requires-port/LICENSE +0 -22
  200. package/test/node_modules/requires-port/README.md +0 -47
  201. package/test/node_modules/requires-port/index.js +0 -38
  202. package/test/node_modules/requires-port/package.json +0 -47
  203. package/test/node_modules/requires-port/test.js +0 -98
  204. package/test/node_modules/safe-buffer/LICENSE +0 -21
  205. package/test/node_modules/safe-buffer/README.md +0 -584
  206. package/test/node_modules/safe-buffer/index.d.ts +0 -187
  207. package/test/node_modules/safe-buffer/index.js +0 -62
  208. package/test/node_modules/safe-buffer/package.json +0 -37
  209. package/test/node_modules/string_decoder/LICENSE +0 -20
  210. package/test/node_modules/string_decoder/README.md +0 -7
  211. package/test/node_modules/string_decoder/index.js +0 -221
  212. package/test/node_modules/string_decoder/package.json +0 -25
  213. package/test/node_modules/url-parse/LICENSE +0 -22
  214. package/test/node_modules/url-parse/README.md +0 -153
  215. package/test/node_modules/url-parse/dist/url-parse.js +0 -755
  216. package/test/node_modules/url-parse/dist/url-parse.min.js +0 -1
  217. package/test/node_modules/url-parse/dist/url-parse.min.js.map +0 -1
  218. package/test/node_modules/url-parse/index.js +0 -589
  219. package/test/node_modules/url-parse/package.json +0 -49
@@ -1,621 +0,0 @@
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
- });