Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buggy time dependency in attack-cpu-background tests #38

Open
kgruszka opened this issue Oct 29, 2020 · 0 comments
Open

Buggy time dependency in attack-cpu-background tests #38

kgruszka opened this issue Oct 29, 2020 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@kgruszka
Copy link
Contributor

Description/Context

Test assertion in attack-cpu-background randomly failed probably due to a buggy timer resolution:

describe('when the process takes some time to initialise', () => {
  it('waits', async () => {
    onFn.mockImplementationOnce((_msg, cb) => setTimeout(cb, 10));
    const attack = new BackgroundCPUAttack({ threads: 1 });
    const time = Date.now();
    await attack.start();
    expect(Date.now() - time).toBeGreaterThanOrEqual(10);
  });
});

It occurred once while I was developing locally and during the execution of GA. Sadly the job was rerun and the logs are lost.
I've executed the tests in a loop dozens of times and could not reproduce 🤔.

Expected behavior

I expect the tests to pass always if there is no bug in code.

Actual behavior

A single test that is dependant on time fails occasionally.

Code to reproduce

Hard to reproduce but just

npm t

Possible fix

Change test implementation to use mocked timers and avoid time dependency.

Checklist

@kgruszka kgruszka added enhancement New feature or request good first issue Good for newcomers labels Oct 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant