Skip to content

Commit 9f70d2c

Browse files
committed
changed executeCommands to return array to force ordering
1 parent b5dcade commit 9f70d2c

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

processProxy.js

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,8 @@ ProcessProxy.prototype.executeCommand = function(command) {
461461

462462
.then(function(cmdResults) {
463463

464-
for (var cmd in cmdResults) {
465-
fulfill(cmdResults[cmd]);
466-
}
464+
fulfill(cmdResults[0]);
465+
467466

468467
}).catch(function(error) {
469468
reject(error);
@@ -475,14 +474,16 @@ ProcessProxy.prototype.executeCommand = function(command) {
475474

476475
/**
477476
* executeCommands - takes an array of raw command strings and returns promise
478-
* to be fulfilled with a a hash
479-
* of "command" -> {command:cmd, stdout:xxxx, stderr:xxxxx}
477+
* to be fulfilled with a an array of
478+
* of [
479+
* {command:cmd1, stdout:xxxx, stderr:xxxxx},
480+
* {command:cmd2, stdout:xxxx, stderr:xxxxx}
481+
* ]
480482
*
481483
* @commands Array of raw command/shell statements to be executed
482484
*
483485
* @return Promise, on fulfill returns promise to be fulfilled with a
484-
* hash of commands -> {stdout:xxxx, stderr:xxxxx}
485-
* on reject returns an exception
486+
* array of command results as described above
486487
*
487488
**/
488489
ProcessProxy.prototype.executeCommands = function(commands) {
@@ -493,7 +494,7 @@ ProcessProxy.prototype.executeCommands = function(commands) {
493494

494495
try {
495496

496-
var cmdResults = new Object();
497+
var cmdResults = [];
497498

498499
for (var i = 0; i < commands.length; i++) {
499500

@@ -505,13 +506,13 @@ ProcessProxy.prototype.executeCommands = function(commands) {
505506
new Command(command,
506507
function(cmd, stdout, stderr) {
507508

508-
cmdResults[cmd] = {
509-
'command': cmd,
510-
'stdout': stdout,
511-
'stderr': stderr
512-
};
509+
cmdResults.push({
510+
'command': cmd,
511+
'stdout': stdout,
512+
'stderr': stderr
513+
});
513514

514-
if (Object.keys(cmdResults).length == commands.length) {
515+
if (cmdResults.length == commands.length) {
515516
fulfill(cmdResults);
516517
}
517518

statefulProcessCommandProxy.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ function StatefulProcessCommandProxy(config) {
133133
delete self._pid2processMap[processProxy.getPid()];
134134

135135
if (cmdResults) {
136-
for (var cmd in cmdResults) {
137-
var cmdResult = cmdResults[cmd];
136+
for (var i=0; i<cmdResults.length; i++) {
137+
var cmdResult = cmdResults[i];
138138
self._log('info',"process preDestroyCmd[" +
139139
cmdResult.command + "] out:" + cmdResult.stdout +
140140
" err:" + cmdResult.stderr);
@@ -280,14 +280,17 @@ StatefulProcessCommandProxy.prototype.executeCommand = function(command) {
280280

281281
/**
282282
* executeCommand - takes an array of raw command strings and returns promise
283-
* to be fulfilled with a a hash
284-
* of "command" -> {command:cmd, stdout:xxxx, stderr:xxxxx}
283+
* to be fulfilled with an array of cmdResults
284+
* [
285+
* {command:cmd1, stdout:xxxx, stderr:xxxxx},
286+
* {command:cmd2, stdout:xxxx, stderr:xxxxx}
287+
* ]
288+
*
285289
*
286290
* @commands Array of raw command/shell statements to be executed
287291
*
288292
* @return Promise, on fulfill returns promise to be fulfilled with a
289-
* hash of commands -> {stdout:xxxx, stderr:xxxxx}
290-
* on reject returns an exception
293+
* array of cmdResults
291294
*
292295
**/
293296
StatefulProcessCommandProxy.prototype.executeCommands = function(commands) {

test/all.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('test stateful-process-command-proxy', function() {
7171
max: 1,
7272
min: 1,
7373
idleTimeoutMillis: 10000,
74-
74+
7575
logFunction: function(severity,origin,msg) {
7676
console.log(severity.toUpperCase() + " " +origin+" "+ msg);
7777
},
@@ -116,10 +116,10 @@ describe('test stateful-process-command-proxy', function() {
116116
// assert all commands, lookup the command
117117
// via the result, to get its asserter
118118
// then invoke the asserter passing the cmd result
119-
for (var key in cmdResults) {
120-
var command = cmdResults[key].command;
119+
for (var i=0; i<cmdResults.length; i++) {
120+
var command = cmdResults[i].command;
121121
var asserter = config.testCommands[command];
122-
asserter(cmdResults[key]);
122+
asserter(cmdResults[i]);
123123
}
124124

125125
// collect status

0 commit comments

Comments
 (0)