testable-utils
Advanced tools
Comparing version 0.3.7 to 0.4.0
@@ -69,3 +69,3 @@ | ||
const log = createLog(); | ||
const results = createResults(doNotWait); | ||
const results = createResults(doNotWait, info); | ||
results.current = results('dummy','http://dummy.com'); | ||
@@ -72,0 +72,0 @@ results.toResourceName = function(url) { return url; }; |
@@ -8,2 +8,3 @@ const request = require('request'); | ||
const PollIntervalMs = 1000; | ||
const UserNs = 'User'; | ||
@@ -66,3 +67,3 @@ function delay(t, v) { | ||
function createResults(noRemote) { | ||
function createResults(noRemote, info) { | ||
const answer = function(resource, url) { | ||
@@ -183,2 +184,4 @@ return { | ||
answer.waitForValue = function(options) { | ||
if (!options.value) | ||
options.value = info.execution ? info.execution.concurrentClients : 1; | ||
options.condition = function(val) { return val >= options.value; }; | ||
@@ -188,2 +191,21 @@ return answer.waitForCondition(options); | ||
answer.incrementAndWaitForValue = function(name, value) { | ||
return answer().counter({ | ||
namespace: UserNs, | ||
name: name, | ||
val: 1, | ||
units: 'requests' | ||
}).then(function() { | ||
return answer.waitForValue({ | ||
namespace: UserNs, | ||
name: name, | ||
value: value | ||
}); | ||
}); | ||
}; | ||
answer.barrier = function(name, value) { | ||
return answer.incrementAndWaitForValue(name, value); | ||
}; | ||
return answer; | ||
@@ -190,0 +212,0 @@ } |
@@ -115,2 +115,12 @@ const _ = require('lodash'); | ||
}); | ||
browser.addCommand('testableIncrementAndWaitForValue', function(options) { | ||
return results.incrementAndWaitForValue(options).catch(function(err) { | ||
throw new Error(err); | ||
}); | ||
}); | ||
browser.addCommand('testableBarrier', function(name, value) { | ||
return results.barrier(name, value).catch(function(err) { | ||
throw new Error(err); | ||
}); | ||
}); | ||
} | ||
@@ -117,0 +127,0 @@ } |
{ | ||
"name": "testable-utils", | ||
"version": "0.3.7", | ||
"version": "0.4.0", | ||
"description": "Utilities for Testable scripts", | ||
@@ -5,0 +5,0 @@ "author": "Avi Stramer", |
@@ -5,3 +5,11 @@ # Testable Script Utilities | ||
* [Custom Metrics](#capture-metrics) | ||
* [Custom metrics](#capture-metrics) | ||
* [Counter](#counter) | ||
* [Timing](#timing) | ||
* [Histogram](#histogram) | ||
* [Metered](#metered) | ||
* [Synchronizing across concurrent users](#synchronizing-across-concurrent-users) | ||
* [Barriers](#barriers) | ||
* [Get execution wide metric value](#get-execution-wide-metric-value) | ||
* [Wait for metric value](#wait-for-metric-value) | ||
* [Stopwatch](#stopwatch) | ||
@@ -11,6 +19,9 @@ * [Logging](#logging) | ||
* [CSV](#csv) | ||
* [Async Code](#async-code) | ||
* [Manual Live Event](#manual-live-event) | ||
* [Wait For Finish](#wait-for-finish) | ||
* [Webdriver.io Custom Commands](#webdriverio-commands) | ||
* [Get row by index](#get-row-by-index) | ||
* [Get random row](#get-random-row) | ||
* [Iterate CSV](#iterate-csv) | ||
* [Async code](#async-code) | ||
* [Manual live event](#manual-live-event) | ||
* [Wait for finish](#wait-for-finish) | ||
* [Webdriver.io custom commands](#webdriverio-commands) | ||
* [Screenshots](#screenshots) | ||
@@ -112,6 +123,28 @@ | ||
##### Get execution wide metric value | ||
### Synchronizing Across Concurrent Users | ||
Testable provides several APIs to assist in coordinating across the concurrent users that are part of your test. | ||
#### Barriers | ||
Returns a promise that will not resolve until all concurrent users globally reach this barrier. | ||
```javscript | ||
results.barrier(name, [value]); | ||
``` | ||
For example: | ||
```javascript | ||
results.get(name, bucket) | ||
results.barrier('Login').then(function() { | ||
// continue executing after all users reach the "Login" barrier. | ||
}) | ||
``` | ||
Optionally accepts a ```value``` as the second parameter if you do not expect all concurrent users globally to reach this barrier. | ||
#### Get execution wide metric value | ||
```javascript | ||
results.get(name, [bucket]) | ||
results.get(options) | ||
@@ -133,6 +166,7 @@ ``` | ||
##### Wait for metric value | ||
#### Wait for metric value | ||
```javascript | ||
results.waitForValue(options) | ||
results.incrementAndWaitForValue(options) | ||
``` | ||
@@ -142,2 +176,4 @@ | ||
If you use the ```incrementAndWaitForValue``` variation it will first increment a counter by 1 with the given name and then wait for the global value to reach the specified threshold. | ||
The options object can include: | ||
@@ -460,2 +496,6 @@ | ||
<tr> | ||
<td><pre>browser.testableGetMetric(options);</pre></td> | ||
<td><a href="#get-execution-wide-metric-value"><pre>results.get(options);</pre></a></td> | ||
</tr> | ||
<tr> | ||
<td><pre>browser.testableWaitForValue(options);</pre></td> | ||
@@ -469,2 +509,6 @@ <td><a href="#wait-for-metric-value"><pre>results.waitForValue(options);</pre></a></td> | ||
<tr> | ||
<td><pre>browser.testableBarrier(name, [value]);</pre></td> | ||
<td><a href="#barriers"><pre>results.barrier(name, [value]);</pre></a></td> | ||
</tr> | ||
<tr> | ||
<td><pre>// blocks until done() is called | ||
@@ -471,0 +515,0 @@ browser.testableStopwatch(function(done) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45190
757
519