Commit 43d6328f authored by Stan Hu's avatar Stan Hu

Merge branch 'fix-random-failing-tests' into 'master'

Fix randomly failing specs (possibly caused by DatabaseCleaner)

## What does this MR do?

This MR ensures that DatabaseCleaner.clean runs AFTER Capybara's cleanup. This is needed because it *seems* like database is being truncated before capybara session ends, which leads to `undefined method ... for nil:NilClass` exceptions causing tests to randomly fail.

## Are there points in the code the reviewer needs to double check?

Failing spec is https://gitlab.com/gitlab-org/gitlab-ce/blob/master/spec/features/boards/boards_spec.rb. Here are some examples of failed builds: 

- https://gitlab.com/gitlab-org/gitlab-ce/builds/3352437
- https://gitlab.com/certik/gitlab-ce/builds/3359940
- https://gitlab.com/gitlab-org/gitlab-ee/builds/3365914

## Why was this MR needed?

I've noticed that many branches suffer from random failures and it's not very comfortable for big test suite. Re-running builds until they pass is not a solution so I tried to come up with a fix. Unfortunately I can't be 100% sure about this fix (flaky test is always green on my local environment, so I can't be sure if green build on CI is false-positive or not), but if database is really being cleaned too early (which is clearly proved by logs provided here https://gitlab.com/gitlab-org/gitlab-ce/issues/21841#note_14926675 then it's very likely that this fix will help to get rid of random failures.

Also it's officially recommended in DatabaseCleaner README to use `append_after` hook instead of just `after` because of the way RSpec runs after hooks (in reverse order):

> It's also recommended to use append_after to ensure DatabaseCleaner.clean runs after the after-test cleanup capybara/rspec installs.

([source](https://github.com/DatabaseCleaner/database_cleaner#rspec-with-capybara-example))

## What are the relevant issue numbers?

#21197

See merge request !6198
parents fc0ceb20 49ea6ac7
......@@ -15,7 +15,7 @@ RSpec.configure do |config|
DatabaseCleaner.start
end
config.after(:each) do
config.append_after(:each) do
DatabaseCleaner.clean
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment