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,390 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var assert = require('assert');
|
|
4
|
+
var defs = require('../lib/defs');
|
|
5
|
+
var Connection = require('../lib/connection').Connection;
|
|
6
|
+
var HEARTBEAT = require('../lib/frame').HEARTBEAT;
|
|
7
|
+
var HB_BUF = require('../lib/frame').HEARTBEAT_BUF;
|
|
8
|
+
var util = require('./util');
|
|
9
|
+
var succeed = util.succeed, fail = util.fail, latch = util.latch;
|
|
10
|
+
var completes = util.completes;
|
|
11
|
+
var kCallback = util.kCallback;
|
|
12
|
+
|
|
13
|
+
var LOG_ERRORS = process.env.LOG_ERRORS;
|
|
14
|
+
|
|
15
|
+
var OPEN_OPTS = {
|
|
16
|
+
// start-ok
|
|
17
|
+
'clientProperties': {},
|
|
18
|
+
'mechanism': 'PLAIN',
|
|
19
|
+
'response': Buffer.from(['', 'guest', 'guest'].join(String.fromCharCode(0))),
|
|
20
|
+
'locale': 'en_US',
|
|
21
|
+
|
|
22
|
+
// tune-ok
|
|
23
|
+
'channelMax': 0,
|
|
24
|
+
'frameMax': 0,
|
|
25
|
+
'heartbeat': 0,
|
|
26
|
+
|
|
27
|
+
// open
|
|
28
|
+
'virtualHost': '/',
|
|
29
|
+
'capabilities': '',
|
|
30
|
+
'insist': 0
|
|
31
|
+
};
|
|
32
|
+
module.exports.OPEN_OPTS = OPEN_OPTS;
|
|
33
|
+
|
|
34
|
+
function happy_open(send, wait) {
|
|
35
|
+
// kick it off
|
|
36
|
+
send(defs.ConnectionStart,
|
|
37
|
+
{versionMajor: 0,
|
|
38
|
+
versionMinor: 9,
|
|
39
|
+
serverProperties: {},
|
|
40
|
+
mechanisms: Buffer.from('PLAIN'),
|
|
41
|
+
locales: Buffer.from('en_US')});
|
|
42
|
+
return wait(defs.ConnectionStartOk)()
|
|
43
|
+
.then(function(f) {
|
|
44
|
+
send(defs.ConnectionTune,
|
|
45
|
+
{channelMax: 0,
|
|
46
|
+
heartbeat: 0,
|
|
47
|
+
frameMax: 0});
|
|
48
|
+
})
|
|
49
|
+
.then(wait(defs.ConnectionTuneOk))
|
|
50
|
+
.then(wait(defs.ConnectionOpen))
|
|
51
|
+
.then(function(f) {
|
|
52
|
+
send(defs.ConnectionOpenOk,
|
|
53
|
+
{knownHosts: ''});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
module.exports.connection_handshake = happy_open;
|
|
57
|
+
|
|
58
|
+
function connectionTest(client, server) {
|
|
59
|
+
return function(done) {
|
|
60
|
+
var bothDone = latch(2, done);
|
|
61
|
+
var pair = util.socketPair();
|
|
62
|
+
var c = new Connection(pair.client);
|
|
63
|
+
if (LOG_ERRORS) c.on('error', console.warn);
|
|
64
|
+
client(c, bothDone);
|
|
65
|
+
|
|
66
|
+
// NB only not a race here because the writes are synchronous
|
|
67
|
+
var protocolHeader = pair.server.read(8);
|
|
68
|
+
assert.deepEqual(Buffer.from("AMQP" + String.fromCharCode(0,0,9,1)),
|
|
69
|
+
protocolHeader);
|
|
70
|
+
|
|
71
|
+
var s = util.runServer(pair.server, function(send, wait) {
|
|
72
|
+
server(send, wait, bothDone, pair.server);
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
suite("Connection errors", function() {
|
|
78
|
+
|
|
79
|
+
test("socket close during open", function(done) {
|
|
80
|
+
// RabbitMQ itself will take at least 3 seconds to close the socket
|
|
81
|
+
// in the event of a handshake problem. Instead of using a live
|
|
82
|
+
// connection, I'm just going to pretend.
|
|
83
|
+
var pair = util.socketPair();
|
|
84
|
+
var conn = new Connection(pair.client);
|
|
85
|
+
pair.server.on('readable', function() {
|
|
86
|
+
pair.server.end();
|
|
87
|
+
});
|
|
88
|
+
conn.open({}, kCallback(fail(done), succeed(done)));
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test("bad frame during open", function(done) {
|
|
92
|
+
var ss = util.socketPair();
|
|
93
|
+
var conn = new (require('../lib/connection').Connection)(ss.client);
|
|
94
|
+
ss.server.on('readable', function() {
|
|
95
|
+
ss.server.write(Buffer.from([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]));
|
|
96
|
+
});
|
|
97
|
+
conn.open({}, kCallback(fail(done), succeed(done)));
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
suite("Connection open", function() {
|
|
103
|
+
|
|
104
|
+
test("happy", connectionTest(
|
|
105
|
+
function(c, done) {
|
|
106
|
+
c.open(OPEN_OPTS, kCallback(succeed(done), fail(done)));
|
|
107
|
+
},
|
|
108
|
+
function(send, wait, done) {
|
|
109
|
+
happy_open(send, wait).then(succeed(done), fail(done));
|
|
110
|
+
}));
|
|
111
|
+
|
|
112
|
+
test("wrong first frame", connectionTest(
|
|
113
|
+
function(c, done) {
|
|
114
|
+
c.open(OPEN_OPTS, kCallback(fail(done), succeed(done)));
|
|
115
|
+
},
|
|
116
|
+
function(send, wait, done) {
|
|
117
|
+
// bad server! bad! whatever were you thinking?
|
|
118
|
+
completes(function() {
|
|
119
|
+
send(defs.ConnectionTune,
|
|
120
|
+
{channelMax: 0,
|
|
121
|
+
heartbeat: 0,
|
|
122
|
+
frameMax: 0});
|
|
123
|
+
}, done);
|
|
124
|
+
}));
|
|
125
|
+
|
|
126
|
+
test("unexpected socket close", connectionTest(
|
|
127
|
+
function(c, done) {
|
|
128
|
+
c.open(OPEN_OPTS, kCallback(fail(done), succeed(done)));
|
|
129
|
+
},
|
|
130
|
+
function(send, wait, done, socket) {
|
|
131
|
+
send(defs.ConnectionStart,
|
|
132
|
+
{versionMajor: 0,
|
|
133
|
+
versionMinor: 9,
|
|
134
|
+
serverProperties: {},
|
|
135
|
+
mechanisms: Buffer.from('PLAIN'),
|
|
136
|
+
locales: Buffer.from('en_US')});
|
|
137
|
+
return wait(defs.ConnectionStartOk)()
|
|
138
|
+
.then(function() {
|
|
139
|
+
socket.end();
|
|
140
|
+
})
|
|
141
|
+
.then(succeed(done), fail(done));
|
|
142
|
+
}));
|
|
143
|
+
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
suite("Connection running", function() {
|
|
147
|
+
|
|
148
|
+
test("wrong frame on channel 0", connectionTest(
|
|
149
|
+
function(c, done) {
|
|
150
|
+
c.on('error', succeed(done));
|
|
151
|
+
c.open(OPEN_OPTS);
|
|
152
|
+
},
|
|
153
|
+
function(send, wait, done) {
|
|
154
|
+
happy_open(send, wait)
|
|
155
|
+
.then(function() {
|
|
156
|
+
// there's actually nothing that would plausibly be sent to a
|
|
157
|
+
// just opened connection, so this is violating more than one
|
|
158
|
+
// rule. Nonetheless.
|
|
159
|
+
send(defs.ChannelOpenOk, {channelId: Buffer.from('')}, 0);
|
|
160
|
+
})
|
|
161
|
+
.then(wait(defs.ConnectionClose))
|
|
162
|
+
.then(function(close) {
|
|
163
|
+
send(defs.ConnectionCloseOk, {}, 0);
|
|
164
|
+
}).then(succeed(done), fail(done));
|
|
165
|
+
}));
|
|
166
|
+
|
|
167
|
+
test("unopened channel", connectionTest(
|
|
168
|
+
function(c, done) {
|
|
169
|
+
c.on('error', succeed(done));
|
|
170
|
+
c.open(OPEN_OPTS);
|
|
171
|
+
},
|
|
172
|
+
function(send, wait, done) {
|
|
173
|
+
happy_open(send, wait)
|
|
174
|
+
.then(function() {
|
|
175
|
+
// there's actually nothing that would plausibly be sent to a
|
|
176
|
+
// just opened connection, so this is violating more than one
|
|
177
|
+
// rule. Nonetheless.
|
|
178
|
+
send(defs.ChannelOpenOk, {channelId: Buffer.from('')}, 3);
|
|
179
|
+
})
|
|
180
|
+
.then(wait(defs.ConnectionClose))
|
|
181
|
+
.then(function(close) {
|
|
182
|
+
send(defs.ConnectionCloseOk, {}, 0);
|
|
183
|
+
}).then(succeed(done), fail(done));
|
|
184
|
+
}));
|
|
185
|
+
|
|
186
|
+
test("unexpected socket close", connectionTest(
|
|
187
|
+
function(c, done) {
|
|
188
|
+
var errorAndClosed = latch(2, done);
|
|
189
|
+
c.on('error', succeed(errorAndClosed));
|
|
190
|
+
c.on('close', succeed(errorAndClosed));
|
|
191
|
+
c.open(OPEN_OPTS, kCallback(function() {
|
|
192
|
+
c.sendHeartbeat();
|
|
193
|
+
}, fail(errorAndClosed)));
|
|
194
|
+
},
|
|
195
|
+
function(send, wait, done, socket) {
|
|
196
|
+
happy_open(send, wait)
|
|
197
|
+
.then(wait())
|
|
198
|
+
.then(function() {
|
|
199
|
+
socket.end();
|
|
200
|
+
}).then(succeed(done));
|
|
201
|
+
}));
|
|
202
|
+
|
|
203
|
+
test("connection.blocked", connectionTest(
|
|
204
|
+
function(c, done) {
|
|
205
|
+
c.on('blocked', succeed(done));
|
|
206
|
+
c.open(OPEN_OPTS);
|
|
207
|
+
},
|
|
208
|
+
function(send, wait, done, socket) {
|
|
209
|
+
happy_open(send, wait)
|
|
210
|
+
.then(function() {
|
|
211
|
+
send(defs.ConnectionBlocked, {reason: 'felt like it'}, 0);
|
|
212
|
+
})
|
|
213
|
+
.then(succeed(done));
|
|
214
|
+
}));
|
|
215
|
+
|
|
216
|
+
test("connection.unblocked", connectionTest(
|
|
217
|
+
function(c, done) {
|
|
218
|
+
c.on('unblocked', succeed(done));
|
|
219
|
+
c.open(OPEN_OPTS);
|
|
220
|
+
},
|
|
221
|
+
function(send, wait, done, socket) {
|
|
222
|
+
happy_open(send, wait)
|
|
223
|
+
.then(function() {
|
|
224
|
+
send(defs.ConnectionUnblocked, {}, 0);
|
|
225
|
+
})
|
|
226
|
+
.then(succeed(done));
|
|
227
|
+
}));
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
suite("Connection close", function() {
|
|
233
|
+
|
|
234
|
+
test("happy", connectionTest(
|
|
235
|
+
function(c, done0) {
|
|
236
|
+
var done = latch(2, done0);
|
|
237
|
+
c.on('close', done);
|
|
238
|
+
c.open(OPEN_OPTS, kCallback(function(_ok) {
|
|
239
|
+
c.close(kCallback(succeed(done), fail(done)));
|
|
240
|
+
}, function() {}));
|
|
241
|
+
},
|
|
242
|
+
function(send, wait, done) {
|
|
243
|
+
happy_open(send, wait)
|
|
244
|
+
.then(wait(defs.ConnectionClose))
|
|
245
|
+
.then(function(close) {
|
|
246
|
+
send(defs.ConnectionCloseOk, {});
|
|
247
|
+
})
|
|
248
|
+
.then(succeed(done), fail(done));
|
|
249
|
+
}));
|
|
250
|
+
|
|
251
|
+
test("interleaved close frames", connectionTest(
|
|
252
|
+
function(c, done0) {
|
|
253
|
+
var done = latch(2, done0);
|
|
254
|
+
c.on('close', done);
|
|
255
|
+
c.open(OPEN_OPTS, kCallback(function(_ok) {
|
|
256
|
+
c.close(kCallback(succeed(done), fail(done)));
|
|
257
|
+
}, done));
|
|
258
|
+
},
|
|
259
|
+
function(send, wait, done) {
|
|
260
|
+
happy_open(send, wait)
|
|
261
|
+
.then(wait(defs.ConnectionClose))
|
|
262
|
+
.then(function(f) {
|
|
263
|
+
send(defs.ConnectionClose, {
|
|
264
|
+
replyText: "Ha!",
|
|
265
|
+
replyCode: defs.constants.REPLY_SUCCESS,
|
|
266
|
+
methodId: 0, classId: 0
|
|
267
|
+
});
|
|
268
|
+
})
|
|
269
|
+
.then(wait(defs.ConnectionCloseOk))
|
|
270
|
+
.then(function(f) {
|
|
271
|
+
send(defs.ConnectionCloseOk, {});
|
|
272
|
+
})
|
|
273
|
+
.then(succeed(done), fail(done));
|
|
274
|
+
}));
|
|
275
|
+
|
|
276
|
+
test("server error close", connectionTest(
|
|
277
|
+
function(c, done0) {
|
|
278
|
+
var done = latch(2, done0);
|
|
279
|
+
c.on('close', succeed(done));
|
|
280
|
+
c.on('error', succeed(done));
|
|
281
|
+
c.open(OPEN_OPTS);
|
|
282
|
+
},
|
|
283
|
+
function(send, wait, done) {
|
|
284
|
+
happy_open(send, wait)
|
|
285
|
+
.then(function(f) {
|
|
286
|
+
send(defs.ConnectionClose, {
|
|
287
|
+
replyText: "Begone",
|
|
288
|
+
replyCode: defs.constants.INTERNAL_ERROR,
|
|
289
|
+
methodId: 0, classId: 0
|
|
290
|
+
});
|
|
291
|
+
})
|
|
292
|
+
.then(wait(defs.ConnectionCloseOk))
|
|
293
|
+
.then(succeed(done), fail(done));
|
|
294
|
+
}));
|
|
295
|
+
|
|
296
|
+
test("operator-intiated close", connectionTest(
|
|
297
|
+
function(c, done) {
|
|
298
|
+
c.on('close', succeed(done));
|
|
299
|
+
c.on('error', fail(done));
|
|
300
|
+
c.open(OPEN_OPTS);
|
|
301
|
+
},
|
|
302
|
+
function(send, wait, done) {
|
|
303
|
+
happy_open(send, wait)
|
|
304
|
+
.then(function(f) {
|
|
305
|
+
send(defs.ConnectionClose, {
|
|
306
|
+
replyText: "Begone",
|
|
307
|
+
replyCode: defs.constants.CONNECTION_FORCED,
|
|
308
|
+
methodId: 0, classId: 0
|
|
309
|
+
});
|
|
310
|
+
})
|
|
311
|
+
.then(wait(defs.ConnectionCloseOk))
|
|
312
|
+
.then(succeed(done), fail(done));
|
|
313
|
+
}));
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
test("double close", connectionTest(
|
|
317
|
+
function(c, done) {
|
|
318
|
+
c.open(OPEN_OPTS, kCallback(function() {
|
|
319
|
+
c.close();
|
|
320
|
+
// NB no synchronisation, we do this straight away
|
|
321
|
+
assert.throws(function() {
|
|
322
|
+
c.close();
|
|
323
|
+
});
|
|
324
|
+
done();
|
|
325
|
+
}, done));
|
|
326
|
+
},
|
|
327
|
+
function(send, wait, done) {
|
|
328
|
+
happy_open(send, wait)
|
|
329
|
+
.then(wait(defs.ConnectionClose))
|
|
330
|
+
.then(function() {
|
|
331
|
+
send(defs.ConnectionCloseOk, {});
|
|
332
|
+
})
|
|
333
|
+
.then(succeed(done), fail(done));
|
|
334
|
+
}));
|
|
335
|
+
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
suite("heartbeats", function() {
|
|
339
|
+
|
|
340
|
+
var heartbeat = require('../lib/heartbeat');
|
|
341
|
+
|
|
342
|
+
setup(function() {
|
|
343
|
+
heartbeat.UNITS_TO_MS = 20;
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
teardown(function() {
|
|
347
|
+
heartbeat.UNITS_TO_MS = 1000;
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
test("send heartbeat after open", connectionTest(
|
|
351
|
+
function(c, done) {
|
|
352
|
+
completes(function() {
|
|
353
|
+
var opts = Object.create(OPEN_OPTS);
|
|
354
|
+
opts.heartbeat = 1;
|
|
355
|
+
// Don't leave the error waiting to happen for the next test, this
|
|
356
|
+
// confuses mocha awfully
|
|
357
|
+
c.on('error', function() {});
|
|
358
|
+
c.open(opts);
|
|
359
|
+
}, done);
|
|
360
|
+
},
|
|
361
|
+
function(send, wait, done, socket) {
|
|
362
|
+
var timer;
|
|
363
|
+
happy_open(send, wait)
|
|
364
|
+
.then(function() {
|
|
365
|
+
timer = setInterval(function() {
|
|
366
|
+
socket.write(HB_BUF);
|
|
367
|
+
}, heartbeat.UNITS_TO_MS);
|
|
368
|
+
})
|
|
369
|
+
.then(wait())
|
|
370
|
+
.then(function(hb) {
|
|
371
|
+
if (hb === HEARTBEAT) done();
|
|
372
|
+
else done("Next frame after silence not a heartbeat");
|
|
373
|
+
clearInterval(timer);
|
|
374
|
+
});
|
|
375
|
+
}));
|
|
376
|
+
|
|
377
|
+
test("detect lack of heartbeats", connectionTest(
|
|
378
|
+
function(c, done) {
|
|
379
|
+
var opts = Object.create(OPEN_OPTS);
|
|
380
|
+
opts.heartbeat = 1;
|
|
381
|
+
c.on('error', succeed(done));
|
|
382
|
+
c.open(opts);
|
|
383
|
+
},
|
|
384
|
+
function(send, wait, done, socket) {
|
|
385
|
+
happy_open(send, wait)
|
|
386
|
+
.then(succeed(done), fail(done));
|
|
387
|
+
// conspicuously not sending anything ...
|
|
388
|
+
}));
|
|
389
|
+
|
|
390
|
+
});
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
// Property-based testing representations of various things in AMQP
|
|
2
|
+
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
var C = require('claire');
|
|
6
|
+
var forAll = C.forAll;
|
|
7
|
+
var arb = C.data;
|
|
8
|
+
var transform = C.transform;
|
|
9
|
+
var repeat = C.repeat;
|
|
10
|
+
var label = C.label;
|
|
11
|
+
var sequence = C.sequence;
|
|
12
|
+
var asGenerator = C.asGenerator;
|
|
13
|
+
var sized = C.sized;
|
|
14
|
+
var recursive = C.recursive;
|
|
15
|
+
var choice = C.choice;
|
|
16
|
+
var Undefined = C.Undefined;
|
|
17
|
+
|
|
18
|
+
// Stub these out so we can use outside tests
|
|
19
|
+
// if (!suite) var suite = function() {}
|
|
20
|
+
// if (!test) var test = function() {}
|
|
21
|
+
|
|
22
|
+
// These aren't exported in claire/index. so I could have to reproduce
|
|
23
|
+
// them I guess.
|
|
24
|
+
function choose(a, b) {
|
|
25
|
+
return Math.random() * (b - a) + a;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function chooseInt(a, b) {
|
|
29
|
+
return Math.floor(choose(a, b));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function rangeInt(name, a, b) {
|
|
33
|
+
return label(name,
|
|
34
|
+
asGenerator(function(_) { return chooseInt(a, b); }));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function toFloat32(i) {
|
|
38
|
+
var b = Buffer.alloc(4);
|
|
39
|
+
b.writeFloatBE(i, 0);
|
|
40
|
+
return b.readFloatBE(0);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function floatChooser(maxExp) {
|
|
44
|
+
return function() {
|
|
45
|
+
var n = Number.NaN;
|
|
46
|
+
while (isNaN(n)) {
|
|
47
|
+
var mantissa = Math.random() * 2 - 1;
|
|
48
|
+
var exponent = chooseInt(0, maxExp);
|
|
49
|
+
n = Math.pow(mantissa, exponent);
|
|
50
|
+
}
|
|
51
|
+
return n;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function explicitType(t, underlying) {
|
|
56
|
+
return label(t, transform(function(n) {
|
|
57
|
+
return {'!': t, value: n};
|
|
58
|
+
}, underlying));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// FIXME null, byte array, others?
|
|
62
|
+
|
|
63
|
+
var Octet = rangeInt('octet', 0, 255);
|
|
64
|
+
var ShortStr = label('shortstr',
|
|
65
|
+
transform(function(s) {
|
|
66
|
+
return s.substr(0, 255);
|
|
67
|
+
}, arb.Str));
|
|
68
|
+
|
|
69
|
+
var LongStr = label('longstr',
|
|
70
|
+
transform(
|
|
71
|
+
function(bytes) { return Buffer.from(bytes); },
|
|
72
|
+
repeat(Octet)));
|
|
73
|
+
|
|
74
|
+
var UShort = rangeInt('short-uint', 0, 0xffff);
|
|
75
|
+
var ULong = rangeInt('long-uint', 0, 0xffffffff);
|
|
76
|
+
var ULongLong = rangeInt('longlong-uint', 0, 0xffffffffffffffff);
|
|
77
|
+
var Short = rangeInt('short-int', -0x8000, 0x7fff);
|
|
78
|
+
var Long = rangeInt('long-int', -0x80000000, 0x7fffffff);
|
|
79
|
+
var LongLong = rangeInt('longlong-int', -0x8000000000000000,
|
|
80
|
+
0x7fffffffffffffff);
|
|
81
|
+
var Bit = label('bit', arb.Bool);
|
|
82
|
+
var Double = label('double', asGenerator(floatChooser(308)));
|
|
83
|
+
var Float = label('float', transform(toFloat32, floatChooser(38)));
|
|
84
|
+
var Timestamp = label('timestamp', transform(
|
|
85
|
+
function(n) {
|
|
86
|
+
return {'!': 'timestamp', value: n};
|
|
87
|
+
}, ULongLong));
|
|
88
|
+
var Decimal = label('decimal', transform(
|
|
89
|
+
function(args) {
|
|
90
|
+
return {'!': 'decimal', value: {places: args[1], digits: args[0]}};
|
|
91
|
+
}, sequence(arb.UInt, Octet)));
|
|
92
|
+
|
|
93
|
+
// Signed 8 bit int
|
|
94
|
+
var Byte = rangeInt('byte', -128, 127);
|
|
95
|
+
|
|
96
|
+
// Explicitly typed values
|
|
97
|
+
var ExByte = explicitType('byte', Byte);
|
|
98
|
+
var ExInt8 = explicitType('int8', Byte);
|
|
99
|
+
var ExShort = explicitType('short', Short);
|
|
100
|
+
var ExInt16 = explicitType('int16', Short);
|
|
101
|
+
var ExInt = explicitType('int', Long);
|
|
102
|
+
var ExInt32 = explicitType('int32', Long);
|
|
103
|
+
var ExLong = explicitType('long', LongLong);
|
|
104
|
+
var ExInt64 = explicitType('int64', LongLong);
|
|
105
|
+
|
|
106
|
+
var FieldArray = label('field-array', recursive(function() {
|
|
107
|
+
return arb.Array(
|
|
108
|
+
arb.Null,
|
|
109
|
+
LongStr, ShortStr,
|
|
110
|
+
Octet, UShort, ULong, ULongLong,
|
|
111
|
+
Byte, Short, Long, LongLong,
|
|
112
|
+
ExByte, ExInt8, ExShort, ExInt16,
|
|
113
|
+
ExInt, ExInt32, ExLong, ExInt64,
|
|
114
|
+
Bit, Float, Double, FieldTable, FieldArray)
|
|
115
|
+
}));
|
|
116
|
+
|
|
117
|
+
var FieldTable = label('table', recursive(function() {
|
|
118
|
+
return sized(function() { return 5; },
|
|
119
|
+
arb.Object(
|
|
120
|
+
arb.Null,
|
|
121
|
+
LongStr, ShortStr, Octet,
|
|
122
|
+
UShort, ULong, ULongLong,
|
|
123
|
+
Byte, Short, Long, LongLong,
|
|
124
|
+
ExByte, ExInt8, ExShort, ExInt16,
|
|
125
|
+
ExInt, ExInt32, ExLong, ExInt64,
|
|
126
|
+
Bit, Float, Double, FieldArray, FieldTable))
|
|
127
|
+
}));
|
|
128
|
+
|
|
129
|
+
// Internal tests of our properties
|
|
130
|
+
var domainProps = [
|
|
131
|
+
[Octet, function(n) { return n >= 0 && n < 256; }],
|
|
132
|
+
[ShortStr, function(s) { return typeof s === 'string' && s.length < 256; }],
|
|
133
|
+
[LongStr, function(s) { return Buffer.isBuffer(s); }],
|
|
134
|
+
[UShort, function(n) { return n >= 0 && n <= 0xffff; }],
|
|
135
|
+
[ULong, function(n) { return n >= 0 && n <= 0xffffffff; }],
|
|
136
|
+
[ULongLong, function(n) {
|
|
137
|
+
return n >= 0 && n <= 0xffffffffffffffff; }],
|
|
138
|
+
[Short, function(n) { return n >= -0x8000 && n <= 0x8000; }],
|
|
139
|
+
[Long, function(n) { return n >= -0x80000000 && n < 0x80000000; }],
|
|
140
|
+
[LongLong, function(n) { return n >= -0x8000000000000000 && n < 0x8000000000000000; }],
|
|
141
|
+
[Bit, function(b) { return typeof b === 'boolean'; }],
|
|
142
|
+
[Double, function(f) { return !isNaN(f) && isFinite(f); }],
|
|
143
|
+
[Float, function(f) { return !isNaN(f) && isFinite(f) && (Math.log(Math.abs(f)) * Math.LOG10E) < 309; }],
|
|
144
|
+
[Decimal, function(d) {
|
|
145
|
+
return d['!'] === 'decimal' &&
|
|
146
|
+
d.value['places'] <= 255 &&
|
|
147
|
+
d.value['digits'] <= 0xffffffff;
|
|
148
|
+
}],
|
|
149
|
+
[Timestamp, function(t) { return t['!'] === 'timestamp'; }],
|
|
150
|
+
[FieldTable, function(t) { return typeof t === 'object'; }],
|
|
151
|
+
[FieldArray, function(a) { return Array.isArray(a); }]
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
suite("Domains", function() {
|
|
155
|
+
domainProps.forEach(function(p) {
|
|
156
|
+
test(p[0] + ' domain',
|
|
157
|
+
forAll(p[0]).satisfy(p[1]).asTest({times: 500}));
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
// For methods and properties (as opposed to field table values) it's
|
|
162
|
+
// easier just to accept and produce numbers for timestamps.
|
|
163
|
+
var ArgTimestamp = label('timestamp', ULongLong);
|
|
164
|
+
|
|
165
|
+
// These are the domains used in method arguments
|
|
166
|
+
var ARG_TYPES = {
|
|
167
|
+
'octet': Octet,
|
|
168
|
+
'shortstr': ShortStr,
|
|
169
|
+
'longstr': LongStr,
|
|
170
|
+
'short': UShort,
|
|
171
|
+
'long': ULong,
|
|
172
|
+
'longlong': ULongLong,
|
|
173
|
+
'bit': Bit,
|
|
174
|
+
'table': FieldTable,
|
|
175
|
+
'timestamp': ArgTimestamp
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
function argtype(thing) {
|
|
179
|
+
if (thing.default === undefined) {
|
|
180
|
+
return ARG_TYPES[thing.type];
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
return choice(ARG_TYPES[thing.type], Undefined);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function zipObject(vals, names) {
|
|
188
|
+
var obj = {};
|
|
189
|
+
vals.forEach(function(v, i) { obj[names[i]] = v; });
|
|
190
|
+
return obj;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function name(arg) { return arg.name; }
|
|
194
|
+
|
|
195
|
+
var defs = require('../lib/defs');
|
|
196
|
+
|
|
197
|
+
function method(info) {
|
|
198
|
+
var domain = sequence.apply(null, info.args.map(argtype));
|
|
199
|
+
var names = info.args.map(name);
|
|
200
|
+
return label(info.name, transform(function(fieldVals) {
|
|
201
|
+
return {id: info.id,
|
|
202
|
+
fields: zipObject(fieldVals, names)};
|
|
203
|
+
}, domain));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function properties(info) {
|
|
207
|
+
var types = info.args.map(argtype);
|
|
208
|
+
types.unshift(ULongLong); // size
|
|
209
|
+
var domain = sequence.apply(null, types);
|
|
210
|
+
var names = info.args.map(name);
|
|
211
|
+
return label(info.name, transform(function(fieldVals) {
|
|
212
|
+
return {id: info.id,
|
|
213
|
+
size: fieldVals[0],
|
|
214
|
+
fields: zipObject(fieldVals.slice(1), names)};
|
|
215
|
+
}, domain));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
var methods = [];
|
|
219
|
+
var propertieses = [];
|
|
220
|
+
|
|
221
|
+
for (var k in defs) {
|
|
222
|
+
if (k.substr(0, 10) === 'methodInfo') {
|
|
223
|
+
methods.push(method(defs[k]));
|
|
224
|
+
methods[defs[k].name] = method(defs[k]);
|
|
225
|
+
}
|
|
226
|
+
else if (k.substr(0, 14) === 'propertiesInfo') {
|
|
227
|
+
propertieses.push(properties(defs[k]));
|
|
228
|
+
propertieses[defs[k].name] = properties(defs[k]);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
module.exports = {
|
|
233
|
+
Octet: Octet,
|
|
234
|
+
ShortStr: ShortStr,
|
|
235
|
+
LongStr: LongStr,
|
|
236
|
+
UShort: UShort,
|
|
237
|
+
ULong: ULong,
|
|
238
|
+
ULongLong: ULongLong,
|
|
239
|
+
Short: Short,
|
|
240
|
+
Long: Long,
|
|
241
|
+
LongLong: LongLong,
|
|
242
|
+
Bit: Bit,
|
|
243
|
+
Double: Double,
|
|
244
|
+
Float: Float,
|
|
245
|
+
Timestamp: Timestamp,
|
|
246
|
+
Decimal: Decimal,
|
|
247
|
+
FieldArray: FieldArray,
|
|
248
|
+
FieldTable: FieldTable,
|
|
249
|
+
|
|
250
|
+
methods: methods,
|
|
251
|
+
properties: propertieses
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
module.exports.rangeInt = rangeInt;
|