Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Tests are based on pytest #192

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f37c299
Using pytest [pytest.raises]
dmitry-lipetsk Feb 23, 2025
53e468e
Using pytest [pytest.skip]
dmitry-lipetsk Feb 23, 2025
12d702a
Using pytest [assertIsNotNone]
dmitry-lipetsk Feb 23, 2025
1cb664e
Using pytest [assertFalse]
dmitry-lipetsk Feb 23, 2025
e2e7e8b
Using pytest [assertTrue]
dmitry-lipetsk Feb 23, 2025
89784a8
Using pytest [assertEqual]
dmitry-lipetsk Feb 23, 2025
2252d60
Using pytest [assertNotEqual]
dmitry-lipetsk Feb 23, 2025
e8aad3d
Using pytest [assertGreaterEqual]
dmitry-lipetsk Feb 23, 2025
eaaa276
Using pytest [assertGreater]
dmitry-lipetsk Feb 23, 2025
4afbe00
Using pytest [assertIn]
dmitry-lipetsk Feb 23, 2025
a8e57ae
Using pytest [assertListEqual]
dmitry-lipetsk Feb 23, 2025
df199b9
unittest is not used
dmitry-lipetsk Feb 23, 2025
a82cf3d
Code style (flake8)
dmitry-lipetsk Feb 23, 2025
9745bc4
Merge commit '38b3dc3697d229b6668217f2f57825379c7f2e23' into D2025022…
dmitry-lipetsk Feb 23, 2025
27c4f40
Execution signature is removed
dmitry-lipetsk Feb 24, 2025
ae41d16
run_tests.sh installs pytest
dmitry-lipetsk Feb 24, 2025
a14b3d7
run_tests.sh is updated
dmitry-lipetsk Feb 24, 2025
e6f4448
Total refactoring of tests
dmitry-lipetsk Feb 24, 2025
842bc08
Code style (flake8)
dmitry-lipetsk Feb 24, 2025
d9afdcc
Merge commit 'de738f9fd8d52345677903bface575d41cbe539c' into D2025022…
dmitry-lipetsk Feb 24, 2025
027d2ea
Merge branch 'D20250224_002--os_ops-in-free_utilities' into D20250223…
dmitry-lipetsk Feb 24, 2025
969e49d
Root __init__.py is added
dmitry-lipetsk Feb 24, 2025
6e2820d
Code style (flake8)
dmitry-lipetsk Feb 24, 2025
588b28b
Merge remote-tracking branch 'origin/D20250224_002--os_ops-in-free_ut…
dmitry-lipetsk Feb 24, 2025
e4e8909
pytest.ini is added
dmitry-lipetsk Feb 24, 2025
66860d0
TestgresTests::test_ports_management is corrected
dmitry-lipetsk Feb 24, 2025
aaaa677
coding: utf-8
dmitry-lipetsk Feb 24, 2025
60bb4c5
Cleanup
dmitry-lipetsk Feb 24, 2025
2d2532c
CI runs all the tests of testgres.
dmitry-lipetsk Feb 24, 2025
537a9ac
Add install ssh
Feb 24, 2025
1f99813
Revert "Add install ssh"
dmitry-lipetsk Feb 25, 2025
41455d6
Revert "CI runs all the tests of testgres."
dmitry-lipetsk Feb 25, 2025
1c43810
Merge commit '669e134ff65b99cd285500e5f362633fc8d50e4e' into D2025022…
dmitry-lipetsk Feb 25, 2025
47a51a8
Test of probackup plugin is restored
dmitry-lipetsk Feb 25, 2025
f7f163d
The test suite of a probackup plugin is based on pytest
dmitry-lipetsk Feb 25, 2025
ed7b187
Probackup plugin is updated
dmitry-lipetsk Feb 25, 2025
8af4a49
CI test use 4 cores
dmitry-lipetsk Feb 25, 2025
d35ca43
testgres.plugins.probackup2.Init was restored [thanks to Yuri Sokolov]
dmitry-lipetsk Feb 25, 2025
181126b
pytest.ini is updated [testpaths]
dmitry-lipetsk Feb 25, 2025
d08f659
test_child_pids (local, remote) is updated
dmitry-lipetsk Feb 25, 2025
e803146
test_child_process_dies is updated
dmitry-lipetsk Feb 25, 2025
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
Empty file added __init__.py
Empty file.
9 changes: 9 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[pytest]
testpaths = ["./tests", "./testgres/plugins/pg_probackup2/pg_probackup2/tests"]
addopts = --strict-markers
markers =
#log_file = logs/pytest.log
log_file_level = NOTSET
log_file_format = %(levelname)8s [%(asctime)s] %(message)s
log_file_date_format=%Y-%m-%d %H:%M:%S

