Skip to content

Commit 81aeddc

Browse files
committed
Use pagination in sentinel
1 parent 6254f5a commit 81aeddc

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

tests/k6/common/sentinel.js

+27-13
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,37 @@ export default function () {
88
scopes: "digdir:dialogporten.serviceprovider digdir:dialogporten.serviceprovider.search digdir:dialogporten.serviceprovider.admin digdir:dialogporten.correspondence"
99
}
1010
describe('Post run: checking for unpurged dialogs', () => {
11-
let r = getSO('dialogs/?Search=' + sentinelValue, null, tokenOptions);
12-
expectStatusFor(r).to.equal(200);
13-
expect(r, 'response').to.have.validJsonBody();
14-
var response = r.json();
15-
if (response.items && response.items.length > 0) {
16-
console.error("Found " + response.items.length + " unpurged dialogs, make sure that all tests clean up after themselves. Purging ...");
17-
response.items.forEach((item) => {
18-
console.warn("Sentinel purging dialog with id: " + item.id)
19-
let r = purgeSO('dialogs/' + item.id, null, tokenOptions);
11+
let hasNextPage = false;
12+
let continuationToken = "";
13+
let dialogIdsToPurge = [];
14+
do {
15+
let r = getSO('dialogs/?Limit=10&Search=' + sentinelValue + continuationToken, null, tokenOptions);
16+
expectStatusFor(r).to.equal(200);
17+
expect(r, 'response').to.have.validJsonBody();
18+
let response = r.json();
19+
if (response.items && response.items.length > 0) {
20+
response.items.forEach((item) => {
21+
dialogIdsToPurge.push(item.id);
22+
});
23+
24+
hasNextPage = response.hasNextPage;
25+
continuationToken = "&continuationToken=" + response.continuationToken;
26+
}
27+
} while (hasNextPage);
28+
29+
if (dialogIdsToPurge.length > 0) {
30+
console.error("Found " + dialogIdsToPurge.length + " unpurged dialogs, make sure that all tests clean up after themselves. Purging ...");
31+
dialogIdsToPurge.forEach((id) => {
32+
console.warn("Sentinel purging dialog with id: " + id)
33+
let r = purgeSO('dialogs/' + id, null, tokenOptions);
2034
if (r.status != 204) {
21-
console.error("Failed to purge dialog with id: " + item.id);
35+
console.error("Failed to purge dialog with id: " + id);
2236
console.log(r);
2337
}
2438
});
25-
26-
// Fail the test after purging for visibility
27-
expect(response.items.length, 'unpurged dialogs').to.equal(0);
2839
}
40+
41+
// Fail the test after purging for visibility
42+
expect(dialogIdsToPurge.length, 'unpurged dialogs').to.equal(0);
2943
});
3044
}

0 commit comments

Comments
 (0)