From 7cb04a8d0d43e5fd44743fdfe2c2a1a34030e7db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Dybvik=20Langfors?= Date: Fri, 1 Nov 2024 12:47:12 +0100 Subject: [PATCH 1/2] Use pagination in sentinel --- tests/k6/common/sentinel.js | 40 +++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/tests/k6/common/sentinel.js b/tests/k6/common/sentinel.js index 5768829da..29b4480fb 100644 --- a/tests/k6/common/sentinel.js +++ b/tests/k6/common/sentinel.js @@ -8,23 +8,37 @@ 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); + }); + + hasNextPage = response.hasNextPage; + continuationToken = "&continuationToken=" + response.continuationToken; + } + } 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); }); } From d6f2fa83d82426d5ab39beeee6095bfe3839addf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Dybvik=20Langfors?= Date: Fri, 1 Nov 2024 12:59:57 +0100 Subject: [PATCH 2/2] Fix possible infinite loop next page contains no items (purged elsewhere) --- tests/k6/common/sentinel.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/k6/common/sentinel.js b/tests/k6/common/sentinel.js index 29b4480fb..57615bf90 100644 --- a/tests/k6/common/sentinel.js +++ b/tests/k6/common/sentinel.js @@ -20,10 +20,9 @@ export default function () { response.items.forEach((item) => { dialogIdsToPurge.push(item.id); }); - - hasNextPage = response.hasNextPage; continuationToken = "&continuationToken=" + response.continuationToken; } + hasNextPage = response.hasNextPage; } while (hasNextPage); if (dialogIdsToPurge.length > 0) {