keenlabs / KeenClient-iOS

Official iOS client for the Keen IO API. Build analytics features directly into your iOS apps.
https://keen.io/docs
MIT License
78 stars 56 forks source link

Fix cases where global state wasn't being reset between tests. #197

Closed baumatron closed 7 years ago

baumatron commented 7 years ago

KeenClient's sharedClient returns nil when no projectid is set, which leads to nasty side-effects for test setup. Basically, any write or read key that was set wasn't getting cleared by setUp because of this, and neither was currentLocation.

The workaround is to carefully reset state to defaults and set the projectid to nil last. Changes to sharedClient behavior proposed by PR #193 will improve this situation because sharedClient will no longer return nil.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.3%) to 64.14% when pulling cc9a0fcdf648d7bab363dbfdbaa965460f96fb14 on fix_test_setup into 826714a5f856f66cdb68453a5f719303fc6c12e1 on master.

masojus commented 7 years ago

I did want to ask, just to be sure, if anywhere else in the tests calls setProjectID and sets it to nil? If that runs before the teardown, that would be the same problem, right? I imagine you checked that, but just in case...

baumatron commented 7 years ago

Yeah, there aren't tests that are setting projectId to nil. There is one where sharedClientWIthProjectID:nil is called, but that short circuits when it validates the parameter and returns nil before actually assigning the project id.