Ensure mergeability check runs on specific cases
What does this MR do and why?
We call MergeRequest#check_mergeability on MR page load to trigger mergeability check. Other than that, we rely on calls for MergeRequest#mergeable? to eventually call it as well. This can cause stale MergeRequest#merge_status when:
- Race condition occurred between the MR page load and the time
NewMergeRequestWorkerruns. - The
MergeRequest#merge_statusgets updated after the MR page has already loaded (e.g. new changes were pushed to the MR's target branch).
As a fix, we are calling MergeRequest#check_mergeability in more
places to ensure we check for it:
- We now call it on
MergeRequests::AfterCreateServiceto prevent race condition issue. This service is called by theNewMergeRequestWorker. This way, we ensure that we check for MR's mergeability after it was created. -
MergeRequestPollCachedWidgetEntity#merge_statushas been updated so whenever theMergeRequest#merge_statusgets updated and the MR widget polls for updated status, we will recheck for mergeability as well. On next poll, it should show the updatedmerge_status. - The
check_mergeability_async_in_widgetFF has also been removed since it doesn't seem to be used at all. We also need to keep the call forMergeRequest#check_mergeabilityon the show action so we won't need to wait for poll in case the merge status gets updated and the user decides to refresh the page.
How to set up and validate locally
Numbered steps to set up and validate the change are strongly suggested.
- Create a MR.
- Check that MR widget is updated and able to merge.
- Update the
merge_statusof the MR manually via Rails console and set it to unchecked by callingmark_as_unchecked!. - Wait for the MR widget to poll and eventually update to a mergeable state.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #351190 (closed)