mirror of
https://github.com/PostHog/posthog.git
synced 2024-11-22 08:40:03 +01:00
perf: Speed up backend tests locally (#9255)
* perf: Speed up backend tests locally * fix
This commit is contained in:
parent
9e449185f4
commit
e6333ca7d7
14
bin/tests
14
bin/tests
@ -28,5 +28,15 @@ PG_HOST="${PGHOST:=localhost}"
|
||||
PG_USER="${PGUSER:=posthog}"
|
||||
PG_PASSWORD="${PGPASSWORD:=posthog}"
|
||||
PG_PORT="${PGPORT:=5432}"
|
||||
psql posthog -d "postgres://${PG_USER}:${PG_PASSWORD}@${PG_HOST}:${PG_PORT}" -c "drop database if exists test_posthog"
|
||||
nodemon -w ./posthog -w ./ee --ext py --exec "OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES pytest --reuse-db -s $* --snapshot-update; mypy posthog ee"
|
||||
PGOPTIONS='--client-min-messages=warning' psql posthog -d "postgres://${PG_USER}:${PG_PASSWORD}@${PG_HOST}:${PG_PORT}" -c "drop database if exists test_posthog" 1> /dev/null
|
||||
|
||||
if [[ "$*" == *"migration"* ]]
|
||||
then
|
||||
echo "Looks like you're testing a migration. Running all migrations first."
|
||||
MIGRATIONS=""
|
||||
else
|
||||
MIGRATIONS="--no-migrations"
|
||||
export SKIP_TRIGRAM_INDEX_FOR_TESTS=1
|
||||
fi
|
||||
|
||||
nodemon -w ./posthog -w ./ee --ext py --exec "OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES pytest --reuse-db --durations-min=2.0 ${MIGRATIONS} -s $* --snapshot-update; mypy posthog ee"
|
||||
|
@ -1,3 +1,5 @@
|
||||
import threading
|
||||
|
||||
import pytest
|
||||
from django.conf import settings
|
||||
from infi.clickhouse_orm import Database
|
||||
@ -60,8 +62,18 @@ def create_clickhouse_tables(num_tables: int):
|
||||
if num_tables == len(TABLES_TO_CREATE_DROP):
|
||||
return
|
||||
|
||||
jobs = []
|
||||
for item in TABLES_TO_CREATE_DROP:
|
||||
sync_execute(item)
|
||||
thread = threading.Thread(target=sync_execute, args=(item,))
|
||||
jobs.append(thread)
|
||||
|
||||
# Start the threads (i.e. calculate the random number lists)
|
||||
for j in jobs:
|
||||
j.start()
|
||||
|
||||
# Ensure all of the threads have finished
|
||||
for j in jobs:
|
||||
j.join()
|
||||
|
||||
|
||||
def reset_clickhouse_tables():
|
||||
@ -95,8 +107,18 @@ def reset_clickhouse_tables():
|
||||
TRUNCATE_GROUPS_TABLE_SQL,
|
||||
]
|
||||
|
||||
jobs = []
|
||||
for item in TABLES_TO_CREATE_DROP:
|
||||
sync_execute(item)
|
||||
thread = threading.Thread(target=sync_execute, args=(item,))
|
||||
jobs.append(thread)
|
||||
|
||||
# Start the threads (i.e. calculate the random number lists)
|
||||
for j in jobs:
|
||||
j.start()
|
||||
|
||||
# Ensure all of the threads have finished
|
||||
for j in jobs:
|
||||
j.join()
|
||||
|
||||
|
||||
@pytest.fixture(scope="package")
|
||||
|
@ -1,3 +1,5 @@
|
||||
import os
|
||||
|
||||
from django.contrib.postgres.indexes import GinIndex
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
@ -22,9 +24,15 @@ class EventDefinition(UUIDModel):
|
||||
|
||||
class Meta:
|
||||
unique_together = ("team", "name")
|
||||
indexes = [
|
||||
GinIndex(name="index_event_definition_name", fields=["name"], opclasses=["gin_trgm_ops"]),
|
||||
] # To speed up DB-based fuzzy searching
|
||||
indexes = (
|
||||
[
|
||||
GinIndex(
|
||||
name="index_event_definition_name", fields=["name"], opclasses=["gin_trgm_ops"]
|
||||
), # To speed up DB-based fuzzy searching
|
||||
]
|
||||
if not os.environ.get("SKIP_TRIGRAM_INDEX_FOR_TESTS")
|
||||
else []
|
||||
) # This index breaks the --no-migrations option when running tests
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.name} / {self.team.name}"
|
||||
|
@ -1,3 +1,5 @@
|
||||
import os
|
||||
|
||||
from django.contrib.postgres.indexes import GinIndex
|
||||
from django.db import models
|
||||
|
||||
@ -50,9 +52,15 @@ class PropertyDefinition(UUIDModel):
|
||||
|
||||
class Meta:
|
||||
unique_together = ("team", "name")
|
||||
indexes = [
|
||||
GinIndex(name="index_property_definition_name", fields=["name"], opclasses=["gin_trgm_ops"]),
|
||||
] # To speed up DB-based fuzzy searching
|
||||
indexes = (
|
||||
[
|
||||
GinIndex(
|
||||
name="index_property_definition_name", fields=["name"], opclasses=["gin_trgm_ops"]
|
||||
), # To speed up DB-based fuzzy searching
|
||||
]
|
||||
if not os.environ.get("SKIP_TRIGRAM_INDEX_FOR_TESTS")
|
||||
else []
|
||||
) # This index breaks the --no-migrations option when running tests
|
||||
constraints = [
|
||||
models.CheckConstraint(name="property_type_is_valid", check=models.Q(property_type__in=PropertyType.values))
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user