events: Fix races in stream creation event and add tests.

This fixes 2 issues:
* Being added to an invite_only stream did not correctly update the
  "streams" key of the initial state.

* Once that's resolved, subscribe_to_stream when called on a
  nonexistant stream would both send a "create" event (from
  create_stream_if_needed) and an "occupy" event (from
  bulk_add_subscriptions).

  The second event should just be suppressed in that case, and this
  implements that suppression.
This commit is contained in:
Tim Abbott
2017-03-23 21:49:23 -07:00
parent 8eb020d190
commit eb19a25aba
5 changed files with 41 additions and 19 deletions

View File

@@ -417,10 +417,11 @@ class ZulipTestCase(TestCase):
realm = get_realm_by_email_domain(email)
try:
stream = get_stream(stream_name, realm)
from_creation = False
except Stream.DoesNotExist:
stream, _ = create_stream_if_needed(realm, stream_name)
stream, from_creation = create_stream_if_needed(realm, stream_name)
user_profile = get_user_profile_by_email(email)
bulk_add_subscriptions([stream], [user_profile])
bulk_add_subscriptions([stream], [user_profile], from_creation=from_creation)
return stream
def unsubscribe_from_stream(self, email, stream_name):