Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: test tesmon with a real PR - DO NOT MERGE #2912

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 2 additions & 24 deletions .github/workflows/api-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ on:
- .github/**
branches:
- main
merge_group:
types: [checks_requested]

defaults:
run:
working-directory: api

jobs:
test:
runs-on: General-Purpose-8c-Runner
runs-on: ubuntu-latest
name: API Unit Tests

services:
Expand All @@ -35,7 +33,7 @@ jobs:
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

strategy:
max-parallel: 2
max-parallel: 4
matrix:
python-version: ['3.10', '3.11']

Expand Down Expand Up @@ -68,31 +66,11 @@ jobs:
opts: --no-input --dry-run --check
run: make django-make-migrations

- name: Restore cached testmon data
if: ${{ github.event_name == 'pull_request' }}
id: cache-testmon-restore
uses: actions/cache/restore@v3
with:
enableCrossOsArchive: true
path: |
/home/runner/work/flagsmith/flagsmith/api/.testmondata*
key: testmon-data-python${{ matrix.python-version }}-${{ github.event.pull_request.base.sha }}
restore-keys: testmon-data-python${{ matrix.python-version }}-

- name: Run Tests
env:
DOTENV_OVERRIDE_FILE: .env-ci
run: make test

- name: Save testmon data cache
id: cache-testmon-save
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
uses: actions/cache/save@v3
with:
path: |
/home/runner/work/flagsmith/flagsmith/api/.testmondata*
key: testmon-data-python${{ matrix.python-version }}-${{github.sha}}

- name: Upload Coverage
uses: codecov/codecov-action@v3
env:
Expand Down
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "2.76.0"
".": "2.77.0"
}
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## [2.77.0](https://github.com/Flagsmith/flagsmith/compare/v2.76.0...v2.77.0) (2023-10-30)


### Features

* Click Segment Overrides icon doesnt open the segment override tab ([#2887](https://github.com/Flagsmith/flagsmith/issues/2887)) ([96f3b22](https://github.com/Flagsmith/flagsmith/commit/96f3b22f3d21d81074643df90878dba2ace51580))
* **permissions/tags:** Add tags support ([#2685](https://github.com/Flagsmith/flagsmith/issues/2685)) ([78e559c](https://github.com/Flagsmith/flagsmith/commit/78e559c320011bcc6ec9339cb2614a9751244156))


### Bug Fixes

* Handle null tooltip data ([#2892](https://github.com/Flagsmith/flagsmith/issues/2892)) ([a1190ae](https://github.com/Flagsmith/flagsmith/commit/a1190ae90a31496e9e368a1dbdc232a1dd4daf1a))

## [2.76.0](https://github.com/Flagsmith/flagsmith/compare/v2.75.0...v2.76.0) (2023-10-24)


Expand Down
2 changes: 1 addition & 1 deletion api/.env-ci
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres
ANALYTICS_DATABASE_URL=postgres://postgres:postgres@localhost:5432/analytics
PYTEST_ADDOPTS=--cov . --cov-report xml -n auto --dist worksteal --testmon
PYTEST_ADDOPTS=--cov . --cov-report xml -n auto --dist worksteal
5 changes: 1 addition & 4 deletions api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ saml/
features/workflows/logic/

# Unit test coverage
.coverage

# pytest-testmon files
.testmondata*
.coverage
7 changes: 4 additions & 3 deletions api/audit/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
)
from audit.models import AuditLog, RelatedObjectType
from task_processor.decorators import register_task_handler
from task_processor.models import TaskPriority

logger = logging.getLogger(__name__)


@register_task_handler()
@register_task_handler(priority=TaskPriority.HIGHEST)
def create_feature_state_went_live_audit_log(feature_state_id: int):
_create_feature_state_audit_log_for_change_request(
feature_state_id, FEATURE_STATE_WENT_LIVE_MESSAGE
)


@register_task_handler()
@register_task_handler(priority=TaskPriority.HIGHEST)
def create_feature_state_updated_by_change_request_audit_log(feature_state_id: int):
_create_feature_state_audit_log_for_change_request(
feature_state_id, FEATURE_STATE_UPDATED_BY_CHANGE_REQUEST_MESSAGE
Expand Down Expand Up @@ -57,7 +58,7 @@ def _create_feature_state_audit_log_for_change_request(
)


@register_task_handler()
@register_task_handler(priority=TaskPriority.HIGHEST)
def create_audit_log_from_historical_record(
history_instance_id: int,
history_user_id: typing.Optional[int],
Expand Down
15 changes: 12 additions & 3 deletions api/core/migration_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import typing
import uuid
from contextlib import suppress

from django.db import migrations

Expand All @@ -8,9 +10,16 @@

class PostgresOnlyRunSQL(migrations.RunSQL):
@classmethod
def from_sql_file(cls, file_path: str, reverse_sql: str) -> "PostgresOnlyRunSQL":
with open(file_path) as f:
return cls(f.read(), reverse_sql=reverse_sql)
def from_sql_file(
cls,
file_path: typing.Union[str, os.PathLike],
reverse_sql: typing.Union[str, os.PathLike] = None,
) -> "PostgresOnlyRunSQL":
with open(file_path) as forward_sql:
with suppress(FileNotFoundError, TypeError):
with open(reverse_sql) as reverse_sql_file:
reverse_sql = reverse_sql_file.read()
return cls(forward_sql.read(), reverse_sql=reverse_sql)

def database_forwards(self, app_label, schema_editor, from_state, to_state):
if schema_editor.connection.vendor != "postgresql":
Expand Down
7 changes: 4 additions & 3 deletions api/edge_api/identities/edge_request_forwarder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@

from environments.dynamodb.migrator import IdentityMigrator
from task_processor.decorators import register_task_handler
from task_processor.models import TaskPriority


def _should_forward(project_id: int) -> bool:
migrator = IdentityMigrator(project_id)
return bool(migrator.is_migration_done)


@register_task_handler(queue_size=2000)
@register_task_handler(queue_size=2000, priority=TaskPriority.LOW)
def forward_identity_request(
request_method: str,
headers: dict,
Expand All @@ -35,7 +36,7 @@ def forward_identity_request(
requests.get(url, params=query_params, headers=headers, timeout=5)


@register_task_handler(queue_size=2000)
@register_task_handler(queue_size=2000, priority=TaskPriority.LOW)
def forward_trait_request(
request_method: str,
headers: dict,
Expand All @@ -61,7 +62,7 @@ def forward_trait_request_sync(
)


@register_task_handler(queue_size=1000)
@register_task_handler(queue_size=1000, priority=TaskPriority.LOW)
def forward_trait_requests(
request_method: str,
headers: str,
Expand Down
3 changes: 2 additions & 1 deletion api/edge_api/identities/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from environments.models import Environment, Webhook
from features.models import Feature, FeatureState
from task_processor.decorators import register_task_handler
from task_processor.models import TaskPriority
from users.models import FFAdminUser
from webhooks.webhooks import WebhookEventType, call_environment_webhooks

Expand Down Expand Up @@ -71,7 +72,7 @@ def call_environment_webhook_for_feature_state_change(
call_environment_webhooks(environment, data, event_type=event_type)


@register_task_handler()
@register_task_handler(priority=TaskPriority.HIGH)
def sync_identity_document_features(identity_uuid: str):
from .models import EdgeIdentity

Expand Down
5 changes: 3 additions & 2 deletions api/environments/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
send_environment_update_message_for_project,
)
from task_processor.decorators import register_task_handler
from task_processor.models import TaskPriority


@register_task_handler()
@register_task_handler(priority=TaskPriority.HIGH)
def rebuild_environment_document(environment_id: int):
wrapper = DynamoEnvironmentWrapper()
if wrapper.is_enabled:
environment = Environment.objects.get(id=environment_id)
wrapper.write_environment(environment)


@register_task_handler()
@register_task_handler(priority=TaskPriority.HIGHEST)
def process_environment_update(audit_log_id: int):
audit_log = AuditLog.objects.get(id=audit_log_id)

Expand Down
33 changes: 14 additions & 19 deletions api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ pip-tools = "~6.13.0"
pytest-cov = "~4.1.0"
datamodel-code-generator = "~0.22"
requests-mock = "^1.11.0"
pytest-testmon = "^2.0.13"

[build-system]
requires = ["poetry-core>=1.5.0"]
Expand Down
13 changes: 9 additions & 4 deletions api/task_processor/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
from django.utils import timezone

from task_processor.exceptions import InvalidArgumentsError, TaskQueueFullError
from task_processor.models import RecurringTask, Task
from task_processor.models import RecurringTask, Task, TaskPriority
from task_processor.task_registry import register_task
from task_processor.task_run_method import TaskRunMethod

logger = logging.getLogger(__name__)


def register_task_handler(task_name: str = None, queue_size: int = None):
def register_task_handler(
task_name: str = None,
queue_size: int = None,
priority: TaskPriority = TaskPriority.NORMAL,
):
def decorator(f: typing.Callable):
nonlocal task_name

Expand Down Expand Up @@ -50,9 +54,10 @@ def delay(
else:
logger.debug("Creating task for function '%s'...", task_identifier)
try:
task = Task.schedule_task(
schedule_for=delay_until or timezone.now(),
task = Task.create(
task_identifier=task_identifier,
scheduled_for=delay_until or timezone.now(),
priority=priority,
queue_size=queue_size,
args=args,
kwargs=kwargs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ class Migration(migrations.Migration):
os.path.join(
os.path.dirname(__file__),
"sql",
"get_tasks_to_process.sql",
"0008_get_tasks_to_process.sql",
),
reverse_sql="DROP FUNCTION IF EXISTS get_tasks_to_process",
),
PostgresOnlyRunSQL.from_sql_file(
os.path.join(
os.path.dirname(__file__),
"sql",
"get_recurring_tasks_to_process.sql",
"0008_get_recurring_tasks_to_process.sql",
),
reverse_sql="DROP FUNCTION IF EXISTS get_recurringtasks_to_process",
),
Expand Down
18 changes: 18 additions & 0 deletions api/task_processor/migrations/0010_task_priority.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.20 on 2023-10-13 06:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('task_processor', '0009_add_recurring_task_run_first_run_at'),
]

operations = [
migrations.AddField(
model_name='task',
name='priority',
field=models.PositiveSmallIntegerField(choices=[(100, 'Lower'), (75, 'Low'), (50, 'Normal'), (25, 'High'), (0, 'Highest')], default=None, null=True),
),
]
Loading
Loading