Skip to content
Browse files

Improve run to use all UAs regardless of onlineClients.

Fixes #31.
  • Loading branch information...
1 parent 010ae47 commit 2fbcc6b3a82b352af3f5f96fbb72fdb5740f4a73 @Krinkle Krinkle committed
Showing with 20 additions and 14 deletions.
  1. +12 −4 README.md
  2. +8 −10 src/testswarm-browserstack.js
View
16 README.md
@@ -5,12 +5,20 @@ This script is currently compatible with:
* [TestSwarm](https://github.com/jquery/testswarm) 1.0.0-alpha or higher
* [BrowserStack API](https://github.com/browserstack/api) v1
+## Install
+--------------------------------------
+```bash
+git clone https://github.com/clarkbox/testswarm-browserstack.git testswarm-browserstack
+cd testswarm-browserstack/
+npm install
+```
+
## How to use CLI:
--------------------------------------
-<pre>
+```bash
node src/cli.js --run
-</pre>
+```
This above command will create and terminate BrowserStack workers as needed according to the information the TestSwarm `swarmstate` API provides. This command should be executed on a regular interval, either via a scheduler (such as crontab) or by letting node do a continuous loop (using the `--run-loop` option). Be sure to do start it from a scheduler still in a way that it will only start it if it isn't running anymore (in case of an exception).
@@ -20,8 +28,8 @@ If you plan to run it from a scheduler and keep log files, you're recommended to
## Main scripts:
--------------------------------------
-1. [testswarm-browserstack.js](https://github.com/Krinkle/testswarm-browserstack/blob/master/src/testswarm-browserstack.js) - Abstraction of TestSwarm API, and Scott González's BrowserStack API. Use it to automatically spawn BrowserStack workers based on your swarm's needs.
-1. [cli.js](https://github.com/Krinkle/testswarm-browserstack/blob/master/src/cli.js) - nodejs cli wrapper around it all. Allows for scripted or generally easy manual invocation of the script.
+1. [testswarm-browserstack.js](https://github.com/clarkbox/testswarm-browserstack/blob/master/src/testswarm-browserstack.js) - Abstraction of TestSwarm API, and Scott González's BrowserStack API. Use it to automatically spawn BrowserStack workers based on your swarm's needs.
+1. [cli.js](https://github.com/clarkbox/testswarm-browserstack/blob/master/src/cli.js) - nodejs cli wrapper around it all. Allows for scripted or generally easy manual invocation of the script.
## testswarm-browserstack.js
View
18 src/testswarm-browserstack.js
@@ -341,7 +341,7 @@ self = {
}
// Task 2: Start workers for browsers with pending tests but 0 online clients
- // and 0 workers (this last bit is important as we don't want to spawncr another
+ // and 0 workers (this last bit is important as we don't want to spawn another
// worker here if there is one queued but not in the swarm yet).
// Note: This is the only case where we ignore the total limit to use the 'queue'
// system of browserstack to start all browsers that are needed without question.
@@ -388,18 +388,16 @@ self = {
for (ua in percSwarmStats) {
stats = percSwarmStats[ua];
if (workersByUa[ua] >= config.browserstack.eqLimit) {
- // We've reached the number of max for this ua.
- priority = 0;
- } else if (stats.onlineClients === 0) {
- // We already dealt with this category. If it is still 0,
- // it means we can't help this one (see Task 1).
- // Also, x/0 is NaN or Infinity in javascript, which we don't want.
+ // We've reached the max for this ua.
priority = 0;
} else {
// This is the priority formula.
- // The more runs and the less clients, the higher the priority.
- // No runs? Priority becomes 0 (0/anything=0).
- priority = stats.pendingRuns / stats.onlineClients;
+ // Principle: The more pending runs and the less online clients, the higher the priority.
+ // No pending runs? Priority becomes 0 (0 / anything = 0).
+ // Note: Don't filter for where onlineClients is 0 (though task 2 already covers those,
+ // and `anything / 0 = NaN`, it only does one, we have eqLimit still).
+ // Fixed by doing +1 on onlineClients (see also clarkbox/testswarm-browserstack#31).
+ priority = stats.pendingRuns / ( stats.onlineClients + 1);
}
if (priority > neediest.priority) {
neediest = {

0 comments on commit 2fbcc6b

Please sign in to comment.
Something went wrong with that request. Please try again.