Skip to content

Create "empty" test database in unit tests - #113

Merged
dnadeau-lanl merged 5 commits into
spacepy:masterfrom
jtniehof:test_db
Jan 7, 2022
Merged

dnadeau-lanl merged 5 commits into
spacepy:masterfrom
jtniehof:test_db

Conversation

@jtniehof

@jtniehof jtniehof commented Jan 7, 2022

Copy link
Copy Markdown
Member

To date, the unit tests proceed mostly by working on a "reference" sqlite database checked into the repository. One of these is "empty", i.e. contains only the dbprocessing table structure but no data.

This PR removes the checked-in empty database. All tests which use an empty database now create the database structure on the fly at the beginning of the test and destroy it at the end.

This PR also checks for PGDATABASE. If it is set, the empty database tests work on an empty Postgresl database instead of sqlite. The database itself must exist, but not the tables. Other tests continue to use sqlite (this is a task for the future). Because of this, a few test failures in Postgresql were also fixed. Only about 20 of the unit tests work on the empty database, but it's a start.

There was some special handling for Postgres testing in the CI suite; that's gone now. The only difference is the setting of the environment variable.

A note on performance: Obviously all this setup/teardown takes some time. Comparison of timing, for running the entire test suite:

  • Current master (all tests sqlite): 27s
  • This PR, all tests sqlite: 28s
  • This PR, some tests Postgres rest sqlite: 48s

So there isn't much of a performance penalty for tests we already had, and the "slow" bit is brand-new tests of the Postgres functionality, which may just plain have more overhead anyhow.

PR Checklist

  • Pull request has descriptive title
  • Pull request gives overview of changes
  • New code has inline comments where necessary
  • (N/A) Any new modules, functions or classes have docstrings consistent with dbprocessing style
  • (N/A) Major new functionality has appropriate Sphinx documentation
  • (N/A, see below) Added an entry to release notes if fixing a major bug or providing a major new feature
  • New features and bug fixes should have unit tests
  • Relevant issues are linked in the description (use Closes # if this PR closes the issue, or some other reference, such as See # if it is related in some other way)

At this point I'm not putting something in release notes because it isn't a substantial improvement in Postgres support, but it's a step towards #14. I want to get this in the bag before converting the rest of the tests. (Also make sure the CI works properly.)

@jtniehof jtniehof added the testing Affects tests not functionality label Jan 7, 2022
 * Work off empty database (tables populated in tests)
 * Simplify CI configuration, and run PG tests on python 3
@jtniehof
jtniehof marked this pull request as ready for review January 7, 2022 16:41
@jtniehof
jtniehof requested a review from dnadeau-lanl January 7, 2022 16:41
@dnadeau-lanl
dnadeau-lanl merged commit 4300d70 into spacepy:master Jan 7, 2022
@jtniehof
jtniehof deleted the test_db branch January 7, 2022 18:42
@jtniehof jtniehof mentioned this pull request Jan 11, 2022
8 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Affects tests not functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants