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

Standardise conditional testing fix #437

Merged
merged 5 commits into from
Aug 8, 2022

Conversation

tegefaulkes
Copy link
Contributor

@tegefaulkes tegefaulkes commented Aug 8, 2022

Description

This PR standardises how conditional testing with testIf and describeIf is used with new reified booleans.

Issues Fixed

Final checklist

  • Domain specific tests
  • Full tests
  • Lint fixed
  • Squash and rebased
  • Sanity check the final build

Moved `tests/utils.ts` to `tests/utils/utils.ts` and created `test/utils/index.ts`. Trying to keep the utils within one place.

Removed `setupGlobalAgent` code, #420 means it isn't used anymore.

Updating how we handle conditional testing utility's. we're switching to using reified booleans and just composing conditional boolean expression.

#434
@ghost
Copy link

ghost commented Aug 8, 2022

👇 Click on the image for a new way to code review
  • Make big changes easier — review code in small groups of related files

  • Know where to start — see the whole change at a glance

  • Take a code tour — explore the change with an interactive tour

  • Make comments and review — all fully sync’ed with github

    Try it now!

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map Legend

@CMCDragonkai
Copy link
Member

Can you make sure global is changed to globalThis?

@CMCDragonkai
Copy link
Member

You can use https://eslint.org/docs/latest/rules/no-restricted-globals to add a restriction to global. And provide a replacement for globalThis. I think it can be autofixed then.

tests/utils/index.ts Outdated Show resolved Hide resolved
@CMCDragonkai CMCDragonkai changed the title Feature conditional testing fix Standardise conditional testing fix Aug 8, 2022
@CMCDragonkai
Copy link
Member

I think the PR still needs a task list to be ticked off. The PR can have tasks that indicate pending things to be done that isn't about the issue.

@tegefaulkes
Copy link
Contributor Author

I didn't include the task list here since this PR leans more to review than drafting out the problem. I'll add it back in but any todos are covered by the review comments right now.

Creating `isPlatformX`, `isTestPlatformX` and `hasX` booleans to use for enabling tests.

Replaced usage of describeIf to use testIf for the tests within the describe block. This means jest shouldn't complain about empty test files if no tests run.

#434
…rms`, replaced with `testIf`

We're replacing these with `testIf` and `describeIf` and reified booleans.

#434
@tegefaulkes tegefaulkes force-pushed the feature-conditional_testing_fix branch from 6b79205 to 3bf5658 Compare August 8, 2022 05:45
@CMCDragonkai
Copy link
Member

CMCDragonkai commented Aug 8, 2022

I just did a quick check, and it is actually:

import * as testUtils from '../../utils';

That is the most common.

Not:

import * as testsUtils from '../../utils';

So I guess we keep it as testUtils for now?

This is because I can see there are other similar test.+Utils.

Hard to remember cause the directory is tests not test.

@tegefaulkes
Copy link
Contributor Author

Changed it to testUtils now.

.eslintrc Outdated Show resolved Hide resolved
We should be using `globalThis` to access global variables. A linting rule has been added to restrict usage of `global`.
@tegefaulkes tegefaulkes force-pushed the feature-conditional_testing_fix branch from 610fe52 to 8ae818b Compare August 8, 2022 05:57
@tegefaulkes
Copy link
Contributor Author

I'm re-triggering agent/service and nat tests in CI. Seems like they failed due to timeouts. It's just 3 tests in total so I think we're good to merge here.

@tegefaulkes
Copy link
Contributor Author

They timed out again.

 ● nodesCrossSignClaim › fails after receiving undefined singly signed claim

    thrown: "Exceeded timeout of 20000 ms for a hook.
    Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."

      31 |   let localId: NodeId;
      32 |   let remoteId: NodeId;
    > 33 |   beforeEach(async () => {
         |   ^
      34 |     dataDir = await fs.promises.mkdtemp(
      35 |       path.join(os.tmpdir(), 'polykey-test-'),
      36 |     );

      at tests/agent/service/nodesCrossSignClaim.test.ts:33:3
      at Object.<anonymous> (tests/agent/service/nodesCrossSignClaim.test.ts:20:1)
      
  ● endpoint independent NAT traversal › node1 behind EIM NAT connects to node2 behind EIM NAT via seed node
    thrown: "Exceeded timeout of 40000 ms for a test.
    Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
      292 |     globalThis.defaultTimeout * 2,
      293 |   );
    > 294 |   testUtils.testIf(supportsNatTesting)(
          |                                       ^
      295 |     'node1 behind EIM NAT connects to node2 behind EIM NAT via seed node',
      296 |     async () => {
      297 |       const {
      at tests/nat/endpointIndependentNAT.test.ts:294:39
      at Object.<anonymous> (tests/nat/endpointIndependentNAT.test.ts:15:1)
      

I don't think there's a problem with the tests themselves. I know the agent/service test is passing locally. Barring a deeper dive into the problem I think we can only increase the timeout for this.

Want me to look into it now or merge now and fix later?

@CMCDragonkai
Copy link
Member

Ok leaving the time outs to a later PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Standardise Conditional Testing Utilties
2 participants