From 7078bde5882546b98bb453fb3e27e5ba6f89ffdb Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Wed, 30 Jul 2025 23:11:50 +0530 Subject: [PATCH 1/2] Added delay in bulk publish test suites --- test/sanity-check/api/bulkOperation-test.js | 154 ++++++++++---------- 1 file changed, 78 insertions(+), 76 deletions(-) diff --git a/test/sanity-check/api/bulkOperation-test.js b/test/sanity-check/api/bulkOperation-test.js index 22643db3..70808a61 100644 --- a/test/sanity-check/api/bulkOperation-test.js +++ b/test/sanity-check/api/bulkOperation-test.js @@ -19,6 +19,27 @@ let jobId3 = '' let tokenUidDev = '' let tokenUid = '' +function delay(ms) { + return new Promise(resolve => setTimeout(resolve, ms)) +} + +async function waitForJobReady(jobId, maxAttempts = 10) { + for (let attempt = 1; attempt <= maxAttempts; attempt++) { + try { + const response = await doBulkOperationWithManagementToken(tokenUidDev) + .jobStatus({ job_id: jobId, api_version: '3.2' }) + + if (response && response.status) { + return response + } + } catch (error) { + console.log(`Attempt ${attempt}: Job not ready yet, retrying...`) + } + await delay(2000) + } + throw new Error(`Job ${jobId} did not become ready after ${maxAttempts} attempts`) +} + describe('BulkOperation api test', () => { setup(() => { const user = jsonReader('loggedinuser.json') @@ -141,91 +162,72 @@ describe('BulkOperation api test', () => { .catch(done) }) - it('should get job status for the first publish job', done => { - doBulkOperationWithManagementToken(tokenUidDev) - .jobStatus({ job_id: jobId1, api_version: '3.2' }) - .then((response) => { - expect(response).to.not.equal(undefined) - expect(response.uid).to.not.equal(undefined) - expect(response.status).to.not.equal(undefined) - expect(response.action).to.not.equal(undefined) - expect(response.summary).to.not.equal(undefined) - expect(response.body).to.not.equal(undefined) - done() - }) - .catch((error) => { - console.error('Job status error:', error) - done(error) - }) + it('should wait for all jobs to be processed before checking status', async () => { + await delay(5000) // Wait 5 seconds for jobs to be processed }) - it('should validate detailed job status response structure', done => { - doBulkOperationWithManagementToken(tokenUidDev) - .jobStatus({ job_id: jobId1, api_version: '3.2' }) - .then((response) => { - expect(response).to.not.equal(undefined) - // Validate main job properties - expect(response.uid).to.not.equal(undefined) - expect(response.api_key).to.not.equal(undefined) - expect(response.status).to.not.equal(undefined) - - // Validate body structure - expect(response.body).to.not.equal(undefined) - expect(response.body.locales).to.be.an('array') - expect(response.body.environments).to.be.an('array') - // Validate summary structure - expect(response.summary).to.not.equal(undefined) - done() - }) - .catch((error) => { - console.error('Detailed job status error:', error) - done(error) - }) + it('should wait for jobs to be ready and get job status for the first publish job', async () => { + const response = await waitForJobReady(jobId1) + + expect(response).to.not.equal(undefined) + expect(response.uid).to.not.equal(undefined) + expect(response.status).to.not.equal(undefined) + expect(response.action).to.not.equal(undefined) + expect(response.summary).to.not.equal(undefined) + expect(response.body).to.not.equal(undefined) }) - it('should get job status for the second publish job', done => { - doBulkOperationWithManagementToken(tokenUidDev) - .jobStatus({ job_id: jobId2, api_version: '3.2' }) - .then((response) => { - expect(response).to.not.equal(undefined) - expect(response.uid).to.not.equal(undefined) - expect(response.status).to.not.equal(undefined) - expect(response.action).to.not.equal(undefined) - expect(response.summary).to.not.equal(undefined) - expect(response.body).to.not.equal(undefined) - done() - }) - .catch(done) + it('should validate detailed job status response structure', async () => { + const response = await waitForJobReady(jobId1) + + expect(response).to.not.equal(undefined) + // Validate main job properties + expect(response.uid).to.not.equal(undefined) + expect(response.api_key).to.not.equal(undefined) + expect(response.status).to.not.equal(undefined) + + // Validate body structure + expect(response.body).to.not.equal(undefined) + expect(response.body.locales).to.be.an('array') + expect(response.body.environments).to.be.an('array') + // Validate summary structure + expect(response.summary).to.not.equal(undefined) }) - it('should get job status for the third publish job', done => { - doBulkOperationWithManagementToken(tokenUidDev) - .jobStatus({ job_id: jobId3, api_version: '3.2' }) - .then((response) => { - expect(response).to.not.equal(undefined) - expect(response.uid).to.not.equal(undefined) - expect(response.status).to.not.equal(undefined) - expect(response.action).to.not.equal(undefined) - expect(response.summary).to.not.equal(undefined) - expect(response.body).to.not.equal(undefined) - done() - }) - .catch(done) + it('should get job status for the second publish job', async () => { + const response = await waitForJobReady(jobId2) + + expect(response).to.not.equal(undefined) + expect(response.uid).to.not.equal(undefined) + expect(response.status).to.not.equal(undefined) + expect(response.action).to.not.equal(undefined) + expect(response.summary).to.not.equal(undefined) + expect(response.body).to.not.equal(undefined) + }) + + it('should get job status for the third publish job', async () => { + const response = await waitForJobReady(jobId3) + + expect(response).to.not.equal(undefined) + expect(response.uid).to.not.equal(undefined) + expect(response.status).to.not.equal(undefined) + expect(response.action).to.not.equal(undefined) + expect(response.summary).to.not.equal(undefined) + expect(response.body).to.not.equal(undefined) }) - it('should get job status with bulk_version parameter', done => { - doBulkOperationWithManagementToken(tokenUidDev) + it('should get job status with bulk_version parameter', async () => { + await waitForJobReady(jobId1) + + const response = await doBulkOperationWithManagementToken(tokenUidDev) .jobStatus({ job_id: jobId1, bulk_version: 'v3', api_version: '3.2' }) - .then((response) => { - expect(response).to.not.equal(undefined) - expect(response.uid).to.not.equal(undefined) - expect(response.status).to.not.equal(undefined) - expect(response.action).to.not.equal(undefined) - expect(response.summary).to.not.equal(undefined) - expect(response.body).to.not.equal(undefined) - done() - }) - .catch(done) + + expect(response).to.not.equal(undefined) + expect(response.uid).to.not.equal(undefined) + expect(response.status).to.not.equal(undefined) + expect(response.action).to.not.equal(undefined) + expect(response.summary).to.not.equal(undefined) + expect(response.body).to.not.equal(undefined) }) it('should delete a Management Token', done => { From 14e7390c7bdb32463ec77c183305c6000934b58a Mon Sep 17 00:00:00 2001 From: sunil-lakshman <104969541+sunil-lakshman@users.noreply.github.com> Date: Wed, 30 Jul 2025 23:12:29 +0530 Subject: [PATCH 2/2] Fixed the lint errors --- test/sanity-check/api/bulkOperation-test.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/sanity-check/api/bulkOperation-test.js b/test/sanity-check/api/bulkOperation-test.js index 70808a61..8e33832d 100644 --- a/test/sanity-check/api/bulkOperation-test.js +++ b/test/sanity-check/api/bulkOperation-test.js @@ -19,16 +19,16 @@ let jobId3 = '' let tokenUidDev = '' let tokenUid = '' -function delay(ms) { +function delay (ms) { return new Promise(resolve => setTimeout(resolve, ms)) } -async function waitForJobReady(jobId, maxAttempts = 10) { +async function waitForJobReady (jobId, maxAttempts = 10) { for (let attempt = 1; attempt <= maxAttempts; attempt++) { try { const response = await doBulkOperationWithManagementToken(tokenUidDev) .jobStatus({ job_id: jobId, api_version: '3.2' }) - + if (response && response.status) { return response } @@ -168,7 +168,7 @@ describe('BulkOperation api test', () => { it('should wait for jobs to be ready and get job status for the first publish job', async () => { const response = await waitForJobReady(jobId1) - + expect(response).to.not.equal(undefined) expect(response.uid).to.not.equal(undefined) expect(response.status).to.not.equal(undefined) @@ -179,7 +179,7 @@ describe('BulkOperation api test', () => { it('should validate detailed job status response structure', async () => { const response = await waitForJobReady(jobId1) - + expect(response).to.not.equal(undefined) // Validate main job properties expect(response.uid).to.not.equal(undefined) @@ -196,7 +196,7 @@ describe('BulkOperation api test', () => { it('should get job status for the second publish job', async () => { const response = await waitForJobReady(jobId2) - + expect(response).to.not.equal(undefined) expect(response.uid).to.not.equal(undefined) expect(response.status).to.not.equal(undefined) @@ -207,7 +207,7 @@ describe('BulkOperation api test', () => { it('should get job status for the third publish job', async () => { const response = await waitForJobReady(jobId3) - + expect(response).to.not.equal(undefined) expect(response.uid).to.not.equal(undefined) expect(response.status).to.not.equal(undefined) @@ -218,10 +218,10 @@ describe('BulkOperation api test', () => { it('should get job status with bulk_version parameter', async () => { await waitForJobReady(jobId1) - + const response = await doBulkOperationWithManagementToken(tokenUidDev) .jobStatus({ job_id: jobId1, bulk_version: 'v3', api_version: '3.2' }) - + expect(response).to.not.equal(undefined) expect(response.uid).to.not.equal(undefined) expect(response.status).to.not.equal(undefined)