I'm experiencing an issue where my Jasmine/Karma tests pass locally but fail in my CI environment (GitLab CI) with a timeout error:
Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
I tried increasing the timeout in my Karma configuration, but the tests still time out in CI. It appears that some asynchronous operations never resolve in CI, even though everything runs fine on my local machine.
Here’s a snippet of my CI configuration:
.admin-test-base:
image: ${BASE_IMAGE}
variables:
GIT_STRATEGY: 'none'
GIT_SUBMODULE_STRATEGY: recursive
PUPPETEER_ARGS: '--no-sandbox --disable-setuid-sandbox --disable-dev-shm-usage'
before_script:
- apt-get update # see .md#setting-up-chrome-linux-sandbox
- apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libnss3 lsb-release xdg-utils wget
- apt-get install -y build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
- cd ${DIR_NAME}
- npm ci
script:
- NODE_ENV=test ./node_modules/karma/bin/karma start karma.conf.js
test-admin:
stage: test-admin
extends: .admin-test-base
variables:
DIR_NAME: 'admin'
And here’s a snippet from one of the failing tests:
it('dereferenceXxx', async () => {
spyOn(Promise, 'all').and.returnValue(Promise.resolve([[], {}]));
spyOn(_, 'get').and.returnValue([{
field_name: 'test_field',
relation: 'ONE_TO_MANY',
remote_model: { name: 'test_model', app: 'test_app' },
local_model: { name: 'test_local', app: 'test_local_app' },
hints: [{ pk: '1', text: '-' }]
}]);
const returnValue = await dereferenceXxx(1337, false, {});
expect(Object.keys(returnValue).sort()).toEqual(
['title', 'model', 'pageMode', 'editMode', 'breadcrumbs', 'detail', 'pages', 'list'].sort()
);
await dereferenceXxx(1337, false, { activeRelationships: 'test_rel' });
});
Has anyone encountered similar issues where tests hang in CI even though they pass locally? Any guidance on diagnosing or resolving this problem would be appreciated.
I'm experiencing an issue where my Jasmine/Karma tests pass locally but fail in my CI environment (GitLab CI) with a timeout error:
Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
I tried increasing the timeout in my Karma configuration, but the tests still time out in CI. It appears that some asynchronous operations never resolve in CI, even though everything runs fine on my local machine.
Here’s a snippet of my CI configuration:
.admin-test-base:
image: ${BASE_IMAGE}
variables:
GIT_STRATEGY: 'none'
GIT_SUBMODULE_STRATEGY: recursive
PUPPETEER_ARGS: '--no-sandbox --disable-setuid-sandbox --disable-dev-shm-usage'
before_script:
- apt-get update # see https://github/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#setting-up-chrome-linux-sandbox
- apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libnss3 lsb-release xdg-utils wget
- apt-get install -y build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev
- cd ${DIR_NAME}
- npm ci
script:
- NODE_ENV=test ./node_modules/karma/bin/karma start karma.conf.js
test-admin:
stage: test-admin
extends: .admin-test-base
variables:
DIR_NAME: 'admin'
And here’s a snippet from one of the failing tests:
it('dereferenceXxx', async () => {
spyOn(Promise, 'all').and.returnValue(Promise.resolve([[], {}]));
spyOn(_, 'get').and.returnValue([{
field_name: 'test_field',
relation: 'ONE_TO_MANY',
remote_model: { name: 'test_model', app: 'test_app' },
local_model: { name: 'test_local', app: 'test_local_app' },
hints: [{ pk: '1', text: '-' }]
}]);
const returnValue = await dereferenceXxx(1337, false, {});
expect(Object.keys(returnValue).sort()).toEqual(
['title', 'model', 'pageMode', 'editMode', 'breadcrumbs', 'detail', 'pages', 'list'].sort()
);
await dereferenceXxx(1337, false, { activeRelationships: 'test_rel' });
});
Has anyone encountered similar issues where tests hang in CI even though they pass locally? Any guidance on diagnosing or resolving this problem would be appreciated.
Share Improve this question asked Mar 25 at 12:01 Tsygankov AlexanderTsygankov Alexander 215 bronze badges 1- Please fix your code so it's syntactically valid. A complete, runnable minimal reproducible example would make this easier to answer. Thanks. – ggorlen Commented Mar 26 at 5:02
1 Answer
Reset to default 0Maybe this will help someone.
I didn’t fully understand what the underlying problem was, but after I rewrote the CI job and stopped running tests inside my custom Docker image, the tests started to pass. The updated job looks like this.
.admin-test-base:
before_script:
- apt-get update
- apt-get install -yq gconf-service libasound2 libatk1.0-0 libc6 libcairo2
libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libgconf-2-4
libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0
libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1
libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1
libxss1 libxtst6 ca-certificates fonts-liberation libnss3 lsb-release
xdg-utils wget build-essential libcairo2-dev libpango1.0-dev libjpeg-dev
libgif-dev librsvg2-dev
- cd ${DIR_NAME}
- npm ci
script:
- npm run test
- cp -r ${CI_PROJECT_DIR}/${DIR_NAME}/coverage ${CI_PROJECT_DIR}/coverage
coverage: '/(\d*.?\d+)%/'
artifacts:
when: 'on_success'
paths:
- coverage/*
test-admin:
image: node:22-bullseye
stage: test-admin
extends: .admin-test-base
allow_failure: false
variables:
DIR_NAME: 'admin'