12 changes: 5 additions & 7 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export VIRTUAL_ENV_DISABLE_PROMPT=1
source $VENV_PATH/bin/activate

# install utilities
$PIP install coverage flake8 psutil Sphinx
$PIP install coverage flake8 psutil Sphinx pytest pytest-xdist psycopg2 six psutil

# install testgres' dependencies
export PYTHONPATH=$(pwd)
$PIP install .
# $PIP install .

# test code quality
flake8 .
Expand All @@ -38,21 +38,19 @@ rm -f $COVERAGE_FILE


# run tests (PATH)
time coverage run -a tests/test_simple.py
time coverage run -a -m pytest -l -v -n 4 -k "TestgresTests"


# run tests (PG_BIN)
time \
PG_BIN=$(dirname $(which pg_config)) \
ALT_CONFIG=1 \
coverage run -a tests/test_simple.py
coverage run -a -m pytest -l -v -n 4 -k "TestgresTests"


# run tests (PG_CONFIG)
time \
PG_CONFIG=$(which pg_config) \
ALT_CONFIG=1 \
coverage run -a tests/test_simple.py
coverage run -a -m pytest -l -v -n 4 -k "TestgresTests"


# show coverage
Expand Down
8 changes: 4 additions & 4 deletions testgres/plugins/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pg_probackup2.gdb import GDBobj
from pg_probackup2.app import ProbackupApp, ProbackupException
from pg_probackup2.init_helpers import init_params
from pg_probackup2.storage.fs_backup import FSTestBackupDir
from .pg_probackup2.pg_probackup2.gdb import GDBobj
from .pg_probackup2.pg_probackup2.app import ProbackupApp, ProbackupException
from .pg_probackup2.pg_probackup2.init_helpers import init_params
from .pg_probackup2.pg_probackup2.storage.fs_backup import FSTestBackupDir

