|
@@ -26,6 +26,7 @@ import os.path
|
|
|
import pytest
|
|
|
import requests
|
|
|
import six
|
|
|
+import time
|
|
|
import inspect
|
|
|
from uuid import uuid4
|
|
|
from contextlib import contextmanager
|
|
@@ -53,6 +54,7 @@ from rest_framework.test import APITestCase as BaseAPITestCase
|
|
|
from six.moves.urllib.parse import urlencode
|
|
|
|
|
|
from sentry import auth
|
|
|
+from sentry import eventstore
|
|
|
from sentry.auth.providers.dummy import DummyProvider
|
|
|
from sentry.auth.superuser import (
|
|
|
Superuser,
|
|
@@ -680,6 +682,26 @@ class SnubaTestCase(BaseTestCase):
|
|
|
self.store_group(stored_group)
|
|
|
return stored_event
|
|
|
|
|
|
+ def wait_for_event_count(self, project_id, total, attempts=2):
|
|
|
+ """
|
|
|
+ Wait until the event count reaches the provided value or until attempts is reached.
|
|
|
+
|
|
|
+ Useful when you're storing several events and need to ensure that snuba/clickhouse
|
|
|
+ state has settled.
|
|
|
+ """
|
|
|
+ # Verify that events have settled in snuba's storage.
|
|
|
+ # While snuba is synchronous, clickhouse isn't entirely synchronous.
|
|
|
+ attempt = 0
|
|
|
+ snuba_filter = eventstore.Filter(project_ids=[project_id])
|
|
|
+ while attempt < attempts:
|
|
|
+ events = eventstore.get_events(snuba_filter)
|
|
|
+ if len(events) >= total:
|
|
|
+ break
|
|
|
+ attempt += 1
|
|
|
+ time.sleep(0.05)
|
|
|
+ if attempt == attempts:
|
|
|
+ assert False, "Could not ensure event was persisted within 10 attempts"
|
|
|
+
|
|
|
def store_session(self, session):
|
|
|
assert (
|
|
|
requests.post(
|