Skip to content

Commit c76168c

Browse files
authored
test: Allow passing of PostgreSQL port (#3281)
Allow passing an arbitrary port via the `SENTPY_PYTHON_TEST_POSTGRES_PORT` environmental variable. Fedora's RPM macro `%postgresql_tests_run` which starts PostgreSQL dynamically selects PostgreSQL port to prevent start failures when running multiple PostgreSQL servers on the same default port [1]. This issue is not specific to Fedora. In case there is some application running on the same machine with port `5432` opened, such as PostgreSQL instance with the default port, this will result in failure to start the PostgreSQL server, resulting in an inability to run these tests. This change allows running these tests in environments where PostgreSQL has a non-default port and where other applications (including a PostgreSQL instance with the default port) have opened port `5432`, while at the same time keeping the old behavior as the default. [1] The macro is provided by https://packages.fedoraproject.org/pkgs/postgresql15/postgresql15-test-rpm-macros/, which packages https://github.com/devexp-db/postgresql-setup. Dynamic selection of the port was added in 2018: devexp-db/postgresql-setup#16, for the reasoning see `NEWS` file changes: https://github.com/devexp-db/postgresql-setup/pull/16/files#diff-7ee66c4f1536ac84dc5bbff1b8312e2eef24b974b3e48a5c5c2bcfdf2eb8f3ce).
1 parent a98f660 commit c76168c

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

tests/integrations/asyncpg/test_asyncpg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
PG_HOST = os.getenv("SENTRY_PYTHON_TEST_POSTGRES_HOST", "localhost")
16-
PG_PORT = 5432
16+
PG_PORT = int(os.getenv("SENTRY_PYTHON_TEST_POSTGRES_PORT", "5432"))
1717
PG_USER = os.getenv("SENTRY_PYTHON_TEST_POSTGRES_USER", "postgres")
1818
PG_PASSWORD = os.getenv("SENTRY_PYTHON_TEST_POSTGRES_PASSWORD", "sentry")
1919
PG_NAME = os.getenv("SENTRY_PYTHON_TEST_POSTGRES_NAME", "postgres")

tests/integrations/django/myapp/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def middleware(request):
122122
DATABASES["postgres"] = {
123123
"ENGINE": db_engine,
124124
"HOST": os.environ.get("SENTRY_PYTHON_TEST_POSTGRES_HOST", "localhost"),
125-
"PORT": 5432,
125+
"PORT": int(os.environ.get("SENTRY_PYTHON_TEST_POSTGRES_PORT", "5432")),
126126
"USER": os.environ.get("SENTRY_PYTHON_TEST_POSTGRES_USER", "postgres"),
127127
"PASSWORD": os.environ.get("SENTRY_PYTHON_TEST_POSTGRES_PASSWORD", "sentry"),
128128
"NAME": os.environ.get(

tests/integrations/django/test_basic.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,9 @@ def test_db_connection_span_data(sentry_init, client, capture_events):
626626
assert data.get(SPANDATA.SERVER_ADDRESS) == os.environ.get(
627627
"SENTRY_PYTHON_TEST_POSTGRES_HOST", "localhost"
628628
)
629-
assert data.get(SPANDATA.SERVER_PORT) == "5432"
629+
assert data.get(SPANDATA.SERVER_PORT) == os.environ.get(
630+
"SENTRY_PYTHON_TEST_POSTGRES_PORT", "5432"
631+
)
630632

631633

632634
def test_set_db_data_custom_backend():

0 commit comments

Comments
 (0)