Skip to content

Conversation

@Dexterp37
Copy link
Contributor

This implements the pings testing API, as discussed and designed in the related bug.

@Dexterp37 Dexterp37 self-assigned this Apr 14, 2021
@Dexterp37 Dexterp37 requested a review from brizental April 14, 2021 11:32
@Dexterp37 Dexterp37 marked this pull request as ready for review April 14, 2021 11:32
Copy link
Contributor

@brizental brizental left a comment

Choose a reason for hiding this comment

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

I am ok with the overall approach. I don't see any other way to implement this feature either. I'll move Bug 1682771 to P2 though. Disallowing test APIs outside of tests seems even more important with this feature.

@Dexterp37 Dexterp37 force-pushed the ping_testing_api branch 2 times, most recently from 2ae611a to 199583e Compare April 14, 2021 18:07
@Dexterp37 Dexterp37 requested a review from brizental April 14, 2021 18:09
Copy link
Contributor

@brizental brizental left a comment

Choose a reason for hiding this comment

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

Will continue on the tests I was doing yesterday, my concerns still remain. I explained what are these concerns on the comment I left on the tests code.

@Dexterp37
Copy link
Contributor Author

Ad discussed with @brizental , sadly we have no way to guarantee that metric calls executed after testBeforeNextSubmit get executed before the ping collection. This is due to the fact that the Glean.js dispatcher is asynchronous even in test mode (it's not in the other bindings). One way to make this happen would be to change the dispatcher to add "task dependencies", e.g. if task A has a dependency B, run B right before running A.

Sadly, that's a bigger change. I'm closing this PR.

@Dexterp37 Dexterp37 closed this Apr 15, 2021
@Dexterp37 Dexterp37 reopened this Apr 15, 2021
@Dexterp37
Copy link
Contributor Author

Let's give this another opportunity.

This commit adds testBeforeNextSubmit to execute a
validation function synchronously before the target ping
is collected.
@Dexterp37 Dexterp37 requested a review from brizental April 27, 2021 08:44
Comment on lines 119 to 122
// This guarantees that, when running tests, the promise returned by
// `testBeforeNextSubmit` is resolved after the ping is collected: this is
// needed to make sure calling the testing APIs on metrics behave consistently
// if tests run fast.
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, I think this comment is a bit confusing and the code speaks for itself.

Copy link
Contributor

Choose a reason for hiding this comment

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

Still think this comment is not necessary... But also wrong now? Specifically

// [...] this is
// needed to make sure calling the testing APIs on metrics behave consistently
// if tests run fast.

@Dexterp37 Dexterp37 requested a review from brizental April 27, 2021 14:01
Copy link
Contributor

@brizental brizental left a comment

Choose a reason for hiding this comment

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

r+wc

Comment on lines 119 to 122
// This guarantees that, when running tests, the promise returned by
// `testBeforeNextSubmit` is resolved after the ping is collected: this is
// needed to make sure calling the testing APIs on metrics behave consistently
// if tests run fast.
Copy link
Contributor

Choose a reason for hiding this comment

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

Still think this comment is not necessary... But also wrong now? Specifically

// [...] this is
// needed to make sure calling the testing APIs on metrics behave consistently
// if tests run fast.

* TODO: Only allow this function to be called on test mode (depends on Bug 1682771).
*
* @param callbackFn The asynchronous validation function to run in order to validate
* the ping content.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Align the second line with callbackFn.

sendIfEmpty: false,
});
await submitSync(ping);
const storedPings = await Context.pingsDatabase["store"]._getWholeStore();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can you rename this file to ping_type.spec.ts since we are here?

@Dexterp37 Dexterp37 merged commit b7a5234 into mozilla:main Apr 27, 2021
@Dexterp37 Dexterp37 deleted the ping_testing_api branch April 27, 2021 14:29
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.

2 participants