mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(tests): Fix test case for Prometheus metrics
Disable prometheus multiprocess mode in tests to avoid global state: Depending on the workers which are processing a testfile, we might run into race issues where tests might influence each other. We also need to make sure to clear any previously collected values in case the same worker/process is executing different tests which evaluate prometheus values. Signed-off-by: moson <moson@archlinux.org>
This commit is contained in:
parent
027dfbd970
commit
4637b2edba
4 changed files with 26 additions and 8 deletions
|
@ -1,7 +1,7 @@
|
|||
import pytest
|
||||
from prometheus_client import REGISTRY, generate_latest
|
||||
|
||||
from aurweb import cache, db, prometheus, time
|
||||
from aurweb import cache, db, time
|
||||
from aurweb.models import Package, PackageBase, PackageRequest
|
||||
from aurweb.models.account_type import PACKAGE_MAINTAINER_ID, USER_ID
|
||||
from aurweb.models.package_request import (
|
||||
|
@ -16,7 +16,7 @@ from aurweb.statistics import Statistics, update_prometheus_metrics
|
|||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def setup(db_test):
|
||||
def setup(db_test, prometheus_test):
|
||||
return
|
||||
|
||||
|
||||
|
@ -140,11 +140,6 @@ def test_get_count_change(stats: Statistics, test_data):
|
|||
|
||||
|
||||
def test_update_prometheus_metrics(test_data):
|
||||
# Make sure any previous data is cleared
|
||||
prometheus.USERS.clear()
|
||||
prometheus.PACKAGES.clear()
|
||||
prometheus.REQUESTS.clear()
|
||||
|
||||
metrics = str(generate_latest(REGISTRY))
|
||||
|
||||
assert "aur_users{" not in metrics
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue