Skip to content

Commit

Permalink
increase test timeout during (slow xplatform emulated) docker builds
Browse files Browse the repository at this point in the history
  • Loading branch information
thom-nic committed Nov 2, 2023
1 parent 22b2d06 commit fdfa667
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-pack-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:

- run: >
docker build .
--build-arg TEST_TIMEOUT_SECONDS=120
--tag node-bcrypt-builder
--platform ${{ matrix.os }}/${{ matrix.arch }}
- run: >
Expand All @@ -37,6 +38,7 @@ jobs:
# build for Alpine:
- run: >
docker build -f Dockerfile-alpine .
--build-arg TEST_TIMEOUT_SECONDS=120
--tag node-bcrypt-builder-alpine
--platform ${{ matrix.os }}/${{ matrix.arch }}
- run: >
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ RUN echo "#log: ${project}: Running build" \
&& npm run build

ARG RUN_TESTS=true
ARG TEST_TIMEOUT_SECONDS=

RUN if "${RUN_TESTS}"; then \
echo "#log ${project}: Running tests" \
Expand Down
1 change: 1 addition & 0 deletions Dockerfile-alpine
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ RUN echo "#log: ${project}: Running build" \
&& npm run build

ARG RUN_TESTS=true
ARG TEST_TIMEOUT_SECONDS=

RUN if "${RUN_TESTS}"; then \
echo "#log ${project}: Running tests" \
Expand Down
17 changes: 13 additions & 4 deletions test/repetitions.test.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
const bcrypt = require('../bcrypt');

const EXPECTED = 2500; //number of times to iterate these tests.)
const { TEST_TIMEOUT_SECONDS } = process.env;
let timeout = 5e3; // default test timeout

// it is necessary to increase the test timeout when emulating cross-architecture
// environments (i.e. arm64 from x86-64 host) which have significantly reduced performance:
if ( TEST_TIMEOUT_SECONDS )
timeout = Number.parseInt(TEST_TIMEOUT_SECONDS, 10) * 1e3;

jest.setTimeout(timeout);

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

return Promise.all(Array.from({length: EXPECTED},
() => bcrypt.genSalt(10)
.then(salt => expect(salt).toHaveLength(29))));
}, 10e3)
})

test('test_hash_length', () => {
expect.assertions(EXPECTED);
const SALT = '$2a$04$TnjywYklQbbZjdjBgBoA4e';
return Promise.all(Array.from({length: EXPECTED},
() => bcrypt.hash('test', SALT)
.then(hash => expect(hash).toHaveLength(60))));
}, 10e3)
})

test('test_compare', () => {
expect.assertions(EXPECTED);
const HASH = '$2a$04$TnjywYklQbbZjdjBgBoA4e9G7RJt9blgMgsCvUvus4Iv4TENB5nHy';
return Promise.all(Array.from({length: EXPECTED},
() => bcrypt.compare('test', HASH)
.then(match => expect(match).toEqual(true))));
}, 10e3)
})

test('test_hash_and_compare', () => {
expect.assertions(EXPECTED * 3);
Expand All @@ -42,5 +51,5 @@ test('test_hash_and_compare', () => {
return Promise.all([goodCompare, badCompare]);
});
}));
}, 30e3);
}, timeout * 3);

0 comments on commit fdfa667

Please sign in to comment.