Skip to content

Commit

Permalink
Merge branch 'main' into performance/create-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dagfinno authored Nov 1, 2024
2 parents f4e5f0e + a1df0ff commit fb08882
Showing 1 changed file with 26 additions and 13 deletions.
39 changes: 26 additions & 13 deletions tests/k6/common/sentinel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,36 @@ export default function () {
scopes: "digdir:dialogporten.serviceprovider digdir:dialogporten.serviceprovider.search digdir:dialogporten.serviceprovider.admin digdir:dialogporten.correspondence"
}
describe('Post run: checking for unpurged dialogs', () => {
let r = getSO('dialogs/?Search=' + sentinelValue, null, tokenOptions);
expectStatusFor(r).to.equal(200);
expect(r, 'response').to.have.validJsonBody();
var response = r.json();
if (response.items && response.items.length > 0) {
console.error("Found " + response.items.length + " unpurged dialogs, make sure that all tests clean up after themselves. Purging ...");
response.items.forEach((item) => {
console.warn("Sentinel purging dialog with id: " + item.id)
let r = purgeSO('dialogs/' + item.id, null, tokenOptions);
let hasNextPage = false;
let continuationToken = "";
let dialogIdsToPurge = [];
do {
let r = getSO('dialogs/?Search=' + sentinelValue + continuationToken, null, tokenOptions);
expectStatusFor(r).to.equal(200);
expect(r, 'response').to.have.validJsonBody();
let response = r.json();
if (response.items && response.items.length > 0) {
response.items.forEach((item) => {
dialogIdsToPurge.push(item.id);
});
continuationToken = "&continuationToken=" + response.continuationToken;
}
hasNextPage = response.hasNextPage;
} while (hasNextPage);

if (dialogIdsToPurge.length > 0) {
console.error("Found " + dialogIdsToPurge.length + " unpurged dialogs, make sure that all tests clean up after themselves. Purging ...");
dialogIdsToPurge.forEach((id) => {
console.warn("Sentinel purging dialog with id: " + id)
let r = purgeSO('dialogs/' + id, null, tokenOptions);
if (r.status != 204) {
console.error("Failed to purge dialog with id: " + item.id);
console.error("Failed to purge dialog with id: " + id);
console.log(r);
}
});

// Fail the test after purging for visibility
expect(response.items.length, 'unpurged dialogs').to.equal(0);
}

// Fail the test after purging for visibility
expect(dialogIdsToPurge.length, 'unpurged dialogs').to.equal(0);
});
}

0 comments on commit fb08882

Please sign in to comment.