Skip to content

gh-108550: Speed up sqlite3 tests#108551

Merged
erlend-aasland merged 4 commits into
python:mainfrom
erlend-aasland:sqlite/speed-up-tests
Aug 28, 2023
Merged

gh-108550: Speed up sqlite3 tests#108551
erlend-aasland merged 4 commits into
python:mainfrom
erlend-aasland:sqlite/speed-up-tests

Conversation

@erlend-aasland

@erlend-aasland erlend-aasland commented Aug 27, 2023

Copy link
Copy Markdown
Contributor

Refactor the CLI so we can easily invoke it and mock command-line
arguments. Adapt the CLI tests so we no longer have to launch a
separate process.

Disable the busy handler for all concurrency tests; we have full
control over the order of the SQLite C API calls, so we can safely
do this.

The sqlite3 test suite now completes ~8 times faster than before.

Refactor the CLI so we can easily invoke it and mock command-line
arguments. Adapt the CLI tests so we no longer have to launch a
separate process.

Disable the busy handler for all concurrency tests; we have full
control over the order of the SQLite C API calls, so we can safely
do this.

The sqlite3 test suite now completes ~10 times faster than before.
@erlend-aasland

Copy link
Copy Markdown
Contributor Author

I ran this some hundred times locally:

$ ./python.exe -m test test_sqlite3 -F
Raised RLIMIT_NOFILE: 256 -> 1024
0:00:00 load avg: 4.23 Run tests sequentially
0:00:00 load avg: 4.23 [  1] test_sqlite3
Warning -- files was modified by test_sqlite3
Warning --   Before: []
Warning --   After:  ['default.profraw'] 
Warning -- files was modified by test_sqlite3
Warning --   Before: []
Warning --   After:  ['default.profraw'] 
0:00:00 load avg: 4.23 [  2/1] test_sqlite3 -- test_sqlite3 failed (env changed)
[...]
0:03:25 load avg: 5.57 [694/1] test_sqlite3

(env changes is because I have profiling enabled by default on my local build)

@erlend-aasland

Copy link
Copy Markdown
Contributor Author

@AlexWaygood, want to have a quick look at the __main__.py and test_cli change? The latter could use a refactor, but I'm not sure it is worth the churn.

@erlend-aasland

Copy link
Copy Markdown
Contributor Author

cc. @serhiy-storchaka if you want to have a look

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

But it was possible to rewrite InteractiveSession tests in such way because you do not test interactivity. For example, that the prompt is displayed before any input. That the continuation line prompt is displayed before finishing the multiline command. In future we can build readline support in the REPL and add tests for history or completion.

Is it possible to support multiple communicate()?

@erlend-aasland

Copy link
Copy Markdown
Contributor Author

Yeah, InteractiveSession had flaws, and it is suboptimal currently. I thought realine support was baked into the interactive console class from code, but I may be misremembering.

@erlend-aasland

Copy link
Copy Markdown
Contributor Author

Is it possible to support multiple communicate()?

It should be possible, but I think that is out of scope for this PR.

@serhiy-storchaka

Copy link
Copy Markdown
Member

On other hand, it is not necessary. There is already a test for initial prompt. We can just add a new test for incomplete multiline input and check secondary prompts. See #108556.

@erlend-aasland

Copy link
Copy Markdown
Contributor Author

On other hand, it is not necessary. There is already a test for initial prompt. We can just add a new test for incomplete multiline input and check secondary prompts. See #108556.

We already do, no? test_interact_valid_multiline_sql checks for PS2.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many ways to break the interactive session, but keep the changed tests passed:

  • Read input not line by line, by the whole content. It delays any interaction until stdin be closed.
  • Buffer stdout, or stderr, or both until the program ends.

So I am not sure about this change. Maybe simulating a subprocess with a thread can mitigate the problem, but we need an analogue of blocking PipeInputStream for this.

There are no such problems with non-interactive tests.

Comment thread Lib/test/test_sqlite3/test_transactions.py
Comment thread Lib/test/test_sqlite3/test_cli.py Outdated
Comment thread Lib/sqlite3/__main__.py Outdated
erlend-aasland and others added 3 commits August 28, 2023 10:25
@erlend-aasland

