Skip to content

Resolve Performance test failures and add unit tests for proto3 data transport format #2503

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

Closed
wants to merge 1 commit into from

Conversation

zijianjoy
Copy link
Contributor

  1. Add a timeout wait function to cc_service.test.ts because the first setTimeout() happens before fake timer is used. (Resolve test failure from Travis CI)
  2. Remove .only() from cc_service.test.ts file so other Fireperf test can be run.
  3. Add unit tests to validate proto3 format serialization works as expected.

Comment on lines 60 to +61
it('throws an error when logging an empty message', () => {
const logger = new Logger('@firebase/performance/cc');
expect(() => {
testCCHandler(logger, LogLevel.SILENT, '');
}).to.throw;
waitForFirstTimeout(() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I tried this out and I don't think any of these 3 tests actually run, as written. When a test is async you have to handle it with a done() or by returning a promise, or else Mocha will just go on to the next test and not wait for the async part to finish, and count it as passed. I think as the code currently stands, you can put anything in the callback and it will pass.

If you wanted it to reach the expect line you'd want

    it('throws an error when logging an empty message', (done) => {
      waitForFirstTimeout(() => {
        const logger = new Logger('@firebase/performance/cc');
        expect(() => {
          testCCHandler(logger, LogLevel.SILENT, '');
        }).to.throw;
       done();
      });
    });

Or instead of using done(), return a promise.

I'm able to get around the described problem (doing a real time offset before tests begin, which allows all imported instances of ccHandler to reach the initial setTimeout callback of processQueue) with this block, which runs before all tests.

before((done) => {
      setTimeout(() => done(), INITIAL_SEND_TIME_DELAY_MS);
    });

You don't need to run this before each test, just all tests, because all instances of the top level call to processQueue runs before any tests which I don't think is what you expect or want, so, can I suggest not calling processQueue automatically at the top level of cc_service.ts but instead providing an init function to run it, which perf_logger.ts can call at the top. This way each test can call the init on its own time and not have to do any kind of setTimeout workaround.

Also another warning, if this code worked as intended (using done() or a promise return to pause the async test until timeout ends and the expect runs), the waitForFirstTimeout would wait on the real time clock, and I think it's set to 100 seconds (10 * 10 * 1000) and on the real time clock that would be bad.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Christina for the detailed feedback and tried with the testing! I have updated the logic in cc_service.ts to provide an init function and updated tests to include fake timer inside describe(). Since this test update is separated from feature branch merge in this PR (fireperf-update-log-format), I created master branch PR for this #2506. Thank you!

@zijianjoy zijianjoy closed this Jan 14, 2020
@firebase firebase locked and limited conversation to collaborators Feb 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants