-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_service_bulk_insert.py
More file actions
55 lines (47 loc) · 1.61 KB
/
test_service_bulk_insert.py
File metadata and controls
55 lines (47 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
Benchmark: service-layer writes for N commits plus one file change each, in one transaction.
"""
from __future__ import annotations
from datetime import datetime, timezone
import pytest
from django.db import transaction
from github_activity_tracker import services
from github_activity_tracker.models import FileChangeStatus
@pytest.mark.benchmark
@pytest.mark.django_db(transaction=True)
def test_service_bulk_commits_and_file_changes(
benchmark,
github_repository,
github_account,
benchmark_commit_n,
):
n = benchmark_commit_n
repo = github_repository
account = github_account
commit_at = datetime(2024, 6, 1, tzinfo=timezone.utc)
hashes = [f"{i:040x}" for i in range(n)]
def run_batch() -> None:
with transaction.atomic():
for i in range(n):
commit_obj, _ = services.create_or_update_commit(
repo=repo,
account=account,
commit_hash=hashes[i],
comment=f"svc bulk {i}",
commit_at=commit_at,
)
github_file, _ = services.create_or_update_github_file(
repo,
f"benchmarks/svc_bulk_{i}.txt",
is_deleted=False,
)
services.add_commit_file_change(
commit_obj,
github_file,
status=FileChangeStatus.MODIFIED,
additions=1,
deletions=0,
patch="",
)
benchmark.extra_info["n"] = n
benchmark(run_batch)