diff --git a/.github/workflows/build-pack-publish.yml b/.github/workflows/build-pack-publish.yml index 3317e66..2e6147c 100644 --- a/.github/workflows/build-pack-publish.yml +++ b/.github/workflows/build-pack-publish.yml @@ -25,6 +25,7 @@ jobs: - run: > docker build . + --build-arg TEST_TIMEOUT_SECONDS=30 --tag node-bcrypt-builder --platform ${{ matrix.os }}/${{ matrix.arch }} - run: > @@ -37,6 +38,7 @@ jobs: # build for Alpine: - run: > docker build -f Dockerfile-alpine . + --build-arg TEST_TIMEOUT_SECONDS=30 --tag node-bcrypt-builder-alpine --platform ${{ matrix.os }}/${{ matrix.arch }} - run: > diff --git a/Dockerfile b/Dockerfile index da3b22f..2802baf 100755 --- a/Dockerfile +++ b/Dockerfile @@ -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" \ diff --git a/Dockerfile-alpine b/Dockerfile-alpine index 7ee6206..7570cfe 100755 --- a/Dockerfile-alpine +++ b/Dockerfile-alpine @@ -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" \ diff --git a/test/repetitions.test.js b/test/repetitions.test.js index 7423c08..63ff407 100644 --- a/test/repetitions.test.js +++ b/test/repetitions.test.js @@ -1,6 +1,15 @@ 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); @@ -8,7 +17,7 @@ test('salt_length', () => { return Promise.all(Array.from({length: EXPECTED}, () => bcrypt.genSalt(10) .then(salt => expect(salt).toHaveLength(29)))); -}, 10e3) +}) test('test_hash_length', () => { expect.assertions(EXPECTED); @@ -16,7 +25,7 @@ test('test_hash_length', () => { return Promise.all(Array.from({length: EXPECTED}, () => bcrypt.hash('test', SALT) .then(hash => expect(hash).toHaveLength(60)))); -}, 10e3) +}) test('test_compare', () => { expect.assertions(EXPECTED); @@ -24,7 +33,7 @@ test('test_compare', () => { 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); @@ -42,5 +51,5 @@ test('test_hash_and_compare', () => { return Promise.all([goodCompare, badCompare]); }); })); -}, 30e3); +}, timeout * 3);