__all__ = [
"ProbackupApp", "ProbackupException", "init_params", "FSTestBackupDir", "GDBobj"
Expand Down
13 changes: 8 additions & 5 deletions testgres/plugins/pg_probackup2/pg_probackup2/init_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ def __init__(self):
self.probackup_path = probackup_path_tmp

if not self.probackup_path:
logging.error('pg_probackup binary is not found')
exit(1)
raise Exception('pg_probackup binary is not found')

if os.name == 'posix':
self.EXTERNAL_DIRECTORY_DELIMITER = ':'
Expand Down Expand Up @@ -213,11 +212,15 @@ def __init__(self):
if self.probackup_version.split('.')[0].isdigit():
self.major_version = int(self.probackup_version.split('.')[0])
else:
logging.error('Can\'t process pg_probackup version \"{}\": the major version is expected to be a number'.format(self.probackup_version))
sys.exit(1)
raise Exception('Can\'t process pg_probackup version \"{}\": the major version is expected to be a number'.format(self.probackup_version))

def test_env(self):
return self._test_env.copy()


init_params = Init()
try:
init_params = Init()
except Exception as e:
logging.error(str(e))
logging.warning("testgres.plugins.probackup2.init_params is set to None.")
init_params = None
Empty file.
80 changes: 0 additions & 80 deletions testgres/plugins/pg_probackup2/pg_probackup2/tests/basic_test.py

This file was deleted.

95 changes: 95 additions & 0 deletions testgres/plugins/pg_probackup2/pg_probackup2/tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
from __future__ import annotations

import os
import shutil
import pytest

from ...... import testgres
from ...pg_probackup2.app import ProbackupApp
from ...pg_probackup2.init_helpers import Init, init_params
from ..storage.fs_backup import FSTestBackupDir


class ProbackupTest:
pg_node: testgres.PostgresNode

@staticmethod
def probackup_is_available() -> bool:
p = os.environ.get("PGPROBACKUPBIN")

if p is None:
return False

if not os.path.exists(p):
return False

return True

@pytest.fixture(autouse=True, scope="function")
def implicit_fixture(self, request: pytest.FixtureRequest):
assert isinstance(request, pytest.FixtureRequest)
self.helper__setUp(request)
yield
self.helper__tearDown()

def helper__setUp(self, request: pytest.FixtureRequest):
assert isinstance(request, pytest.FixtureRequest)

self.helper__setup_test_environment(request)
self.helper__setup_test_paths()
self.helper__setup_backup_dir()
self.helper__setup_probackup()

def helper__setup_test_environment(self, request: pytest.FixtureRequest):
assert isinstance(request, pytest.FixtureRequest)

self.output = None
self.cmd = None
self.nodes_to_cleanup = []
self.module_name, self.fname = request.node.cls.__name__, request.node.name
self.test_env = Init().test_env()

def helper__setup_test_paths(self):
self.rel_path = os.path.join(self.module_name, self.fname)
self.test_path = os.path.join(init_params.tmp_path, self.rel_path)
os.makedirs(self.test_path, exist_ok=True)
self.pb_log_path = os.path.join(self.test_path, "pb_log")

def helper__setup_backup_dir(self):
self.backup_dir = self.helper__build_backup_dir('backup')
self.backup_dir.cleanup()

def helper__setup_probackup(self):
self.pg_node = testgres.NodeApp(self.test_path, self.nodes_to_cleanup)
self.pb = ProbackupApp(self, self.pg_node, self.pb_log_path, self.test_env,
auto_compress_alg='zlib', backup_dir=self.backup_dir)

def helper__tearDown(self):
if os.path.exists(self.test_path):
shutil.rmtree(self.test_path)

def helper__build_backup_dir(self, backup='backup'):
return FSTestBackupDir(rel_path=self.rel_path, backup=backup)


@pytest.mark.skipif(not ProbackupTest.probackup_is_available(), reason="Check that PGPROBACKUPBIN is defined and is valid.")
class TestBasic(ProbackupTest):
def test_full_backup(self):
# Setting up a simple test node
node = self.pg_node.make_simple('node', pg_options={"fsync": "off", "synchronous_commit": "off"})

# Initialize and configure Probackup
self.pb.init()
self.pb.add_instance('node', node)
self.pb.set_archiving('node', node)

# Start the node and initialize pgbench
node.slow_start()
node.pgbench_init(scale=100, no_vacuum=True)

# Perform backup and validation
backup_id = self.pb.backup_node('node', node)
out = self.pb.validate('node', backup_id)

# Check if the backup is valid
assert f"INFO: Backup {backup_id} is valid" in out
1 change: 1 addition & 0 deletions tests/helpers/run_conditions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding: utf-8
import pytest
import platform

Expand Down
7 changes: 4 additions & 3 deletions tests/test_local.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# coding: utf-8
import os

import pytest
import re
import tempfile

from testgres import ExecUtilException
from testgres import InvalidOperationException
from testgres import LocalOperations
from ..testgres import ExecUtilException
from ..testgres import InvalidOperationException
from ..testgres import LocalOperations

from .helpers.run_conditions import RunConditions

Expand Down
9 changes: 5 additions & 4 deletions tests/test_remote.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# coding: utf-8
import os

import pytest
import re
import tempfile

from testgres import ExecUtilException
from testgres import InvalidOperationException
from testgres import RemoteOperations
from testgres import ConnectionParams
from ..testgres import ExecUtilException
from ..testgres import InvalidOperationException
from ..testgres import RemoteOperations
from ..testgres import ConnectionParams


class TestRemoteOperations:
Expand Down
Loading