Project

General

Profile

Actions

Defect #44072

closed

OauthProviderSystemTest#test_application_creation_and_authorization fails randomly

Added by Mizuki ISHIKAWA about 11 hours ago. Updated about 5 hours ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Code cleanup/refactoring
Target version:
-
Resolution:
Fixed
Affected version:

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

Related to Redmine - Feature #24808: OAuth2 support for Redmine API Apps (OAuth2 Provider)ClosedMarius BĂLTEANUActions
Actions #1

Updated by Go MAEDA about 11 hours ago

  • Related to Feature #24808: OAuth2 support for Redmine API Apps (OAuth2 Provider) added
Actions #2

Updated by Go MAEDA about 5 hours ago

  • Status changed from New to Closed
  • Assignee set to Go MAEDA
  • Resolution set to Fixed

Committed the fix as part of #24808.

Actions

Also available in: Atom PDF