Commit Graph

17 Commits

Author SHA1 Message Date
Hannah Wolfe
911ce5f92d Cleaned up db-utils and added jsdocs
- Attempted to make it clearer what the db utils do and what each one is for
- Clearly marked the old clearData & initData as deprecated, we don't want to mix db and url service resets
2022-03-17 17:33:11 +00:00
Hannah Wolfe
11a792f7df Wrapped test teardown in a fallback
- The fast truncateAll method can fail
- If it does, use knex-migrate to do a safe reset of the DB instead
- This is being done to try to make test runs more reliable in the face of database errors
2022-03-17 17:33:11 +00:00
Hannah Wolfe
b90e367563 Fixed error handling on db truncate in tests
- if the database does not exist, ignore the error
   - tables that don't exist don't need truncating
   - instead wait until the next thing calls init, that will cause a fresh db to be created in the correct state
- inside of reset, if the truncate fails then do a full reset instead
2022-03-17 17:33:11 +00:00
Hannah Wolfe
83ad79308b Updated tests to use DatabaseInfo
- some code in tests were still using various unreliable methods to determine the database in use
- DatabaseInfo is the correct method to check if the db is mysql or sqlite
- Exposed DatabaseInfo via our test db-utils to make this easier
2022-03-17 17:33:11 +00:00
Hannah Wolfe
2cc2d114f4
Revert "Added global setup to reset DB before test run"
This reverts commit d50fb7c922.
2022-03-16 21:10:49 +00:00
Hannah Wolfe
d50fb7c922
Added global setup to reset DB before test run
- We've been seeing weird errors with tables not existing when running tests locally
- This appears to happen after an error causes the tests to abort
- This change includes two fixes:
1. we triggers a full DB reset just before the entire test suite runs
 - this is done by wrapping the override file for tests that use a db, and supplying a mochaGlobalSetup hook
2. catch errors when attempting to do a fast truncation-based reset & init, and do a full reset & init instead

- These two changes should ensure the DB is always in the state we expect when running a new test suite
2022-03-16 20:56:17 +00:00
Daniel Lockyer
828a5d4d5a Restored quick database reset method via table truncation
refs a3cc66be50

- in the referenced commit, I made a util to speed up resetting the DB
  for SQLite by copying the database file
- I inadvertently removed an optimization we had before - where we
  truncate the tables and insert the fixtures instead of dropping the
  entire database
- this would be missing on MySQL tests
- this seems to have a big difference so this commit re-adds the
  optimization in
2022-02-07 21:27:10 +01:00
Daniel Lockyer
4673bd05fc
Destroyed connection before restoring DB file
no issue

- we've seen some instances of SQLite saying "database disk image is malformed"
- I think this happens because we copy the file whilst we are still connected to
  the old DB
- this commit destroys the connection before copying the clean file to the live
  DB file
2021-12-07 08:23:51 +00:00
Daniel Lockyer
a3cc66be50 Copied DB for faster SQLite tests
refs https://github.com/TryGhost/Toolbox/issues/136

- we nuke and reinitialize the DB many times between tests
- this forms a good portion of the time taken and we shouldn't be spending
  so much time on just resetting the DB back to a known state
- this commit switches out the knex-migrator reset + init calls for SQLite to
  a function which keeps a clean copy of the DB and copies the file back
  when we "reset"
- for MySQL, existing functionality is kept
- this massively speeds up tests because it saves ~700ms+ for every reset
- whilst this change seems to work, it's just the start so there's a
  lot more refactoring needed. this change is currently gated to CI until
  it's deemed safe/sane enough to run on local machines without blowing
  up
2021-12-06 15:22:44 +00:00
Hannah Wolfe
cc9e256b36 Added extra debug to test utilities
- Looking for places we can SAVE TIME running tests
2021-11-19 10:47:21 +00:00
Sam Lord
35e51e364b Switch to @tryghost/debug, remove ghost-ignition
no issue
The only pieces of Ghost-Ignition used in Ghost were debug and
logging. Both of these modules have been superceded by the Framework
monorepo, and all usages of Ignition have now been removed, replaced
with @tryghost/debug and @tryghost/logging.
2021-06-15 17:24:22 +01:00
Hannah Wolfe
1025600ae1 Cleaned up some unused code in test fixtures
- the themeService.loadAll method was refactored out ages ago, so this clearly isn't used in tests
- the rest are requires I spotted whilst working around the codebase
- note: we have noUnusedVars disabled as a linting error in tests because else should complains everywhere
2021-04-26 13:20:07 +01:00
Thibaut Patel
874ccaef53 💡 Enabled foreign key checks on sqlite3
issue https://github.com/TryGhost/Team/issues/476
2021-03-02 11:13:19 +01:00
Hannah Wolfe
70ed998838 Replaced db.ready event with direct call to urlservice
refs dd715b33dc

- this is the last event that is used to trigger part of the standard boot process
- events make the code harder to read/reason about
- the urlservice is one of the most core and critical components in Ghost, possibly the biggest consumer of time and memory
- we want to have the work it is doing front and center so that we can improve it
2021-02-23 10:05:59 +00:00
Hannah Wolfe
24bfb5567b Cleaned up test utils with async/await
- I'm on a mission to make this code comprehensible so we can work it into something better with new boot
- Who else loves async/await? :D
- Dried up a block of duplicated code
2021-02-18 10:15:19 +00:00
Hannah Wolfe
1b4ebce3b0 Split urlServiceUtils from testUtils & unified
- There is now just one way to wait until the UrlService is finished across all of our tests!
- db.ready is only called in the one utility + the actual UrlService tests
2021-02-17 17:36:27 +00:00
Hannah Wolfe
21b30c94f4 Split test utilities out into separate files
- The current huge test utilities file is really hard to reason about
- It is so big we have no idea what's in it anymore
- It's also full of terrible code we want to rework
- Splitting it down into smaller pieces makes it easier to see which are the worst bits!
2021-02-16 20:17:04 +00:00