Defect #44072
closedOauthProviderSystemTest#test_application_creation_and_authorization fails randomly
Description
OauthProviderSystemTest#test_application_creation_and_authorization fails randomly in CI with the following error:
Failure: OauthProviderSystemTest#test_application_creation_and_authorization [test/system/oauth_provider_test.rb:84]: Expected nil to be truthy.
After clicking the Authorize button, the browser is redirected to a server (127.0.0.1 on a random port) to simulate an OAuth client. Capybara does not guarantee that the redirect is fully complete before the next line is executed. If the test queries the database for the access grant before Doorkeeper finishes writing it, the result is nil and the assertion fails.
Fix¶
Move the Capybara wait assertion (find 'p', text: /Authorization succeeded/) before the database check. This ensures the full authorization flow including the redirect is complete before querying the database.
Running the test 20 times in our local CI environment, OauthProviderSystemTest#test_application_creation_and_authorization did not fail once. This fix should at least reduce the frequency of failures.
diff --git a/test/system/oauth_provider_test.rb b/test/system/oauth_provider_test.rb
index f9439affa..98041542c 100644
--- a/test/system/oauth_provider_test.rb
+++ b/test/system/oauth_provider_test.rb
@@ -81,13 +81,13 @@ class OauthProviderSystemTest < ApplicationSystemTestCase
click_button 'Authorize'
- assert grant = app.access_grants.last
- assert_equal 'view_issues view_project', grant.scopes.to_s
-
- # check for output defined above in the request handler
+ # wait for redirect to complete before checking the database
find 'p', visible: true, text: /Authorization succeeded/
assert token.present?
+ assert grant = app.access_grants.last
+ assert_equal 'view_issues view_project', grant.scopes.to_s
+
visit '/my/account'
click_link 'Authorized applications'
find 'td', visible: true, text: /Oauth Test/
Related issues
Updated by Go MAEDA 21 days ago
- Related to Feature #24808: OAuth2 support for Redmine API Apps (OAuth2 Provider) added
Updated by Go MAEDA 14 days ago
- Status changed from Closed to Resolved
- Target version set to 6.1.3
Go MAEDA wrote in #note-2:
Committed the fix as part of #24808.
I mistakenly thought the target version of #24808 was the unreleased 7.0.0, but it was actually the already released 6.1.0.
Therefore, this fix should be treated as a separate fix rather than part of #24808, and it should be backported to the 6.1-stable branch.
Based on this, I am changing the target version of this issue to 6.1.3.