oaeproject/Hilary — pull request #960 by mrvisser (2014-07-07 21:23:25+00:00)
Title: Intermittent test failure: Email scheduling is not synchronized in tests

Currently when activity is delivered, we listen to the delivery event which eventually schedules email to be sent. The process in `collectAndFetchAllEmails` is currently:

1. Collect activity -- this fires the ACTIVITIES_DELIVERED events
2. Collect all scheduled emails
3. Listen to the `debugSent` event for all emails that were sent

However in between step 1 and 2, there is no guarantee that there was sufficient time for the emails to be schedule for the email, therefore step 2 collects no scheduled emails, and you wind up with:

```
2) Notifications Mail deduplication verify mails for the same activity and the same user are only sent once:
Uncaught AssertionError: 0 == 2
at /Users/branden/Source/oaeproject/Hilary/node_modules/oae-activity/tests/test-notifications.js:293:40
at /Users/branden/Source/oaeproject/Hilary/node_modules/oae-email/lib/test/util.js:102:28
at allDone (/Users/branden/Source/oaeproject/Hilary/node_modules/oae-activity/lib/internal/email.js:182:20)
at /Users/branden/Source/oaeproject/Hilary/node_modules/oae-activity/lib/internal/buckets.js:119:16
at _collectBuckets (/Users/branden/Source/oaeproject/Hilary/node_modules/oae-activity/lib/internal/buckets.js:138:16)
at /Users/branden/Source/oaeproject/Hilary/node_modules/oae-activity/lib/internal/buckets.js:149:16
at /Users/branden/Source/oaeproject/Hilary/node_modules/oae-activity/lib/internal/buckets.js:215:28
at /Users/branden/Source/oaeproject/Hilary/node_modules/oae-util/lib/locking.js:94:20
at b (domain.js:183:18)
at try_callback (/Users/branden/Source/oaeproject/Hilary/node_modules/redis/index.js:573:9)
```

... intermittently. This is probably a fairly large source of intermittent test failures in email currently along with #956