Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run Backend Tests in Transactions #2304

Merged
merged 13 commits into from Jan 13, 2021
Merged

Run Backend Tests in Transactions #2304

merged 13 commits into from Jan 13, 2021

Conversation

askvortsov1
Copy link
Sponsor Member

@askvortsov1 askvortsov1 commented Sep 24, 2020

Integration tests are now run in transactions. This has been separated into well-described commits, I recommend looking through those for more info on specifics of changes. Some highlights:

  • populateDatabase no longer actually modifies the database, it just adds data to an object of seed data that will be applied after the transaction begins during app boot. This means:
    • populateDatabase no longer triggers app boot, so we can get rid of all the prepDb stuff and just use setUp
    • populateDatabase does nothing once the app is booted, so we need to use $this->database directly for those changes
  • We now rely on the state of the installed Flarum site (with regards to default user (admin), groups, and permissions), so those do not need to be specified in per-test seed data
  • A trait that enables purging of cached settings has been added. @tankerkiller125 never again shall we face this extremely annoying bug!
  • Seed data for fulltext search test cases is inserted into (and removed from) the database outside of a transaction in a special case, I don't expect to see this anywhere else so there's no util for it.

@askvortsov1 askvortsov1 changed the title [Franz] Run Tests in Transactions Run Backend Tests in Transactions Sep 24, 2020
@askvortsov1 askvortsov1 added this to the 0.1.0-beta.15 milestone Oct 1, 2020
@askvortsov1 askvortsov1 removed this from the 0.1.0-beta.15 milestone Oct 27, 2020
@askvortsov1 askvortsov1 force-pushed the fl/tests-in-transaction branch 7 times, most recently from 9cbf69d to 793e9ed Compare January 7, 2021 22:24
@askvortsov1 askvortsov1 force-pushed the fl/tests-in-transaction branch 3 times, most recently from c153cb9 to b5181f3 Compare January 8, 2021 01:40
Copy link
Member

@SychO9 SychO9 left a comment

Choose a reason for hiding this comment

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

I was wondering why the display name driver test was failing for me locally despite clearing the settings cache. Makes sense now, I missed the fact that it is statically set when the app is booted.

It all looks good to me, nicely done!

tests/integration/extenders/ModelTest.php Outdated Show resolved Hide resolved
franzliedke and others added 6 commits January 9, 2021 00:35
Previously, the `prepareDatabase` method would directly modify the database, booting the app in the process. This would prevent any extenders from being applied, since `->extend()` has no effect once the app is booted.

Since the new implementation of `prepareDatabase` simply registers seed data to be applied during app boot, the workaround of sticking this seed data into `prepDb` is no longer necessary, and seed data common to all test cases in a class can be provided in `setUp`.

When needed, app boot is explicitly triggered in individual test cases by calling `$this->app()`.
Before transactions, each test class would need to explicitly state starting state for permissions, which made the initial permission configuration somewhat arbitrary. Now, we might as well use the initial state of the default installation.

One of the User show_test tests has been commented out until
Some tests need to change settings, but since MemoryCacheSettingsRepository caches settings in-memory, those changes aren't reflected. The new `purgeSettingsCache` removes it from the container, eliminating that cache.

For UserTest, we also need to regenerate the display name driver, since that's set statically on boot, before we'll get a change to clear the settings cache.
Under InnoDB, database entries created in transactions are not processed by fulltext indexes until the transaction is committed. To work around this, cases that test fulltext search have been split off into a separate class that adds and removes seed discussions/posts outside of transactions during setUp/tearDown.
[ci skip] [skip ci]
Copy link
Member

@SychO9 SychO9 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@tankerkiller125 tankerkiller125 left a comment

Choose a reason for hiding this comment

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

Looks good code wise to me, I haven't tested locally but CI is passing. Given the massive changes here maybe one more set of eyeballs before merging?

@askvortsov1 askvortsov1 merged commit 85210ff into master Jan 13, 2021
@askvortsov1 askvortsov1 deleted the fl/tests-in-transaction branch January 13, 2021 02:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants