Skip to content

Commit 190e143

Browse files
feat: enhance job readiness checks and implement retry logic for test stability
1 parent e2f43f3 commit 190e143

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

test/sanity-check/api/bulkOperation-test.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function assetsWithValidUids () {
4040
return [assetUid1, assetUid2].filter(uid => uid && String(uid).trim()).map(uid => ({ uid }))
4141
}
4242

43-
async function waitForJobReady (jobId, maxAttempts = 3) {
43+
async function waitForJobReady (jobId, maxAttempts = 15) {
4444
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
4545
try {
4646
// GET /v3/bulk/jobs/{job_id} on AM2.0 requires management token auth (authtoken returns 401)
@@ -369,6 +369,7 @@ describe('BulkOperation api test', () => {
369369

370370
it('should wait for jobs to be ready and get job status for the first publish job', async function () {
371371
this.timeout(60000)
372+
this.retries(2)
372373

373374
const response = await waitForJobReady(jobId1)
374375
expect(response).to.not.equal(undefined)
@@ -381,6 +382,7 @@ describe('BulkOperation api test', () => {
381382

382383
it('should validate detailed job status response structure', async function () {
383384
this.timeout(60000)
385+
this.retries(2)
384386
const response = await waitForJobReady(jobId1)
385387
expect(response).to.not.equal(undefined)
386388
expect(response.uid).to.not.equal(undefined)
@@ -394,6 +396,7 @@ describe('BulkOperation api test', () => {
394396

395397
it('should get job status for the second publish job', async function () {
396398
this.timeout(60000)
399+
this.retries(2)
397400

398401
const response = await waitForJobReady(jobId2)
399402
expect(response).to.not.equal(undefined)
@@ -406,6 +409,7 @@ describe('BulkOperation api test', () => {
406409

407410
it('should get job status for the third publish job', async function () {
408411
this.timeout(60000)
412+
this.retries(2)
409413

410414
const response = await waitForJobReady(jobId3)
411415
expect(response).to.not.equal(undefined)
@@ -418,6 +422,7 @@ describe('BulkOperation api test', () => {
418422

419423
it('should get job status for publishAllLocalized=true job', async function () {
420424
this.timeout(60000)
425+
this.retries(2)
421426

422427
const response = await waitForJobReady(jobId4)
423428
expect(response).to.not.equal(undefined)
@@ -430,6 +435,7 @@ describe('BulkOperation api test', () => {
430435

431436
it('should get job status for publishAllLocalized=false job', async function () {
432437
this.timeout(60000)
438+
this.retries(2)
433439

434440
const response = await waitForJobReady(jobId5)
435441
expect(response).to.not.equal(undefined)
@@ -442,6 +448,7 @@ describe('BulkOperation api test', () => {
442448

443449
it('should get job status for asset publishAllLocalized job', async function () {
444450
this.timeout(60000)
451+
this.retries(2)
445452

446453
const response = await waitForJobReady(jobId6)
447454
expect(response).to.not.equal(undefined)
@@ -454,6 +461,7 @@ describe('BulkOperation api test', () => {
454461

455462
it('should get job status for unpublishAllLocalized=true job', async function () {
456463
this.timeout(60000)
464+
this.retries(2)
457465

458466
const response = await waitForJobReady(jobId7)
459467
expect(response).to.not.equal(undefined)
@@ -466,6 +474,7 @@ describe('BulkOperation api test', () => {
466474

467475
it('should get job status for unpublishAllLocalized=false job', async function () {
468476
this.timeout(60000)
477+
this.retries(2)
469478

470479
const response = await waitForJobReady(jobId8)
471480
expect(response).to.not.equal(undefined)
@@ -478,6 +487,7 @@ describe('BulkOperation api test', () => {
478487

479488
it('should get job status for asset unpublishAllLocalized job', async function () {
480489
this.timeout(60000)
490+
this.retries(2)
481491

482492
const response = await waitForJobReady(jobId9)
483493
expect(response).to.not.equal(undefined)
@@ -490,6 +500,7 @@ describe('BulkOperation api test', () => {
490500

491501
it('should get job status for multiple parameters job', async function () {
492502
this.timeout(60000)
503+
this.retries(2)
493504

494505
const response = await waitForJobReady(jobId10)
495506
expect(response).to.not.equal(undefined)
@@ -502,6 +513,7 @@ describe('BulkOperation api test', () => {
502513

503514
it('should get job status with bulk_version parameter', async function () {
504515
this.timeout(60000)
516+
this.retries(2)
505517

506518
await waitForJobReady(jobId1)
507519
const response = await doBulkOperationWithManagementToken(tokenUidDev)
@@ -516,6 +528,7 @@ describe('BulkOperation api test', () => {
516528

517529
it('should get job items for a completed job', async function () {
518530
this.timeout(60000)
531+
this.retries(2)
519532

520533
await waitForJobReady(jobId1)
521534
const response = await doBulkOperationWithManagementToken(tokenUidDev)
@@ -526,6 +539,7 @@ describe('BulkOperation api test', () => {
526539

527540
it('should get job items with explicit api_version', async function () {
528541
this.timeout(60000)
542+
this.retries(2)
529543

530544
await waitForJobReady(jobId2)
531545
const response = await doBulkOperationWithManagementToken(tokenUidDev)

test/sanity-check/sanity.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,17 @@ before(async function () {
242242
// GLOBAL CURL CAPTURE FOR ALL TESTS (PASSED AND FAILED)
243243
// ============================================================================
244244

245-
// Clear request log and assertion tracker before each test
246-
beforeEach(function () {
245+
// Clear request log and assertion tracker before each test.
246+
// When a test has this.retries(N) and is being retried, waits 7 seconds first
247+
// so the server has time to recover from slowness before the next attempt.
248+
beforeEach(async function () {
249+
const retryNum = (typeof this.currentRetry === 'function') ? this.currentRetry() : 0
250+
if (retryNum > 0) {
251+
const testTitle = (this.currentTest && this.currentTest.title) || 'unknown'
252+
console.log(` [retry] attempt ${retryNum + 1} for "${testTitle}" — waiting 7s for server recovery...`)
253+
await new Promise(resolve => setTimeout(resolve, 7000))
254+
}
255+
247256
// Clear SDK plugin request capture
248257
testSetup.clearCapturedRequests()
249258

0 commit comments

Comments
 (0)