Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(e2e): Use pagination in sentinel #1372

Merged
merged 3 commits into from
Nov 1, 2024
Merged
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
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);
elsand marked this conversation as resolved.
Show resolved Hide resolved
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);
}
});
elsand marked this conversation as resolved.
Show resolved Hide resolved

// 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);
});
}