diff --git a/README.md b/README.md index 52ceb81..77af9fa 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ fuzzy-tester -t dev * `-o` Select an output mode. Valid values are `terminal` (default), `csv`, `json`, and `autocomplete` (see below) * `-q` Enable quiet mode. Only test failures (not successes) are printed * `-t` Select a test 'type' to filter on. This is a free-text value that can be added to each test, to allow running a subset of tests +* `-r` Set a limit of the number of requests that can be sent per second when running tests. This is useful to avoid overloading a small Pelias server ## Test Case Files Test-cases are expected to live in `test_cases/`, and are split into test diff --git a/bin/fuzzy-tester b/bin/fuzzy-tester index 27cf380..619e7a9 100755 --- a/bin/fuzzy-tester +++ b/bin/fuzzy-tester @@ -27,7 +27,7 @@ var analyze_results = require( '../lib/analyze_results' ); var urls = gather_test_urls(config, testSuites); // request all urls - request_urls(urls, function processResponses(responses) { + request_urls(config, urls, function processResponses(responses) { // responses is a simple object where the keys are urls, and the value is the // entire response from fetching that url // test cases can have many URLs (in autocomplete mode), and the same url diff --git a/lib/processArguments.js b/lib/processArguments.js index 258aec2..4dd5a06 100644 --- a/lib/processArguments.js +++ b/lib/processArguments.js @@ -47,6 +47,11 @@ function setUpCommander() { endpointHelp, 'prod' ) + .option( + '-r, --rate ', + 'The maxium number of requests per second (RPS) to allow', + 100 + ) .option( '-o, --output ', outputGeneratorHelp, @@ -113,6 +118,7 @@ function getConfig() { url: apiUrl, name: commander.endpoint }, + rate: commander.rate, outputGenerator: outputGenerator, testType: commander.testType, testSuites: testSuites, diff --git a/lib/request_urls.js b/lib/request_urls.js index 1df09ac..61a8fe3 100644 --- a/lib/request_urls.js +++ b/lib/request_urls.js @@ -25,12 +25,13 @@ function shouldRetryRequest(res) { return false; } -function request_urls(urls, callback) { +function request_urls(config, urls, callback) { var total_length = urls.length; var responses = {}; var agent = new http.Agent({keepAlive: true, maxSockets: 1}); var intervalId; - var test_interval = new ExponentialBackoff(1, 5, 1, 20000); + const interval = 1000 / config.rate; // the number of miliseconds to delay between requests + var test_interval = new ExponentialBackoff(interval, 5, interval, 20000); var delay = test_interval.getBackoff(); var getOneUrl = function (){