This repository has been archived by the owner on Apr 24, 2020. It is now read-only.
/
stress_buffer.js
110 lines (84 loc) · 2.28 KB
/
stress_buffer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var vows = require('vows'),
assert = require('assert'),
zeromq = require('zeromq');
var uri = 'inproc://unbalanced';
var sock1 = zeromq.createSocket("xreq");
sock1["identity"] = "Sock1";
var sock2 = zeromq.createSocket("xrep");
function sock1Message(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
{
assert.equal(arg2, "this");
assert.equal(arg3, "is");
assert.equal(arg4, "a");
assert.equal(arg5, "long");
assert.equal(arg6, "message");
assert.equal(arg7, "back");
assert.equal(arg8, "to");
assert.equal(arg9, "you");
//console.log("got message on sock1: ", arg1 ? arg1.toString() : "", arg2 ? arg2.toString() : "",
// arg3 ? arg3.toString() : "");
//sock1.send('message back');
}
function sock1Error(err)
{
console.log("error from sock1: ", err);
sock1.close();
sock2.close();
process.exit(1);
}
function sock2Message(arg1, arg2, arg3)
{
assert.equal(arg1.toString(), "Sock1");
assert.equal(arg2.toString(), "message");
//console.log("got message on sock2: ", arg1 ? arg1.toString() : "", arg2 ? arg2.toString() : "",
// arg3 ? arg3.toString() : "");
sock2.send(arg1, arg2, 'this', 'is', 'a', 'long', 'message', 'back', 'to', 'you');
//console.log("got message on sock2: ", arg1, arg2, arg3);
//sock2.send(arg1, 'hi', 'back');
}
function sock2Error(err)
{
console.log("error from sock2: ", err);
sock1.close();
sock2.close();
process.exit(1);
}
sock1.on('message', sock1Message);
sock1.on('error', sock1Error);
sock2.on('message', sock2Message);
sock2.on('error', sock2Error);
var msg = 0;
var intervalId;
function onTick()
{
for (var i = 0; i < 1000; ++i) {
sock1.send('message', "" + msg);
++msg;
}
console.log("done " + msg + " messages");
if (msg > 1000000) {
clearInterval(intervalId);
sock1.close();
sock2.close();
}
}
function onBindDone()
{
sock1.connect(uri);
//sock1.send('hello', 'world');
intervalId = setInterval(onTick, 1);
}
var doSync = true;
if (doSync) {
sock2.bindSync(uri);
onBindDone();
}
else {
sock2.bind(uri, onBindDone);
}
var suite = vows.describe('ZeroMQ');
suite.options.error = false;
var tests = {
};
suite.addBatch(tests);
suite.export(module);