Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:

build_images:
name: Build test image (PG${{ matrix.PGVERSION }})
needs: style_checker
runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ RUN apt-get update \
make \
autoconf \
openssl \
pipenv \
python3-nose \
python3-pytest \
python3 \
python3-setuptools \
python3-psycopg2 \
Expand Down Expand Up @@ -74,7 +74,7 @@ RUN apt-get update \
postgresql-${PGVERSION} \
&& rm -rf /var/lib/apt/lists/*

RUN pip3 install pyroute2>=0.5.17
RUN pip3 install 'pyroute2>=0.5.17'

RUN adduser --disabled-password --gecos '' docker
RUN adduser docker sudo
Expand Down
23 changes: 11 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ include Makefile.azure
#
# LIST TESTS
#
NOSETESTS = $(shell which nosetests3 || which nosetests)
PYTEST = python3 -m pytest

# Tests for the monitor
TESTS_MONITOR = test_extension_update
Expand Down Expand Up @@ -78,17 +78,17 @@ TESTS_MULTI += test_multi_standbys
# Included Makefile may define TEST_ARGUMENT (like for citus)
TEST ?=
ifeq ($(TEST),)
TEST_ARGUMENT = --where=tests
TEST_ARGUMENT = tests/*.py
else ifeq ($(TEST),multi)
TEST_ARGUMENT = --where=tests --tests=$(TESTS_MULTI)
TEST_ARGUMENT = $(TESTS_MULTI:%=tests/%.py)
else ifeq ($(TEST),single)
TEST_ARGUMENT = --where=tests --tests=$(TESTS_SINGLE)
TEST_ARGUMENT = $(TESTS_SINGLE:%=tests/%.py)
else ifeq ($(TEST),monitor)
TEST_ARGUMENT = --where=tests --tests=$(TESTS_MONITOR)
TEST_ARGUMENT = $(TESTS_MONITOR:%=tests/%.py)
else ifeq ($(TEST),ssl)
TEST_ARGUMENT = --where=tests --tests=$(TESTS_SSL)
TEST_ARGUMENT = $(TESTS_SSL:%=tests/%.py)
else
TEST_ARGUMENT = $(TEST:%=tests/%.py)
TEST_ARGUMENT = tests/$(TEST).py
endif

#
Expand Down Expand Up @@ -167,11 +167,10 @@ ifeq ($(TEST),tablespaces)
$(MAKE) -C tests/tablespaces run-test
else
sudo -E env "PATH=${PATH}" USER=$(shell whoami) \
$(NOSETESTS) \
--verbose \
--nologcapture \
--nocapture \
--stop \
$(PYTEST) \
-v \
-s \
-x \
${TEST_ARGUMENT}
endif

Expand Down
2 changes: 1 addition & 1 deletion Makefile.citus
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ifeq ($(TEST),citus)
TESTS_CITUS += test_nonha_citus_operation
TESTS_CITUS += test_citus_skip_pg_hba

TEST_ARGUMENT = --where=tests --tests=$(TESTS_CITUS)
TEST_ARGUMENT = $(TESTS_CITUS:%=tests/%.py)
endif

# this target is defined and used later in the main Makefile
Expand Down
4 changes: 4 additions & 0 deletions tests/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def run(self, command, user=os.getenv("USER")):
user,
"env",
"PATH=" + os.getenv("PATH"),
"LC_ALL=C",
"LANG=C",
] + command
return managed_nspopen(
self.namespace,
Expand All @@ -179,6 +181,8 @@ def run_unmanaged(self, command, user=os.getenv("USER")):
user,
"env",
"PATH=" + os.getenv("PATH"),
"LC_ALL=C",
"LANG=C",
] + command
return NSPopen(
self.namespace,
Expand Down
13 changes: 9 additions & 4 deletions tests/pgautofailover_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,21 @@ def run_sql_query(self, query, autocommit, *args):
conn = psycopg2.connect(self.connection_string())
conn.autocommit = autocommit

with conn:
try:
with conn.cursor() as cur:
cur.execute(query, args)
try:
result = cur.fetchall()
except psycopg2.ProgrammingError:
pass
# leaving contexts closes the cursor, however
# leaving contexts doesn't close the connection
conn.close()
if not autocommit:
conn.commit()
except Exception:
if not autocommit:
conn.rollback()
raise
finally:
conn.close()

return result

Expand Down
8 changes: 8 additions & 0 deletions tests/tablespaces/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import sys
import os

# tablespace tests import as "from tests.tablespaces.xxx import ..." which
# requires the project root (parent of tests/) on sys.path. pytest does not
# add it automatically; nosetests used to, by treating tests/__init__.py as a
# package root. Add it here so both test runners work.
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(__file__))))