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

test(cmd-api-server): fix flaky runtime-plugin-imports-test #1903

Merged
merged 1 commit into from
May 10, 2022

Commits on May 9, 2022

  1. test: jestify runtime-plugin-import test and fix flaky test

    Migrated test from Tap to Jest.
    
    File Path:
    packages/cactus-test-cmd-api-server/src/test/typescript/integration/runtime-plugin-imports.test.ts
    
    =======================================================================
    
    This is a flaky test case that can't be reliably reproduce. I've ran the
    test individually 40 times and all 40 times it has passed successfully.
    
    This error, however, seems to pop up only when the `yarn jest` command
    is run (when I ran the test individually).
    
    Based on the linked
    ["hint"](https://stackoverflow.com/a/50793993)
    from the issue, it seems like using `jest.useFakeTimers()` a good
    solution. However, using the `jest.useFakeTimers()` with`async/await`
    was not recommended.
    
    However, I found a [different source]
    (https://gist.github.com/apieceofbart/e6dea8d884d29cf88cdb54ef14ddbcc4#file-test-js-L58)
    that showed examples
    of how to use the `jest.useFakeTimers()`.
    Our original problem, however, is probably because the after the test
    environment is torn down, the second test file is trying to import
    files from the first environment, triggering the error
    ([explained here](jestjs/jest#11438 (comment))).
    
    So I've come to the solution of installing another node package:
    [node-cleanup](https://www.npmjs.com/package/node-cleanup) and running
    that within the afterAll at the very end of the test.
    
    My laptop can't take running the `yarn jest` script too much so I
    haven't seen it reproduce the error yet. (WOT ruhrow)
    
    _______________________edit below _________________________
    
    So it turns out that this flaky test due to libraries trying to third
    libraries trying to run after the test runs is a simple fix that was
    documented [here](https://testing-library.com/docs/using-fake-timers/)
    where we just add the `useRealTimer` in the `afterEach`. Lol so sorry!!
    
    =======================================================================
    
    This is a PARTIAL resolution to issue hyperledger-cacti#238
    
    Fixes hyperledger-cacti#1667
    
    Signed-off-by: awadhana <[email protected]>
    Signed-off-by: Youngone Lee <[email protected]>
    Signed-off-by: Peter Somogyvari <[email protected]>
    awadhana authored and petermetz committed May 9, 2022
    Configuration menu
    Copy the full SHA
    fcec902 View commit details
    Browse the repository at this point in the history