Skip to content

Ensure seeded merge requests have diffs in development environment

Stan Hu requested to merge sh-fix-mr-db-fixtures into master

What does this MR do and why?

Previously when merge requests were seeded in a development environment, the merge request diffs were never built unless a merge request were closed and reopened. This has been happening since we moved the building of merge request diffs to a Sidekiq job (!100390 (merged)). NewMergeRequestWorker now has to run for a diff to be built, but that job was never run. This commit fixes that problem.

When the development seeds run via bin/rake db:seed_fu, Sidekiq::Testing.fake! is on by default. MergeRequests::CreateService#after_create schedules the running of NewMergeRequestWorker in the merge request's after_commit hook. Since Seed Fu runs the fixture in a transaction, the after_commit hook runs after the seed is completed. Thus in order to build the merge request diff inline, we need to flush the after_commit queue inside a Sidkeiq::Testing.inline! block. In addition, we have to disable the exclusive lease check that would ordinarily raise an error because the exclusive lease is retrieved inside the Seed Fu transaction.

How to set up and validate locally

  1. Attempt to seed merge requests: FILTER=merge_requests bin/rake db:seed_fu.
  2. Look up the last merge request created in the Rails console:
bin/rails c
MergeRequest.last
  1. Go to the merge request and see that the diff doesn't exist.
  2. Check out this branch and repeat steps 1-3.
  3. You should now see diffs present.
Edited by Stan Hu

Merge request reports