Skip to content
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

Run tests against multiple PostgreSQL versions #139

Closed
simonw opened this issue Jul 4, 2021 · 15 comments · Fixed by #140
Closed

Run tests against multiple PostgreSQL versions #139

simonw opened this issue Jul 4, 2021 · 15 comments · Fixed by #140
Labels
ci Continuous integration with GitHub Actions

Comments

@simonw
Copy link
Owner

simonw commented Jul 4, 2021

It would be great to have the GitHub Actions workflow run tests against multiple PostgreSQL versions to catch this kind of thing in the future https://github.com/simonw/django-sql-dashboard/blob/main/.github/workflows/test.yml

Originally posted by @simonw in #138 (comment)

@simonw simonw added the ci Continuous integration with GitHub Actions label Jul 4, 2021
@ryancheley
Copy link
Contributor

Looks like this might help as a starting point

https://justatheory.com/2020/06/test-extensions-with-github-actions/

@simonw
Copy link
Owner Author

simonw commented Jul 5, 2021

https://www.postgresql.org/download/linux/ubuntu/ has relevant instructions too.

The list of currently supported PostgreSQL versions is at https://www.postgresql.org/support/versioning/ - currently that's:

  • 9.6
  • 10
  • 11
  • 12
  • 13

@simonw
Copy link
Owner Author

simonw commented Jul 5, 2021

The GitHub Actions ubuntu-latest worker has PostgreSQL 13 by default - checked with tmate:

runner@fv-az206-57:~/work/datasette/datasette$ /usr/lib/postgresql/13/bin/postgres --version
postgres (PostgreSQL) 13.3 (Ubuntu 13.3-1.pgdg20.04+1)

@simonw
Copy link
Owner Author

simonw commented Jul 5, 2021

I tried running this:

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql-12

And now this works too:

runner@fv-az206-57:~/work/datasette/datasette$ /usr/lib/postgresql/12/bin/postgres --version
postgres (PostgreSQL) 12.7 (Ubuntu 12.7-1.pgdg20.04+1)

@simonw
Copy link
Owner Author

simonw commented Jul 5, 2021

sudo apt-get -y install postgresql-10 worked but sudo apt-get -y install postgresql-9 did not.

@simonw
Copy link
Owner Author

simonw commented Jul 6, 2021

Since this installs multiple PostgreSQL versions I need to figure out how to tell testing.postgresql which one to launch. https://github.com/tk0miya/testing.postgresql/blob/master/src/testing/postgresql.py is relevant code.

@simonw
Copy link
Owner Author

simonw commented Jul 6, 2021

        self.postgres = self.settings.pop('postgres')
        if self.postgres is None:
            self.postgres = find_program('postgres', ['bin'])

So I need to use the settings["postgres"] mechanism, which is a parameter passed to this constructor:

from testing.postgresql import Postgresql
_POSTGRESQL = Postgresql()

@simonw
Copy link
Owner Author

simonw commented Jul 6, 2021

I'm going to test on 10, 11, 12 and 13 - using a matrix.

@simonw
Copy link
Owner Author

simonw commented Jul 6, 2021

If this passes I'll revert the change from #138 on this branch to confirm that it fails, then merge the new tests.

@simonw
Copy link
Owner Author

simonw commented Jul 6, 2021

Error:

  File "/opt/hostedtoolcache/Python/3.6.13/x64/lib/python3.6/site-packages/testing/common/database.py", line 171, in wait_booting
    self.read_bootlog())
RuntimeError: *** failed to launch Postgresql ***
2021-07-06 00:20:45.509 UTC [4414] FATAL:  database files are incompatible with server
2021-07-06 00:20:45.509 UTC [4414] DETAIL:  The data directory was initialized by PostgreSQL version 13, which is not compatible with this version 11.12 (Ubuntu 11.12-1.pgdg20.04+1).

@simonw
Copy link
Owner Author

simonw commented Jul 6, 2021

I think this is the problem:

    def initialize(self):
        self.initdb = self.settings.pop('initdb')
        if self.initdb is None:
            self.initdb = find_program('initdb', ['bin'])

        self.postgres = self.settings.pop('postgres')
        if self.postgres is None:
            self.postgres = find_program('postgres', ['bin'])

So I need to pass in a custom path to initdb too.

simonw added a commit that referenced this issue Jul 6, 2021
@simonw
Copy link
Owner Author

simonw commented Jul 6, 2021

That passed against all PostgreSQL versions!

simonw added a commit that referenced this issue Jul 6, 2021
@simonw
Copy link
Owner Author

simonw commented Jul 6, 2021

I expect this to break in PostgreSQL 10.

@simonw
Copy link
Owner Author

simonw commented Jul 6, 2021

Revert__Fix_issue_with_Postgres_10___138___-_to_help_test__139_·_simonw_django-sql-dashboard_9bc6ff2

It failed against PostgreSQL 10 as expected.

simonw added a commit that referenced this issue Jul 6, 2021
* Run tests against multiple PostgreSQL versions, closes #139
simonw added a commit that referenced this issue Jul 6, 2021
simonw added a commit that referenced this issue Jul 6, 2021
@simonw
Copy link
Owner Author

simonw commented Jul 6, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci Continuous integration with GitHub Actions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants