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

perf: wrap tests in check to make sure app is ready when they run #5317

Merged
merged 13 commits into from
Jul 26, 2019

Conversation

kieckhafer
Copy link
Member

@kieckhafer kieckhafer commented Jul 12, 2019

Resolves #5315
Impact: minor
Type: performance

Issue

CI test-app tests intermittently fail with a timeout, but usually pass on a second or third run.

Solution

Wrap each test in Reaction.onAppStartupComplete(() => { /* tests */ }) to make sure app is ready before tests run.

Breaking changes

None

Testing

  1. run tests a multiple times
  2. see that they pass every time

@kieckhafer kieckhafer marked this pull request as ready for review July 12, 2019 17:55
@kieckhafer kieckhafer changed the title [WIP] perf: wrap tests in check to make sure app is ready when they run perf: wrap tests in check to make sure app is ready when they run Jul 12, 2019
@kieckhafer
Copy link
Member Author

@aldeed @focusaurus not sure the best way to test this, since it was an intermittent thing. I ran locally and it passed a couple times, and it passed the first time when pushing it to CI, so that's a good sign at least.

@focusaurus
Copy link
Contributor

focusaurus commented Jul 12, 2019

I'm worried putting the describe calls inside the event handler function might make mocha unaware that the tests even exist. Are you sure these will run every time? I'd be inclined to provide a helper function we can wrap just around the it handler like pseudocode:

import { appIsReady } from "some-test-utils-module";
describe("used outside of a connection", () => {
  ConnectionDataStore.set("key", "val");
  it(
    "sets/gets cached data",
    appIsReady(() => {
      ConnectionDataStore.set("key", "val");

      expect(ConnectionDataStore.get("key")).to.equal("val");
      expect(ConnectionDataStore.get("key")).to.equal("val");
    })
  );
});

Or use appIsReady around the describe handler function if the code in there needs to wait as well.

@focusaurus
Copy link
Contributor

Could we also do this in a before() handler?

@kieckhafer
Copy link
Member Author

@focusaurus most of the tests were already wrapped in this Reaction.onAppStartupComplete(() => {}), I only updated about 1/3rd of them so yes, if they've been working up until now, then I don't think this will change that.

@aldeed
Copy link
Contributor

aldeed commented Jul 12, 2019

@focusaurus You are correct. Looking at the logging, it appears that tests passed because no tests were found. I remember thinking this might be happening at some point but forgot to check it. Sorry!

I like the idea of doing a before handler instead, and calling done() within Reaction.onAppStartupComplete. Something like

before((done) => {
  Reaction.onAppStartupComplete(() => {
    Fixtures();
    done();
  });
});

Didn't try it so I'm not sure it works. If the file calls Fixtures, that needs to happen after startup is complete. That was the original reason I wrapped some of them.

@kieckhafer the output when the tests run should say "N passed", where N is the number of it calls we have in the app-test files. On CI now it says "0 passed" so it's not seeing any of them.

@focusaurus
Copy link
Contributor

OK I think that makes more sense. Already have lots of nesting due to the mocha API. I think this type of thing is a poster child for why before() exists.

@kieckhafer
Copy link
Member Author

@aldeed does the before need to be done inside each describe? Or once per file?

@focusaurus
Copy link
Contributor

I think you can have a top-level (not nested) before once per file before any describe calls and that should work.

@spencern
Copy link
Contributor

@kieckhafer have you had a chance to look at this recently?

@kieckhafer
Copy link
Member Author

@spencern been caught up with some other time-sensitive work this morning, will circle back once that is finished up.

@kieckhafer
Copy link
Member Author

Made all the updates mentioned here, wrapping it all in a before and the issue still persists.

@focusaurus
Copy link
Contributor

Bummer. Not sure just from code inspection what the issue is then.

@aldeed
Copy link
Contributor

aldeed commented Jul 18, 2019

I will check out this branch and spend a couple minutes seeing if anything I can think of works.

They are now all running reliably, but
issues with the fixtures and the tests
need to be fixed

Signed-off-by: Eric Dobbertin <[email protected]>
@aldeed
Copy link
Contributor

aldeed commented Jul 18, 2019

@kieckhafer @focusaurus I pushed a commit that has all of the Meteor app tests being reliably detected and run. I couldn't get many of the tests to be found, and then I noticed that they were all ones that were moved to /tests/meteor folder. So I decided to Google it, and it turns out that Meteor test runner ignores test files within /tests folder. Makes perfect sense, right? 🙄

Anyway I moved those to be in /imports and now they run.

The remaining problem is that since these haven't been running for awhile, there are at least 24 tests that need to be investigated and fixed. Most of these are probably issues with the mock data or APIs that changed after the tests stopped running. I don't have time to go through any more right now.

@aldeed
Copy link
Contributor

aldeed commented Jul 26, 2019

@kieckhafer @focusaurus I think what's happening with the eslint check is that it's not omitting deleted / moved files from the list. Maybe there is a git diff option to omit those, or you could loop through and check for existence before passing to ESLint command.

@kieckhafer
Copy link
Member Author

@aldeed @focusaurus added a check for deleted files: --diff-filter=d, that seemed to fix the issue.

Signed-off-by: Erik Kieckhafer <[email protected]>
@kieckhafer kieckhafer merged commit d5f4058 into develop Jul 26, 2019
@kieckhafer kieckhafer deleted the test-kieckhafer-wrapInIsAppReady branch July 26, 2019 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants