@@ -89,13 +89,16 @@ When('the job to replicate existing objects with status {string} is executed',
8989 await createAndRunPod ( this , podManifest ) ;
9090 } ) ;
9191
92- Then ( 'the object should eventually {string} replicated' , { timeout : 360_000 } ,
93- async function ( this : Zenko , replicate : 'be' | 'fail to be' ) {
92+ Then ( 'the object replication should {string} within {int} seconds' , { timeout : 600_000 } ,
93+ async function (
94+ this : Zenko ,
95+ expectedOutcome : 'succeed' | 'fail' | 'never happen' ,
96+ replicationTimeout : number
97+ ) {
9498 const objectName = this . getSaved < string > ( 'objectName' ) ;
9599 const bucketSource = this . getSaved < string > ( 'bucketName' ) ;
96100 const startTime = Date . now ( ) ;
97- const replicationTimeoutMs = 300_000 ;
98- while ( Date . now ( ) - startTime < replicationTimeoutMs ) {
101+ while ( Date . now ( ) - startTime < replicationTimeout * 1000 ) {
99102 await new Promise ( resolve => setTimeout ( resolve , 3000 ) ) ;
100103
101104 const response = await headObject ( this , objectName , bucketSource ) ;
@@ -112,26 +115,30 @@ Then('the object should eventually {string} replicated', { timeout: 360_000 },
112115 assert ( parsed . ok ) ;
113116 const replicationStatus = parsed . result ?. ReplicationStatus ;
114117
115- if ( replicate === 'be' ) {
116- assert . notStrictEqual ( replicationStatus , 'FAILED' , `replication failed for object ${ objectName } ` ) ;
117- if ( replicationStatus === 'COMPLETED' ) {
118- return ;
119- }
120- } else if ( replicate === 'fail to be' ) {
121- assert . notStrictEqual (
122- replicationStatus ,
123- 'COMPLETED' ,
124- `expected replication to fail for object ${ objectName } `
125- ) ;
126- if ( replicationStatus === 'FAILED' ) {
127- return ;
128- }
129- }
130- if ( replicationStatus === 'PENDING' || replicationStatus === 'PROCESSING' ) {
118+ switch ( replicationStatus ) {
119+ case 'PENDING' :
120+ case 'PROCESSING' :
121+ assert . notStrictEqual ( expectedOutcome , 'never happen' ,
122+ `replication status is ${ replicationStatus } , but expected to never happen` ) ;
131123 continue ;
124+ case 'COMPLETED' :
125+ assert . strictEqual ( expectedOutcome , 'succeed' ,
126+ `replication is completed, but expected outcome was '${ expectedOutcome } '` ) ;
127+ return ;
128+ case 'FAILED' :
129+ assert . strictEqual ( expectedOutcome , 'fail' ,
130+ `replication is failed, but expected outcome was '${ expectedOutcome } '` ) ;
131+ return ;
132+ case undefined :
133+ // If we don't expect a replication to happen, the replication status should remain undefined
134+ assert . strictEqual ( expectedOutcome , 'never happen' ,
135+ `got undefined replication status for expected outcome '${ expectedOutcome } '` ) ;
136+ return ;
137+ default :
138+ throw new Error ( `Unexpected replication status: ${ replicationStatus } ` ) ;
132139 }
133140 }
134- assert . fail ( `Timeout: Object '${ objectName } ' is still pending/processing after timeout` ) ;
141+ assert . fail ( `Timeout: Object '${ objectName } ' is still in pending/processing state after timeout` ) ;
135142 } ) ;
136143
137144Then (
0 commit comments