Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions params.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,36 @@ class Params {
this.startDelay = 100;
}

for (const paramKey of ["tag", "tags", "test", "tests"]) {
this.testList = this._parseTestListParam(sourceParams, paramKey);
}

this.testIterationCount = this._parseIntParam(sourceParams, "iterationCount", 1);
this.testWorstCaseCount = this._parseIntParam(sourceParams, "worstCaseCount", 1);
this.testList = this._parseOneOf(sourceParams, ["testList", "tag", "tags", "test", "tests"], this._parseTestListParam);
this.testIterationCount = this._parseOneOf(sourceParams, ["testIterationCount", "iterationCount", "iterations" ], this._parseIntParam, 1);
this.testWorstCaseCount = this._parseOneOf(sourceParams, ["testWorstCaseCount", "worstCaseCount", "worst"], this._parseIntParam, 1);

const unused = Array.from(sourceParams.keys());
if (unused.length > 0)
console.error("Got unused source params", unused);
}

_parseOneOf(sourceParams, paramKeys, parseFunction, ...args) {
const defaultParamKey = paramKeys[0]
let result = undefined;
let parsedParamKey = undefined;
for (const paramKey of paramKeys) {
if (!sourceParams.has(paramKey)) {
continue;
}
const parseResult = parseFunction.call(this, sourceParams, paramKey, ...args);
if (parsedParamKey) {
throw new Error(`Cannot parse ${paramKey}, overriding previous "${parsedParamKey}" value ${JSON.stringify(result)} with ${JSON.stringify(parseResult)}`)
}
parsedParamKey = paramKey;
result = parseResult;
}
if (!parsedParamKey) {
return DefaultJetStreamParams[defaultParamKey];
}
return result;
}

_parseTestListParam(sourceParams, key) {
if (!sourceParams.has(key))
return this.testList;
Expand All @@ -108,9 +126,6 @@ class Params {
}
testList = testList.map(each => each.trim());
sourceParams.delete(key);
if (this.testList.length > 0 && testList.length > 0) {
throw new Error(`Overriding previous testList='${this.testList.join()}' with ${key} url-parameter.`);
}
return testList;
}

Expand Down
19 changes: 18 additions & 1 deletion tests/unit-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function assertThrows(message, func) {
} catch (e) {
didThrow = true;
}
assertTrue(didThrow, message);
assertTrue(didThrow, `Test did not throw: ${message}`);
}

(function testTagsAreLowerCaseStrings() {
Expand Down Expand Up @@ -276,3 +276,20 @@ async function testStartupBenchmarkInnerTests() {
}
);
})();


(function testParseIterationCount() {
assertThrows("Cannot parse negative iterationCounts",
() => {
const sourceParams = new Map(Object.entries({ iterationCount: -123, }));
new Params(sourceParams);
});
assertThrows("Cannot parse multiple iterationCounts",
() => {
const sourceParams = new Map(Object.entries({ iterationCount: 123, testIterationCount: 10 }));
new Params(sourceParams);
});
let sourceParams = new Map(Object.entries({ iterationCount: 123 }));
let params = new Params(sourceParams);
assertEquals(params.testIterationCount, 123);
})();
Loading