mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-28 09:16:49 +01:00
92bd10ffa5
* Speed up EE tests by not destroying tables
* Fix broken tests
* Speed up tests by not running migrations
* Fix last test
* req file?
* caching
* Parallel
* revert exp
* debug without parallel
* Revert "debug without parallel"
This reverts commit 83b3ad633f
.
* Undo parallel tests
* Speed up more tests
* use final
* correct final
* print exception
* more prints
* move test
* add filter
* remove duplicate test
* prints here
* test wait
* set variable in query
* remove mutations_sync
* cleanup
Co-authored-by: eric <eeoneric@gmail.com>
97 lines
2.8 KiB
Python
97 lines
2.8 KiB
Python
import pytest
|
|
from infi.clickhouse_orm import Database
|
|
|
|
from ee.clickhouse.client import sync_execute
|
|
from posthog.settings import (
|
|
CLICKHOUSE_DATABASE,
|
|
CLICKHOUSE_HTTP_URL,
|
|
CLICKHOUSE_PASSWORD,
|
|
CLICKHOUSE_USER,
|
|
CLICKHOUSE_VERIFY,
|
|
)
|
|
from posthog.test.base import TestMixin
|
|
|
|
|
|
def reset_clickhouse_tables():
|
|
# Reset clickhouse tables to default before running test
|
|
# Mostly so that test runs locally work correctly
|
|
from ee.clickhouse.sql.cohort import CREATE_COHORTPEOPLE_TABLE_SQL, DROP_COHORTPEOPLE_TABLE_SQL
|
|
from ee.clickhouse.sql.events import DROP_EVENTS_TABLE_SQL, EVENTS_TABLE_SQL
|
|
from ee.clickhouse.sql.person import (
|
|
DROP_PERSON_DISTINCT_ID_TABLE_SQL,
|
|
DROP_PERSON_STATIC_COHORT_TABLE_SQL,
|
|
DROP_PERSON_TABLE_SQL,
|
|
PERSON_STATIC_COHORT_TABLE_SQL,
|
|
PERSONS_DISTINCT_ID_TABLE_SQL,
|
|
PERSONS_TABLE_SQL,
|
|
)
|
|
from ee.clickhouse.sql.plugin_log_entries import DROP_PLUGIN_LOG_ENTRIES_TABLE_SQL, PLUGIN_LOG_ENTRIES_TABLE_SQL
|
|
from ee.clickhouse.sql.session_recording_events import (
|
|
DROP_SESSION_RECORDING_EVENTS_TABLE_SQL,
|
|
SESSION_RECORDING_EVENTS_TABLE_SQL,
|
|
)
|
|
|
|
# REMEMBER TO ADD ANY NEW CLICKHOUSE TABLES TO THIS ARRAY!
|
|
TABLES_TO_CREATE_DROP = [
|
|
(DROP_EVENTS_TABLE_SQL, EVENTS_TABLE_SQL),
|
|
(DROP_PERSON_TABLE_SQL, PERSONS_TABLE_SQL),
|
|
(DROP_PERSON_DISTINCT_ID_TABLE_SQL, PERSONS_DISTINCT_ID_TABLE_SQL),
|
|
(DROP_PERSON_STATIC_COHORT_TABLE_SQL, PERSON_STATIC_COHORT_TABLE_SQL),
|
|
(DROP_SESSION_RECORDING_EVENTS_TABLE_SQL, SESSION_RECORDING_EVENTS_TABLE_SQL),
|
|
(DROP_PLUGIN_LOG_ENTRIES_TABLE_SQL, PLUGIN_LOG_ENTRIES_TABLE_SQL),
|
|
(DROP_COHORTPEOPLE_TABLE_SQL, CREATE_COHORTPEOPLE_TABLE_SQL),
|
|
]
|
|
for item in TABLES_TO_CREATE_DROP:
|
|
try:
|
|
sync_execute(item[0])
|
|
except Exception as e:
|
|
pass
|
|
try:
|
|
sync_execute(item[1])
|
|
except Exception as e:
|
|
pass
|
|
|
|
|
|
@pytest.fixture(scope="package")
|
|
def django_db_setup(django_db_setup, django_db_keepdb):
|
|
database = Database(
|
|
CLICKHOUSE_DATABASE,
|
|
db_url=CLICKHOUSE_HTTP_URL,
|
|
username=CLICKHOUSE_USER,
|
|
password=CLICKHOUSE_PASSWORD,
|
|
verify_ssl_cert=CLICKHOUSE_VERIFY,
|
|
)
|
|
|
|
if not django_db_keepdb:
|
|
try:
|
|
database.drop_database()
|
|
except:
|
|
pass
|
|
|
|
if not django_db_keepdb or not database.db_exists:
|
|
database.create_database()
|
|
|
|
reset_clickhouse_tables()
|
|
|
|
yield
|
|
|
|
if not django_db_keepdb:
|
|
try:
|
|
database.drop_database()
|
|
except:
|
|
pass
|
|
|
|
|
|
@pytest.fixture
|
|
def base_test_mixin_fixture():
|
|
kls = TestMixin()
|
|
kls.setUp()
|
|
kls.setUpTestData()
|
|
|
|
return kls
|
|
|
|
|
|
@pytest.fixture
|
|
def team(base_test_mixin_fixture):
|
|
return base_test_mixin_fixture.team
|