aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/py/conftest.py6
-rw-r--r--test/py/lib/db.py28
-rw-r--r--test/py/test_repo.py32
3 files changed, 54 insertions, 12 deletions
diff --git a/test/py/conftest.py b/test/py/conftest.py
index 750e4e8..ead09d1 100644
--- a/test/py/conftest.py
+++ b/test/py/conftest.py
@@ -8,6 +8,7 @@ import os
from pytest import fixture
+from lib.db import Database
from lib.net import random_unused_port
from lib.process import CmdLine
from lib.test_repo import TestRepo
@@ -190,3 +191,8 @@ def client(client_cmd):
@fixture
def test_repo(tmp_path):
return TestRepo(tmp_path)
+
+
+@fixture
+def sqlite_db(server, sqlite_path):
+ return Database(sqlite_path)
diff --git a/test/py/lib/db.py b/test/py/lib/db.py
new file mode 100644
index 0000000..b9059c5
--- /dev/null
+++ b/test/py/lib/db.py
@@ -0,0 +1,28 @@
+# Copyright (c) 2023 Egor Tensin <Egor.Tensin@gmail.com>
+# This file is part of the "cimple" project.
+# For details, see https://github.com/egor-tensin/cimple.
+# Distributed under the MIT License.
+
+from contextlib import closing, contextmanager
+import sqlite3
+
+
+class Database:
+ def __init__(self, path):
+ self.conn = sqlite3.connect(f'file:{path}?mode=ro')
+
+ def __enter__(self):
+ return self
+
+ def __exit__(*args):
+ self.conn.close()
+
+ @contextmanager
+ def get_cursor(self):
+ with closing(self.conn.cursor()) as cur:
+ yield cur
+
+ def get_all_runs(self):
+ with self.get_cursor() as cur:
+ cur.execute('SELECT * FROM cimple_runs_readable')
+ return cur.fetchall()
diff --git a/test/py/test_repo.py b/test/py/test_repo.py
index 782240b..1cc1434 100644
--- a/test/py/test_repo.py
+++ b/test/py/test_repo.py
@@ -4,6 +4,7 @@
# Distributed under the MIT License.
from multiprocessing import Process
+import re
import pytest
@@ -14,10 +15,11 @@ class LoggingEventRunComplete(LoggingEvent):
def __init__(self, target):
self.counter = 0
self.target = target
+ self.re = re.compile(r'run \d+ as finished')
super().__init__(timeout=60)
def log_line_matches(self, line):
- return 'Received a "run finished" message from worker' in line
+ return bool(self.re.search(line))
def set(self):
self.counter += 1
@@ -25,7 +27,7 @@ class LoggingEventRunComplete(LoggingEvent):
super().set()
-def _test_repo_internal(server_and_workers, test_repo, client, numof_processes, runs_per_process):
+def _test_repo_internal(server_and_workers, test_repo, client, numof_processes, runs_per_process, db):
numof_runs = numof_processes * runs_per_process
server, workers = server_and_workers
@@ -47,24 +49,30 @@ def _test_repo_internal(server_and_workers, test_repo, client, numof_processes,
event.wait()
assert numof_runs == test_repo.count_ci_output_files()
+ runs = db.get_all_runs()
+ assert numof_runs == len(runs)
-def test_repo_1_client_1_run(server_and_workers, test_repo, client):
- _test_repo_internal(server_and_workers, test_repo, client, 1, 1)
+ for id, status, ec, output, url, rev in runs:
+ assert status == 'finished', f'Invalid status for run {id}: {status}'
-def test_repo_1_client_2_runs(server_and_workers, test_repo, client):
- _test_repo_internal(server_and_workers, test_repo, client, 1, 2)
+def test_repo_1_client_1_run(server_and_workers, test_repo, client, sqlite_db):
+ _test_repo_internal(server_and_workers, test_repo, client, 1, 1, sqlite_db)
-def test_repo_1_client_10_runs(server_and_workers, test_repo, client):
- _test_repo_internal(server_and_workers, test_repo, client, 1, 10)
+def test_repo_1_client_2_runs(server_and_workers, test_repo, client, sqlite_db):
+ _test_repo_internal(server_and_workers, test_repo, client, 1, 2, sqlite_db)
+
+
+def test_repo_1_client_10_runs(server_and_workers, test_repo, client, sqlite_db):
+ _test_repo_internal(server_and_workers, test_repo, client, 1, 10, sqlite_db)
@pytest.mark.stress
-def test_repo_1_client_2000_runs(server_and_workers, test_repo, client):
- _test_repo_internal(server_and_workers, test_repo, client, 1, 2000)
+def test_repo_1_client_2000_runs(server_and_workers, test_repo, client, sqlite_db):
+ _test_repo_internal(server_and_workers, test_repo, client, 1, 2000, sqlite_db)
@pytest.mark.stress
-def test_repo_4_clients_500_runs(server_and_workers, test_repo, client):
- _test_repo_internal(server_and_workers, test_repo, client, 4, 500)
+def test_repo_4_clients_500_runs(server_and_workers, test_repo, client, sqlite_db):
+ _test_repo_internal(server_and_workers, test_repo, client, 4, 500, sqlite_db)