Skip to content

Convert all unit tests to use Postgres - #114

Merged
dnadeau-lanl merged 13 commits into
spacepy:masterfrom
jtniehof:postgres_unittest
Jan 21, 2022
Merged

dnadeau-lanl merged 13 commits into
spacepy:masterfrom
jtniehof:postgres_unittest

Conversation

@jtniehof

@jtniehof jtniehof commented Jan 11, 2022 •

Copy link
Copy Markdown
Member

This PR is a follow on from #113 to do all database-touching unit tests in Postgres as well as sqlite.

Because this removes the sqlite testing database, it closes #34. It does not fill the entire wishlist of #34, in that it doesn't support having lots of different database structures. Long-term, I think the best approach is to implement #7 and then have all tests run against the latest database structure, except for unit tests of the migration tools (which will need other means of building the test databases.)

It also converts the unit tests (and thus CI) to use the version of dbprocessing in the build directory...this lets you test updates without installing them.

The biggest commit is the one that converts the RBSP_mageis database to a JSON file instead of sqlite database. This did a huge amount of work in one commit, because otherwise there would be multiple checked-in versions of the binary test database file, making the repository much larger (this is what we're trying to avoid with this PR). So this commit:

  • Cuts down the size of the magEIS test database
  • Changes tests based on the new database contents
  • Updates tests to load data from a JSON file, allowing postgresql testing.

I found this approach makes the sqlite tests slightly slower (about a minute instead of 30s on my machine) and the Postgresql tests are quite a bit slower yet (about 5 minutes for the whole suite, on my machine). Reducing the size of the test database further didn't affect this much; it seems to be primarily in the table setup and teardown. But that can potentially be looked at later...it's not a ridiculous length of time for the test suite.

Fortunately there were only a couple of Postgresql-related bugs found and fixed by doing these tests.

The use of Postgresql databases is added to the documentation.

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
  • Major new functionality has appropriate Sphinx documentation
  • (N/A) 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)

@jtniehof jtniehof added the testing Affects tests not functionality label Jan 11, 2022
 * Checked-in database remains, since used by unit tests.
 * Remove "full test" since functional and unit tests are now more split,
   running against installed and built versions, respectively.
 * This is a step towards treating these tests more like the emptyDB tests.
…y data

 * Input data now human readable.
   - Remove old testDB.sqlite (functional output)
 * Converts these tests to use Postgresql.
 * Some test fixes for postgres (tests only, not actual functionality):
   - Postgres enforces length limit on character varying
   - Integers 0/1 were being used instead of booleans
 * testDB not emptyDB, since used for more than empty tests.
 * Three main changes in one commit:
   - Cut down the size of the magEIS test database (this is why this is
     all combined in one commit, so that there are not many commits
     with different versions of the large sqlite file.)
   - Change tests based on the new database contents
   - Update tests to load data from a JSON file instead of holding
     the database
 * Also adds ability to pass an existing DButils to the DButils
   constructor, useful in ProcessQueue tests.
 * Includes several fixes for postgresql
   - Return order not guaranteed in postgres, a few tests changed.
   - getProductID when a name is passed in and there is no record.
@jtniehof
jtniehof marked this pull request as ready for review January 21, 2022 22:12
@jtniehof
jtniehof requested a review from dnadeau-lanl January 21, 2022 22:12

@dnadeau-lanl dnadeau-lanl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Impressive. That was a big "json" file.

@dnadeau-lanl
dnadeau-lanl merged commit fb95a08 into spacepy:master Jan 21, 2022
@jtniehof
jtniehof deleted the postgres_unittest branch January 22, 2022 16:00
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.

Create RBSP_MAGEIS.sqlite database

2 participants