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

Dont use pendingEventsDispatcher with user defined eventDispatcher #289

Merged

Conversation

jordangarcia
Copy link
Contributor

Summary

The is an edge case where the sendPendingEvents() mechanism keeps sending events because a custom eventDispatcher never invoked the callback() denoting the request completed. This leads to events piling up in localStorage and sending every event each time the SDK is initialized.

To prevent this only use the pendingEventDispatcher if the default event dispatcher is used, since this guarantees the callback is properly called.

Test plan

  • Added unit tests

Issues

  • OASIS-4887

@coveralls
Copy link

Coverage Status

Coverage increased (+0.005%) to 97.604% when pulling 9d1d9de on jordan/only-wrap-default-event-dispatcher-pending into d0ac882 on master.

2 similar comments
@coveralls
Copy link

Coverage Status

Coverage increased (+0.005%) to 97.604% when pulling 9d1d9de on jordan/only-wrap-default-event-dispatcher-pending into d0ac882 on master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.005%) to 97.604% when pulling 9d1d9de on jordan/only-wrap-default-event-dispatcher-pending into d0ac882 on master.

@coveralls
Copy link

coveralls commented Jun 10, 2019

Coverage Status

Coverage increased (+0.005%) to 97.604% when pulling e25f922 on jordan/only-wrap-default-event-dispatcher-pending into 4c65f58 on master.

@jordangarcia jordangarcia force-pushed the jordan/only-wrap-default-event-dispatcher-pending branch from 9d1d9de to 1ed3859 Compare June 10, 2019 18:50
});

describe('when an eventDispatcher is passed in', function() {
it('should wrap the default eventDispatcher and invoke sendPendingEvents', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should say 'should not wrap...' right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch

if (config.eventDispatcher == null) { // eslint-disable-line eqeqeq
// only wrap the event dispatcher with pending events retry if the user didnt override
eventDispatcher = new eventProcessor.LocalStoragePendingEventsDispatcher({
eventDispatcher: defaultEventDispatcher,
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that we we no longer allow a custom eventDispatcher to be used with LocalStoragePendingEventsDispatcher, does passing eventDispatcher to LocalStoragePendingEventsDispatcher still make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, you mean the idea of having an event dispatcher that wraps another event dispatcher.

Probably isn't the most ideal design, but I dont hate it. If we just made this the default event dispatcher, without wrapping it, then we'd be replacing the existing defaultEventDispatcher implementation. That could be a bit strange for people using the eventDispatcher in a custom manner.

When we made the decision to only wrap the defaultEventDispatcher, I did feel a bit safer about this pattern then replacement.

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense to me. Initially, I thought this wrapper pattern was weird given that it only ever wraps one thing, but it is safe, and I like that pending-events-related logic is isolated.

@mjc1283 mjc1283 self-requested a review June 11, 2019 20:49
@jordangarcia jordangarcia force-pushed the jordan/only-wrap-default-event-dispatcher-pending branch from 9744b09 to 9a351c0 Compare June 11, 2019 21:56
@jordangarcia jordangarcia force-pushed the jordan/only-wrap-default-event-dispatcher-pending branch from 9a351c0 to e25f922 Compare June 12, 2019 16:38
Copy link
Contributor

@mikeproeng37 mikeproeng37 left a comment

Choose a reason for hiding this comment

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

Lgtm!

@jordangarcia jordangarcia merged commit f0980f5 into master Jun 12, 2019
mikeproeng37 pushed a commit that referenced this pull request Aug 20, 2019
)

* Dont use pendingEventsDispatcher with user defined eventDispatcher

* Update test
@mikeproeng37 mikeproeng37 deleted the jordan/only-wrap-default-event-dispatcher-pending branch September 23, 2019 22:12
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.

None yet

4 participants