Skip to content

Commit 09f0375

Browse files
committed
Fix duration mode and connector client
1 parent deb1208 commit 09f0375

File tree

4 files changed

+32
-16
lines changed

4 files changed

+32
-16
lines changed

lib/connectorClient.js

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const Options = require('./optionsParser.js').ConnectorOptions;
2626
class Connector extends CoreClient {
2727
constructor() {
2828
super();
29+
this.stop = false;
2930
this.containers = [];
3031
this.connections = [];
3132
this.senders = [];
@@ -40,6 +41,20 @@ class Connector extends CoreClient {
4041
};
4142
}
4243

44+
sendMessage(context, self) {
45+
self.results.sent++;
46+
47+
context.sender.send({body: 'test message ' + self.sent});
48+
49+
if (self.options.timeout > 0) {
50+
self.resetTimeout(context, false);
51+
}
52+
53+
if (self.options.infinitySend && !self.stop) {
54+
setTimeout(self.sendMessage, 1000, context, self);
55+
}
56+
}
57+
4358
/**
4459
* Close all connection, sessions, senders and receiver
4560
* @method CloseObjects
@@ -107,25 +122,17 @@ class Connector extends CoreClient {
107122
self.results.receivers.open += 1;
108123
});
109124

110-
this.containers[i].on('sender_open', function() {
125+
this.containers[i].on('sender_open', function(context) {
111126
self.results.senders.open += 1;
127+
if (self.options.objCtrl && self.options.objCtrl.indexOf('S') && self.options.senderCount > 0) {
128+
self.sendMessage(context, self);
129+
}
112130
});
113131

114-
if (this.options.objCtrl && this.options.objCtrl.indexOf('S') && this.options.senderCount > 0) {
115-
this.containers[i].on('sendable', function(context) {
116-
const count = 1;
117-
let sent = 0;
118-
while(sent < count && context.sender.sendable()) {
119-
context.sender.send({body: 'test message ' + sent});
120-
sent++;
121-
self.results.sent++;
122-
}
123-
});
124-
}
125-
126132
if (this.options.objCtrl && this.options.objCtrl.indexOf('R') && this.options.receiverCount > 0) {
127-
this.containers[i].on('message', function() {
133+
this.containers[i].on('message', function(context) {
128134
self.results.received++;
135+
context.delivery.accept();
129136
});
130137
}
131138

@@ -176,6 +183,7 @@ class Connector extends CoreClient {
176183

177184
//set timeout for end connections
178185
setTimeout(function(connector) {
186+
connector.stop = true;
179187
connector.closeObjects(connector);
180188
connector.printOutput();
181189
}, this.options.timeout,

lib/optionsParser.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ class ConnectorOptions extends BasicOptions {
383383
this.objCtrl;
384384
this.senderCount;
385385
this.receiverCount;
386+
this.infinitySend;
386387
}
387388

388389
/**
@@ -397,13 +398,15 @@ class ConnectorOptions extends BasicOptions {
397398
'obj-ctrl': { default: 'C', describe: 'Optional creation object control based on <object-ids>, syntax C/E/S/R stands for Connection, sEssion, Sender, Receiver'},
398399
'sender-count': { default: 1, describe: 'count of senders', type: 'uint'},
399400
'receiver-count': { default: 1, describe: 'count of receivers', type: 'uint'},
401+
'infinity-send': { default: true, describe: 'set infinite send loop until kill or timeout', type: 'boolean'},
400402
});
401403
const args = this.parse(argsProcessor, listArgs);
402404
this.parseBasic(listArgs);
403405

404406
this.objCtrl = args['obj-ctrl'];
405407
this.senderCount = args['sender-count'];
406408
this.receiverCount = args['receiver-count'];
409+
this.infinitySend = args['infinity-send'];
407410
}
408411
}
409412

lib/senderClient.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ class Sender extends CoreClient {
184184
const self = this;
185185
//send messages
186186
this.container.on('sendable', function (context) {
187-
self._sendMessage(context);
187+
if (self.options.duration === 0) {
188+
self._sendMessage(context);
189+
}
188190
});
189191

190192
//on accept message
@@ -206,6 +208,9 @@ class Sender extends CoreClient {
206208

207209
//event raised when sender is opening
208210
this.container.on('sender_open', function (context) {
211+
if (self.options.duration > 0) {
212+
self._sendMessage(context);
213+
}
209214
if (self.options.timeout > 0) {
210215
self.timeoutClose(context, self.options.timeout);
211216
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"cli-rhea-connector": "bin/connector-client.js"
1919
},
2020
"dependencies": {
21-
"rhea": "^1.0.10",
21+
"rhea": "^1.0.19",
2222
"string-format-js": "",
2323
"ws": "^5.0.0",
2424
"yargs": "7.1.0"

0 commit comments

Comments
 (0)