Skip to content

test: Allow passing of PostgreSQL port #3281

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 2 commits into from
Jul 16, 2024

Conversation

rominf
Copy link
Contributor

@rominf rominf commented Jul 11, 2024

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 reasoningsee NEWS file changes: https://github.com/devexp-db/postgresql-setup/pull/16/files#diff-7ee66c4f1536ac84dc5bbff1b8312e2eef24b974b3e48a5c5c2bcfdf2eb8f3ce).


General Notes

Thank you for contributing to sentry-python!

Please add tests to validate your changes, and lint your code using tox -e linters.

Running the test suite on your PR might require maintainer approval. Some tests (AWS Lambda) additionally require a maintainer to add a special label to run and will fail if the label is not present.

For maintainers

Sensitive test suites require maintainer review to ensure that tests do not compromise our secrets. This review must be repeated after any code revisions.

Before running sensitive test suites, please carefully check the PR. Then, apply the Trigger: tests using secrets label. The label will be removed after any code changes to enforce our policy requiring maintainers to review all code revisions before running sensitive tests.

@rominf
Copy link
Contributor Author

rominf commented Jul 11, 2024

Test failure in Test Web Frameworks 2 looks like a flaky test: https://github.com/getsentry/sentry-python/actions/runs/9881406304/job/27310056793.

@szokeasaurusrex
Copy link
Member

Hi @rominf – can you please explain why this change is necessary? I would argue that the tests are fine with the hardcoded port, since the tests work fine in our CI.

@rominf
Copy link
Contributor Author

rominf commented Jul 15, 2024

Hi @szokeasaurusrex.

There is no doubt related tests successfully run on your CI without the change. This is not always true for running these tests in other environments, such as developer machines and other CI/CD servers.

While enabling PostgreSQL-dependent tests for Fedora's python-sentry-sdk package packaging Sentry SDK for Python, I discovered that 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]. Therefore, I had to apply this change to the python-sentry-sdk package as a patch for running these tests [2].

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.

Thus, this few-line 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 where you can find the reasoning (see NEWS file changes: https://github.com/devexp-db/postgresql-setup/pull/16/files#diff-7ee66c4f1536ac84dc5bbff1b8312e2eef24b974b3e48a5c5c2bcfdf2eb8f3ce).
[2] https://src.fedoraproject.org/fork/rominf/rpms/python-sentry-sdk/c/7194c68da701a2b2d76058ec8b48ca7c6b5098e5

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).
@rominf rominf force-pushed the rominf-asyncpg-pg-port branch from 5f7df61 to aba417a Compare July 15, 2024 16:06
Copy link

codecov bot commented Jul 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.43%. Comparing base (855c15f) to head (aba417a).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3281   +/-   ##
=======================================
  Coverage   79.43%   79.43%           
=======================================
  Files         132      132           
  Lines       14280    14280           
  Branches     3002     3002           
=======================================
  Hits        11343    11343           
  Misses       2090     2090           
  Partials      847      847           

@szokeasaurusrex
Copy link
Member

Fair enough @rominf, my main concern is that adding this environment variable will provide only limited usefulness, since it is not documented anywhere.

However, if this feature helps you, I can go ahead and merge it. It looks like we are already allowing other PostreSQL options to be configured via environment variable, so it is probably fine to allow the port to be set as well

@szokeasaurusrex szokeasaurusrex added the Trigger: tests using secrets PR code is safe; run CI label Jul 16, 2024
@github-actions github-actions bot removed the Trigger: tests using secrets PR code is safe; run CI label Jul 16, 2024
@sentrivana sentrivana enabled auto-merge (squash) July 16, 2024 14:19
@sentrivana sentrivana added the Trigger: tests using secrets PR code is safe; run CI label Jul 16, 2024
@sentrivana sentrivana merged commit c76168c into getsentry:master Jul 16, 2024
124 of 126 checks passed
@rominf rominf deleted the rominf-asyncpg-pg-port branch July 16, 2024 14:38
arjennienhuis pushed a commit to arjennienhuis/sentry-python that referenced this pull request Sep 30, 2024
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Trigger: tests using secrets PR code is safe; run CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants