Skip to content

Commit ae21bf1

Browse files
committed
increase test timeout during (slow xplatform emulated) docker builds
1 parent 1f1b08f commit ae21bf1

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

.github/workflows/build-pack-publish.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525

2626
- run: >
2727
docker build .
28+
--build-arg TEST_TIMEOUT_SECONDS=30
2829
--tag node-bcrypt-builder
2930
--platform ${{ matrix.os }}/${{ matrix.arch }}
3031
- run: >
@@ -37,6 +38,7 @@ jobs:
3738
# build for Alpine:
3839
- run: >
3940
docker build -f Dockerfile-alpine .
41+
--build-arg TEST_TIMEOUT_SECONDS=30
4042
--tag node-bcrypt-builder-alpine
4143
--platform ${{ matrix.os }}/${{ matrix.arch }}
4244
- run: >

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ RUN echo "#log: ${project}: Running build" \
4545
&& npm run build
4646

4747
ARG RUN_TESTS=true
48+
ARG TEST_TIMEOUT_SECONDS=
4849

4950
RUN if "${RUN_TESTS}"; then \
5051
echo "#log ${project}: Running tests" \

Dockerfile-alpine

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ RUN echo "#log: ${project}: Running build" \
2929
&& npm run build
3030

3131
ARG RUN_TESTS=true
32+
ARG TEST_TIMEOUT_SECONDS=
3233

3334
RUN if "${RUN_TESTS}"; then \
3435
echo "#log ${project}: Running tests" \

test/repetitions.test.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
const bcrypt = require('../bcrypt');
22

33
const EXPECTED = 2500; //number of times to iterate these tests.)
4+
const { TEST_TIMEOUT_SECONDS } = process.env;
5+
let timeout = 5e3; // default test timeout
6+
7+
// it is necessary to increase the test timeout when emulating cross-architecture
8+
// environments (i.e. arm64 from x86-64 host) which have significantly reduced performance:
9+
if ( TEST_TIMEOUT_SECONDS )
10+
timeout = Number.parseInt(TEST_TIMEOUT_SECONDS, 10) * 1e3;
11+
12+
jest.setTimeout(timeout);
413

514
test('salt_length', () => {
615
expect.assertions(EXPECTED);
716

817
return Promise.all(Array.from({length: EXPECTED},
918
() => bcrypt.genSalt(10)
1019
.then(salt => expect(salt).toHaveLength(29))));
11-
}, 10e3)
20+
})
1221

1322
test('test_hash_length', () => {
1423
expect.assertions(EXPECTED);
1524
const SALT = '$2a$04$TnjywYklQbbZjdjBgBoA4e';
1625
return Promise.all(Array.from({length: EXPECTED},
1726
() => bcrypt.hash('test', SALT)
1827
.then(hash => expect(hash).toHaveLength(60))));
19-
}, 10e3)
28+
})
2029

2130
test('test_compare', () => {
2231
expect.assertions(EXPECTED);
2332
const HASH = '$2a$04$TnjywYklQbbZjdjBgBoA4e9G7RJt9blgMgsCvUvus4Iv4TENB5nHy';
2433
return Promise.all(Array.from({length: EXPECTED},
2534
() => bcrypt.compare('test', HASH)
2635
.then(match => expect(match).toEqual(true))));
27-
}, 10e3)
36+
})
2837

2938
test('test_hash_and_compare', () => {
3039
expect.assertions(EXPECTED * 3);
@@ -42,5 +51,5 @@ test('test_hash_and_compare', () => {
4251
return Promise.all([goodCompare, badCompare]);
4352
});
4453
}));
45-
}, 30e3);
54+
}, timeout * 3);
4655

0 commit comments

Comments
 (0)