Skip to content

Conversation

@Dexterp37
Copy link
Contributor

This guarantees the dispatcher is always available even before the Glean initialization. We need this because our APIs can be used before initialization, to perform fast recording of metrics.

@Dexterp37 Dexterp37 requested a review from brizental April 26, 2021 14:55
@Dexterp37 Dexterp37 self-assigned this Apr 26, 2021
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.

Would you mind also adding a simple test to ensure this behaviour?

private static _instance: Context;

private _dispatcher!: Dispatcher;
private _dispatcher!: Dispatcher | null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this need to be null? Can't we initialize the dispatcher on the Context's constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs to be null because we can't really tear down the whole Context when we reset Glean, because we need to retain the storage. So we do a "soft reset" by nulling out the dispatcher in testReset

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I would prefer private _dispatcher?: Dispatcher;, but no strong requirement for this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes it undefined though,

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but this a very philosophical thing (null vs undefined) and makes no real difference here. Feel free to ignore the request ;)

@Dexterp37
Copy link
Contributor Author

Would you mind also adding a simple test to ensure this behaviour?

Now that we're properly resetting, all the tests fail without the fix (instantiating the dispatcher if not available). Any test I might add would basically be the same, but let me see what I can pull off

This guarantees the dispatcher is always available
even before the Glean initialization. We need this
because our APIs can be used before initialization,
to perform fast recording of metrics.
@Dexterp37 Dexterp37 merged commit 5a864ce into mozilla:main Apr 26, 2021
@Dexterp37 Dexterp37 deleted the fix_dispatcher branch April 26, 2021 15:44
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