simonw / db-to-sqlite

CLI tool for exporting tables or queries from any SQL database to a SQLite file
Apache License 2.0
368 stars 28 forks source link

Some of the tests are hanging in CI #47

Closed simonw closed 1 year ago

simonw commented 1 year ago

https://github.com/simonw/db-to-sqlite/actions/runs/4109081649

image

I hit cancel workflow when it was clear three of them were not going to finish.

simonw commented 1 year ago

All three of the cancelled ones reported the same almost-complete status:

platform linux -- Python 3.11.1, pytest-7.2.1, pluggy-1.0.0 -- /opt/hostedtoolcache/Python/3.11.1/x64/bin/python
cachedir: .pytest_cache
rootdir: /home/runner/work/db-to-sqlite/db-to-sqlite
collecting ... collected 19 items

tests/test_db_to_sqlite.py::test_db_to_sqlite[mysql://root@127.0.0.1:3306/test_db_to_sqlite] PASSED [  5%]
tests/test_db_to_sqlite.py::test_db_to_sqlite[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 10%]
tests/test_db_to_sqlite.py::test_db_to_sqlite[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 15%]
tests/test_db_to_sqlite.py::test_index_fks[mysql://root@127.0.0.1:3306/test_db_to_sqlite] PASSED [ 21%]
tests/test_db_to_sqlite.py::test_index_fks[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 26%]
tests/test_db_to_sqlite.py::test_index_fks[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 31%]
tests/test_db_to_sqlite.py::test_specific_tables[mysql://root@127.0.0.1:3306/test_db_to_sqlite] PASSED [ 36%]
tests/test_db_to_sqlite.py::test_specific_tables[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 42%]
tests/test_db_to_sqlite.py::test_specific_tables[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 47%]
tests/test_db_to_sqlite.py::test_sql_query[mysql://root@127.0.0.1:3306/test_db_to_sqlite] PASSED [ 52%]
tests/test_db_to_sqlite.py::test_sql_query[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 57%]
tests/test_db_to_sqlite.py::test_sql_query[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 63%]
tests/test_db_to_sqlite.py::test_postgres_schema PASSED                  [ 68%]
tests/test_docs.py::test_readme_contains_latest_help PASSED              [ 73%]
tests/test_fixtures.py::test_fixture_mysql PASSED                        [ 78%]
tests/test_fixtures.py::test_fixture_postgresql PASSED                   [ 84%]
tests/test_redact.py::test_redact[mysql://root@127.0.0.1:3306/test_db_to_sqlite] PASSED [ 89%]
tests/test_redact.py::test_redact[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 94%]
Error: The operation was canceled.
simonw commented 1 year ago

Deduped the tests that pass are:

test_db_to_sqlite.py::test_db_to_sqlite
test_db_to_sqlite.py::test_index_fks
test_db_to_sqlite.py::test_postgres_schema                  
test_db_to_sqlite.py::test_specific_tables
test_db_to_sqlite.py::test_sql_query
test_docs.py::test_readme_contains_latest_help              
test_fixtures.py::test_fixture_mysql                        
test_fixtures.py::test_fixture_postgresql                   
test_redact.py::test_redact

When I run locally there's only one test that isn't in that list:

test_postgres_schema

This test here:

https://github.com/simonw/db-to-sqlite/blob/a2ae06effad5ba4ec16fb834db2601207b4f7192/tests/test_db_to_sqlite.py#L108-L122

simonw commented 1 year ago

The SQL for creating that other schema looked odd to me:

https://github.com/simonw/db-to-sqlite/blob/a2ae06effad5ba4ec16fb834db2601207b4f7192/tests/conftest.py#L133-L139

Shouldn't that have a semicolon after CREATE SCHEMA other_schema?

The tests have been passing for a couple of years so apparently that worked OK before though.

simonw commented 1 year ago

Weird: this workaround got 3.10 to pass but still seems to hang for 3.9 and 3.11.

image

https://github.com/simonw/db-to-sqlite/actions/runs/4109240953/jobs/7090852122

simonw commented 1 year ago

Still hanging for 3.9 and 3.11: https://github.com/simonw/db-to-sqlite/actions/runs/4109280459/jobs/7090938290

It gets this far still:

tests/test_redact.py::test_redact[mysql://root@127.0.0.1:3306/test_db_to_sqlite] PASSED [ 89%]
tests/test_redact.py::test_redact[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 94%]

It looks like the last of the series of test_redact tests might be hanging - that's the second PostgreSQL one that uses postgres:// as the connection string instead of postgresql://:

https://github.com/simonw/db-to-sqlite/blob/e722d7e4fff3c105117b014b6048f5b59065af1a/tests/shared.py#L39-L45

simonw commented 1 year ago

Maybe more likely though is that the code that tears down the PostgreSQL test servers is hanging for some reason.

simonw commented 1 year ago

Urgh. Removing that postgres:// thing didn't fix the problem either.

https://github.com/simonw/db-to-sqlite/actions/runs/4109349112/jobs/7091083066

platform linux -- Python 3.8.16, pytest-7.2.1, pluggy-1.0.0 -- /opt/hostedtoolcache/Python/3.8.16/x64/bin/python
cachedir: .pytest_cache
rootdir: /home/runner/work/db-to-sqlite/db-to-sqlite
collecting ... collected 14 items

tests/test_db_to_sqlite.py::test_db_to_sqlite[mysql://root@127.0.0.1:3306/test_db_to_sqlite] PASSED [  7%]
tests/test_db_to_sqlite.py::test_db_to_sqlite[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 14%]
tests/test_db_to_sqlite.py::test_index_fks[mysql://root@127.0.0.1:3306/test_db_to_sqlite] PASSED [ 21%]
tests/test_db_to_sqlite.py::test_index_fks[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 28%]
tests/test_db_to_sqlite.py::test_specific_tables[mysql://root@127.0.0.1:3306/test_db_to_sqlite] PASSED [ 35%]
tests/test_db_to_sqlite.py::test_specific_tables[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 42%]
tests/test_db_to_sqlite.py::test_sql_query[mysql://root@127.0.0.1:3306/test_db_to_sqlite] PASSED [ 50%]
tests/test_db_to_sqlite.py::test_sql_query[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 57%]
tests/test_db_to_sqlite.py::test_postgres_schema PASSED                  [ 64%]
tests/test_docs.py::test_readme_contains_latest_help PASSED              [ 71%]
tests/test_fixtures.py::test_fixture_mysql PASSED                        [ 78%]
tests/test_fixtures.py::test_fixture_postgresql PASSED                   [ 85%]
tests/test_redact.py::test_redact[mysql://root@127.0.0.1:3306/test_db_to_sqlite] PASSED [ 92%]
Error: The operation was canceled.

There's still something which is causing the tests to hang towards the end of the run.

simonw commented 1 year ago

Still the same problem: https://github.com/simonw/db-to-sqlite/actions/runs/4109380335/jobs/7091148981

Even skipping the test_redact() test - so it's clearly not that test that is causing the problem:

platform linux -- Python 3.9.16, pytest-7.2.1, pluggy-1.0.0 -- /opt/hostedtoolcache/Python/3.9.16/x64/bin/python
cachedir: .pytest_cache
rootdir: /home/runner/work/db-to-sqlite/db-to-sqlite
collecting ... collected 19 items

tests/test_db_to_sqlite.py::test_db_to_sqlite[mysql://root@127.0.0.1:3306/test_db_to_sqlite] PASSED [  5%]
tests/test_db_to_sqlite.py::test_db_to_sqlite[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 10%]
tests/test_db_to_sqlite.py::test_db_to_sqlite[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 15%]
tests/test_db_to_sqlite.py::test_index_fks[mysql://root@127.0.0.1:3306/test_db_to_sqlite] PASSED [ 21%]
tests/test_db_to_sqlite.py::test_index_fks[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 26%]
tests/test_db_to_sqlite.py::test_index_fks[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 31%]
tests/test_db_to_sqlite.py::test_specific_tables[mysql://root@127.0.0.1:3306/test_db_to_sqlite] PASSED [ 36%]
tests/test_db_to_sqlite.py::test_specific_tables[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 42%]
tests/test_db_to_sqlite.py::test_specific_tables[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 47%]
tests/test_db_to_sqlite.py::test_sql_query[mysql://root@127.0.0.1:3306/test_db_to_sqlite] PASSED [ 52%]
tests/test_db_to_sqlite.py::test_sql_query[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 57%]
tests/test_db_to_sqlite.py::test_sql_query[***127.0.0.1:5432/test_db_to_sqlite] PASSED [ 63%]
tests/test_db_to_sqlite.py::test_postgres_schema PASSED                  [ 68%]
tests/test_docs.py::test_readme_contains_latest_help PASSED              [ 73%]
tests/test_fixtures.py::test_fixture_mysql PASSED                        [ 78%]
tests/test_fixtures.py::test_fixture_postgresql PASSED                   [ 84%]
tests/test_redact.py::test_redact[mysql://root@127.0.0.1:3306/test_db_to_sqlite] SKIPPED (https://github.com/simonw/db-to-sqlite/issues/47) [ 89%]
tests/test_redact.py::test_redact[***127.0.0.1:5432/test_db_to_sqlite] SKIPPED (https://github.com/simonw/db-to-sqlite/issues/47) [ 94%]
Error: The operation was canceled.
simonw commented 1 year ago

https://pybit.es/articles/pytest-timeout/ suggests using pytest-timeout and running it with these options in order to get a detailed traceback:

pytest --timeout=3 --timeout_method=thread
simonw commented 1 year ago

One of the MySQL tests failed with the timeout!

https://github.com/simonw/db-to-sqlite/actions/runs/4109415108/jobs/7091221231

  File "/home/runner/work/db-to-sqlite/db-to-sqlite/tests/conftest.py", line 171, in setup_mysql
    cursor.execute("DROP DATABASE {};".format(bits.database))
  File "/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/MySQLdb/cursors.py", line 319, in _query
    db.query(q)
  File "/opt/hostedtoolcache/Python/3.8.16/x64/lib/python3.8/site-packages/MySQLdb/connections.py", line 254, in query
    _mysql.connection.query(self, query)

+++++++++++++++++++++++++++++++++++ Timeout ++++++++++++++++++++++++++++++++++++
Error: Process completed with exit code 1.

Looks like it failed during an attempt to drop the database.

simonw commented 1 year ago

The PostgreSQL fixture doesn't actually bother trying to drop the database - I've removed that from the MySQL one too.

simonw commented 1 year ago

Yup, the MySQL teardown change fixed it.

My best guess is there was a transaction left open which was blocking the DROP DATABASE from running - absolutely no idea why that would only affect some versions of Python and not others though.