diff --git a/tests/functional/ctst/steps/azureArchive.ts b/tests/functional/ctst/steps/azureArchive.ts index b85e9a3f4..2366836c1 100644 --- a/tests/functional/ctst/steps/azureArchive.ts +++ b/tests/functional/ctst/steps/azureArchive.ts @@ -52,30 +52,26 @@ function getAzureCreds( * @returns {string} name of the tar blob */ async function isObjectRehydrated(zenko: Zenko, objectName: string) { - let found = false; - const { - tarName, - } = await findObjectPackAndManifest( + const { tarName } = await findObjectPackAndManifest( zenko, zenko.getSaved('bucketName'), objectName || zenko.getSaved('objectName'), ); - const start = new Date(); assert(tarName); - while (!found) { - found = await AzureHelper.blobExists( + const start = Date.now(); + //wait for 1 minute max + while (Date.now() - start <= 60000) { + const found = await AzureHelper.blobExists( zenko.parameters.AzureArchiveContainer, `rehydrate/${tarName}`, getAzureCreds(zenko), ); - await Utils.sleep(1000); - - //wait for 1 minute max - if (new Date().getTime() - start.getTime() > 60000) { - return undefined; + if (found) { + return tarName; } + await Utils.sleep(1000); } - return tarName; + return undefined; } /** diff --git a/tests/functional/ctst/steps/utils/kubernetes.ts b/tests/functional/ctst/steps/utils/kubernetes.ts index a917e5b25..d7d0f4411 100644 --- a/tests/functional/ctst/steps/utils/kubernetes.ts +++ b/tests/functional/ctst/steps/utils/kubernetes.ts @@ -260,7 +260,6 @@ export async function waitForZenkoToStabilize( // So, this function will first wait till we detect a reconciliation // (deploymentInProgress = true), and then wait for the status to be available const startTime = Date.now(); - let status = false; let deploymentFailure: ZenkoStatusValue = { lastTransitionTime: '', message: '', @@ -287,7 +286,7 @@ export async function waitForZenkoToStabilize( world.logger.debug('Waiting for Zenko to stabilize'); const zenkoClient = createKubeCustomObjectClient(world); - while (!status && Date.now() - startTime < timeout) { + while (Date.now() - startTime < timeout) { const zenkoCR = await zenkoClient.getNamespacedCustomObject({ group: 'zenko.io', version: 'v1alpha2', @@ -342,19 +341,16 @@ export async function waitForZenkoToStabilize( deploymentInProgress.status === 'False' && available.status === 'True' ) { - status = true; + return; } await Utils.sleep(1000); } - if (!status) { - throw new Error('Zenko did not stabilize'); - } + throw new Error('Zenko did not stabilize'); } export async function waitForDataServicesToStabilize(world: Zenko, timeout = 15 * 60 * 1000, namespace = 'default') { - let allRunning = false; const startTime = Date.now(); const annotationKey = 'operator.zenko.io/dependencies'; const dataServices = ['connector-cloudserver-config', 'backbeat-config']; @@ -379,8 +375,8 @@ export async function waitForDataServicesToStabilize(world: Zenko, timeout = 15 deployments: deployments.map(deployment => deployment.metadata?.name), }); - while (!allRunning && Date.now() - startTime < timeout) { - allRunning = true; + while (Date.now() - startTime < timeout) { + let allRunning = true; // get the deployments in the array, and check in loop if they are ready for (const deployment of deployments) { @@ -414,14 +410,13 @@ export async function waitForDataServicesToStabilize(world: Zenko, timeout = 15 } } + if (allRunning) { + return true; + } await Utils.sleep(1000); } - if (!allRunning) { - throw new Error('Data services did not stabilize'); - } - - return allRunning; + throw new Error('Data services did not stabilize'); } export async function displayCRStatus(world: Zenko, namespace = 'default') { diff --git a/tests/functional/ctst/steps/utils/utils.ts b/tests/functional/ctst/steps/utils/utils.ts index 3d0b60129..3612fdc35 100644 --- a/tests/functional/ctst/steps/utils/utils.ts +++ b/tests/functional/ctst/steps/utils/utils.ts @@ -484,24 +484,16 @@ async function verifyObjectLocation(this: Zenko, objectName: string, if (versionId) { this.addCommandParameter({ versionId }); } - let conditionOk = false; - const startTime = Date.now(); const timeoutMs = 5 * 60 * 1000; - while (!conditionOk) { - if (Date.now() - startTime > timeoutMs) { - throw new Error( - `verifyObjectLocation timed out after ${timeoutMs / 1000}s ` + - `waiting for object "${objName}" to reach status "${objectTransitionStatus}" ` + - `with storage class "${storageClass}"` - ); - } + while (Date.now() - startTime <= timeoutMs) { const res = await S3.headObject(this.getCommandParameters()); if (res.err?.includes('NotFound')) { await Utils.sleep(1000); continue; - } else if (res.err) { - break; + } + if (res.err) { + throw new Error(`verifyObjectLocation: headObject failed for "${objName}": ${res.err}`); } assert(res.stdout); const parsed = safeJsonParse<{ @@ -510,19 +502,23 @@ async function verifyObjectLocation(this: Zenko, objectName: string, }>(res.stdout); assert(parsed.ok); const expectedClass = storageClass !== '' ? storageClass : undefined; - if (parsed.result?.StorageClass === expectedClass) { - conditionOk = true; - } + let ok = parsed.result?.StorageClass === expectedClass; if (objectTransitionStatus == 'restored') { - const isRestored = !!parsed.result?.Restore && + ok = ok && !!parsed.result?.Restore && parsed.result.Restore.includes('ongoing-request="false", expiry-date='); - conditionOk = conditionOk && isRestored; } else if (objectTransitionStatus == 'cold') { - conditionOk = conditionOk && !parsed.result?.Restore; + ok = ok && !parsed.result?.Restore; + } + if (ok) { + return; } await Utils.sleep(1000); } - assert(conditionOk); + throw new Error( + `verifyObjectLocation timed out after ${timeoutMs / 1000}s ` + + `waiting for object "${objName}" to reach status "${objectTransitionStatus}" ` + + `with storage class "${storageClass}"` + ); } async function restoreObject(this: Zenko, objectName: string, days: number) {