koa-health / mixpanel_analytics

A dart wrapper on the mixpanel REST API to be used in Flutter applications.
https://pub.dev/packages/mixpanel_analytics
MIT License
19 stars 26 forks source link

test(analytics): fix race condition making test to fail #17

Closed jordins closed 3 years ago

jordins commented 3 years ago

Description

The tests sometimes failed because there is a timer scheduled to upload events and to store them in storage in case of failure. The tests calls a dispose function which stops the timer but the already scheduled requests from the previous timer is going to happen anyway. The test after calling dispose resets the mocks, therefore when the "save event to storage" function kicks in it crashes.

Implementation

The solution is simply to remove the reset of the mock because we don't need it since we are generating a new mock on each test.

This is not solving the issue of having pending operations after stoping the timer but does the job.

We've also done some cleanup of unnecessary "nullifications" and used the new later keyword.