@@ -89,13 +89,16 @@ When('the job to replicate existing objects with status {string} is executed',
89
89
await createAndRunPod ( this , podManifest ) ;
90
90
} ) ;
91
91
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
+ ) {
94
98
const objectName = this . getSaved < string > ( 'objectName' ) ;
95
99
const bucketSource = this . getSaved < string > ( 'bucketName' ) ;
96
100
const startTime = Date . now ( ) ;
97
- const replicationTimeoutMs = 300_000 ;
98
- while ( Date . now ( ) - startTime < replicationTimeoutMs ) {
101
+ while ( Date . now ( ) - startTime < replicationTimeout * 1000 ) {
99
102
await new Promise ( resolve => setTimeout ( resolve , 3000 ) ) ;
100
103
101
104
const response = await headObject ( this , objectName , bucketSource ) ;
@@ -112,26 +115,33 @@ Then('the object should eventually {string} replicated', { timeout: 360_000 },
112
115
assert ( parsed . ok ) ;
113
116
const replicationStatus = parsed . result ?. ReplicationStatus ;
114
117
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` ) ;
131
123
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
+ // For 'succeed'/'fail', the object may not have been switched to pending status yet
134
+ // For 'never happen', the status should remain undefined
135
+ continue ;
136
+ default :
137
+ throw new Error ( `Unexpected replication status: ${ replicationStatus } ` ) ;
132
138
}
133
139
}
134
- assert . fail ( `Timeout: Object '${ objectName } ' is still pending/processing after timeout` ) ;
140
+ if ( expectedOutcome === 'never happen' ) {
141
+ // Success: status remained undefined throughout the timeout period
142
+ return ;
143
+ }
144
+ assert . fail ( `Timeout: Object '${ objectName } ' is still in pending/processing state after timeout` ) ;
135
145
} ) ;
136
146
137
147
Then (
0 commit comments