Skip to content

Commit fb6d175

Browse files
committed
perf: wait for local ddb to be ready instead of waiting for 1s
1 parent 6ea115d commit fb6d175

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

setup.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports = async function () {
3838
try {
3939
const {TableNames: tableNames} = await Promise.race([
4040
dynamoDB.listTables({}),
41-
new Promise(resolve => setTimeout(resolve, 1000))
41+
waitForLocalhost(DEFAULT_PORT)
4242
]);
4343
await deleteTables(dynamoDB, tableNames); // cleanup leftovers
4444
} catch (err) {
@@ -54,7 +54,7 @@ module.exports = async function () {
5454

5555
global.__DYNAMODB__ = await DynamoDbLocal.launch(port, null, options);
5656

57-
await waitForLocalhost({port: DEFAULT_PORT, useGet: true, path: '/'});
57+
await waitForLocalhost(DEFAULT_PORT);
5858
}
5959
}
6060

wait-for-localhost.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@
66

77
const http = require('http');
88

9-
const waitForLocalhost = options => {
10-
options = {...options};
11-
9+
const waitForLocalhost = port => {
1210
return new Promise(resolve => {
1311
const retry = () => setTimeout(main, 200);
1412

15-
const method = options.useGet ? 'GET' : 'HEAD';
16-
1713
const main = () => {
18-
const request = http.request({method, port: options.port, path: options.path}, response => {
14+
const request = http.request({method: 'GET', port, path: '/'}, response => {
1915
if (response.statusCode === 400) {
2016
return resolve();
2117
}

0 commit comments

Comments
 (0)