Copy link
Copy Markdown
Contributor Author

This PR seems to risk running stale. I'm opening a more narrowed PR for the busy timeout optimisation instead.

@erlend-aasland erlend-aasland marked this pull request as draft August 28, 2023 12:07

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I approve this change, but I afraid that we will need to revert some of them in future.

@erlend-aasland

Copy link
Copy Markdown
Contributor Author

I approve this change, but I afraid that we will need to revert some of them in future.

Yes, I also believe we need to further rework the interactive tests. I'm not even sure we need all of them.

@erlend-aasland

Copy link
Copy Markdown
Contributor Author

Thanks for the review, Serhiy.

@erlend-aasland erlend-aasland merged commit 0e8b3fc into python:main Aug 28, 2023
@miss-islington

This comment was marked as outdated.

@erlend-aasland erlend-aasland deleted the sqlite/speed-up-tests branch August 28, 2023 12:17
@miss-islington

Copy link
Copy Markdown
Contributor

Sorry, @erlend-aasland, I could not cleanly backport this to 3.11 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 0e8b3fc718c8a1c4de558c553d9e05049c1dbec6 3.11

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 28, 2023
Refactor the CLI so we can easily invoke it and mock command-line
arguments. Adapt the CLI tests so we no longer have to launch a
separate process.

Disable the busy handler for all concurrency tests; we have full
control over the order of the SQLite C API calls, so we can safely
do this.

The sqlite3 test suite now completes ~8 times faster than before.

(cherry picked from commit 0e8b3fc)

Co-authored-by: Erlend E. Aasland <erlend@python.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-bot

Copy link
Copy Markdown

GH-108566 is a backport of this pull request to the 3.12 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.12 only security fixes label Aug 28, 2023
erlend-aasland added a commit to erlend-aasland/cpython that referenced this pull request Aug 28, 2023
Disable the busy handler for all concurrency tests; we have full
control over the order of the SQLite C API calls, so we can safely
do this.

test_sqlite3.test_transactions now completes ~10 times faster than before.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
erlend-aasland added a commit to erlend-aasland/cpython that referenced this pull request Aug 28, 2023
Disable the busy handler for all concurrency tests; we have full
control over the order of the SQLite C API calls, so we can safely
do this.

test_sqlite3.test_transactions now completes ~10 times faster than before.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-bot

Copy link
Copy Markdown

GH-108567 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Aug 28, 2023

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post-merge review: LGTM too (though I'm no expert on testing interactive REPLs)!

Execution time for me on Windows went down from 3.8s to 548ms :D

@erlend-aasland

Copy link
Copy Markdown
Contributor Author

Execution time for me on Windows went down from 3.8s to 548ms :D

Yay! 😃

erlend-aasland added a commit that referenced this pull request Aug 28, 2023
Disable the busy handler for all concurrency tests; we have full
control over the order of the SQLite C API calls, so we can safely
do this.

test_sqlite3.test_transactions now completes ~10 times faster than before.

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Yhg1s pushed a commit that referenced this pull request Aug 28, 2023
gh-108550: Speed up sqlite3 tests (GH-108551)

Refactor the CLI so we can easily invoke it and mock command-line
arguments. Adapt the CLI tests so we no longer have to launch a
separate process.

Disable the busy handler for all concurrency tests; we have full
control over the order of the SQLite C API calls, so we can safely
do this.

The sqlite3 test suite now completes ~8 times faster than before.

(cherry picked from commit 0e8b3fc)

Co-authored-by: Erlend E. Aasland <erlend@python.org>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
erlend-aasland added a commit to erlend-aasland/cpython that referenced this pull request Aug 29, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 29, 2023
…honGH-108618)

(cherry picked from commit c884784)

Co-authored-by: Erlend E. Aasland <erlend@python.org>
Yhg1s pushed a commit that referenced this pull request Aug 29, 2023
… (#108621)

gh-108550: Fix sqlite3 CLI regression from gh-108551 (GH-108618)
(cherry picked from commit c884784)

Co-authored-by: Erlend E. Aasland <erlend@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants