Skip to content

Commit c86d1d3

Browse files
committed
feat(cucumber): use waiters in s3 integ tests
1 parent 5ecda4b commit c86d1d3

File tree

1 file changed

+21
-46
lines changed

1 file changed

+21
-46
lines changed

features/extra/helpers.js

Lines changed: 21 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
const {
2+
waitForBucketExists: bucketExists,
3+
waitForBucketNotExists: bucketNotExists,
4+
} = require("../../clients/client-s3");
5+
16
module.exports = {
27
assert: require("./assertions").assert,
38

@@ -189,55 +194,25 @@ module.exports = {
189194
return buffer;
190195
},
191196

192-
/**
193-
* Waits for the bucketExists state by periodically calling the underlying S3.headBucket() operation
194-
* every 5 seconds (at most 20 times).
195-
*/
196197
waitForBucketExists: function (s3client, params, callback) {
197-
const maxAttempts = 20;
198-
let currentAttempt = 0;
199-
const delay = 5000;
200-
201-
const checkForBucketExists = () => {
202-
currentAttempt++;
203-
s3client.headBucket(params, function (err, data) {
204-
if (currentAttempt > maxAttempts) {
205-
callback(new Error("waitForBucketExists: max attempts exceeded"));
206-
} else if (data) {
207-
callback();
208-
} else {
209-
setTimeout(function () {
210-
checkForBucketExists();
211-
}, delay);
212-
}
213-
});
214-
};
215-
checkForBucketExists();
198+
bucketExists({ client: s3client }, params).then(
199+
function (data) {
200+
callback();
201+
},
202+
function (err) {
203+
callback(err);
204+
}
205+
);
216206
},
217207

218-
/**
219-
* Waits for the bucketNotExists state by periodically calling the underlying S3.headBucket() operation
220-
* every 5 seconds (at most 20 times).
221-
*/
222208
waitForBucketNotExists: function (s3client, params, callback) {
223-
const maxAttempts = 20;
224-
let currentAttempt = 0;
225-
const delay = 5000;
226-
227-
const checkForBucketNotExists = () => {
228-
currentAttempt++;
229-
s3client.headBucket(params, function (err, data) {
230-
if (currentAttempt > maxAttempts) {
231-
callback(new Error("waitForBucketNotExists: max attempts exceeded"));
232-
} else if (err && err.name === "NotFound") {
233-
callback();
234-
} else {
235-
setTimeout(function () {
236-
checkForBucketNotExists();
237-
}, delay);
238-
}
239-
});
240-
};
241-
checkForBucketNotExists();
209+
bucketNotExists({ client: s3client }, params).then(
210+
function (data) {
211+
callback();
212+
},
213+
function (err) {
214+
callback(err);
215+
}
216+
);
242217
},
243218
};

0 commit comments

Comments
 (0)