mozilla/talkilla — pull request #385 by Standard8 (2014-01-26 16:14:32+00:00)
Title: Ensure tkWorker.contactsDb.add is stubbed, and add tests for ensuring we add contacts at the right time

This is to fix the [intermittent failures in the frontend worker tests](https://trello.com/c/MXiQKrki).

The primary issue is that tkWorker.contactsDb.add is not stubbed on some of the incoming spa messages - so when various tests hit those instances, there's an async add that is going on.

In the case of the recently added InstantShare tests, which are calling add, these happen right before the tkWorker tests - which don't stub contactsDb and try to open/drop it frequently. In the failure cases, it appears the add is ongoing whilst the drop is still happening.

The changes in this PR ensure the add is stubbed, and provides tests for where the adds are taking place. This will mean the intermittent failures aren't hit.

It feels like tkWorker should be using a mock/stub of the contactsDb rather than trying to use it directly, however, updating the tests appeared complex, so I'll discuss this during the week.