Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
d4f65056
Commit
d4f65056
authored
Nov 12, 2021
by
Andrejs Cunskis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ability to pass custom message to repeater
parent
ea2d0e11
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
73 additions
and
26 deletions
+73
-26
qa/qa/page/base.rb
qa/qa/page/base.rb
+19
-10
qa/qa/page/group/bulk_import.rb
qa/qa/page/group/bulk_import.rb
+1
-1
qa/qa/support/repeater.rb
qa/qa/support/repeater.rb
+7
-3
qa/qa/support/retrier.rb
qa/qa/support/retrier.rb
+7
-4
qa/spec/support/repeater_spec.rb
qa/spec/support/repeater_spec.rb
+33
-8
qa/spec/support/retrier_spec.rb
qa/spec/support/retrier_spec.rb
+6
-0
No files found.
qa/qa/page/base.rb
View file @
d4f65056
...
...
@@ -57,16 +57,25 @@ module QA
end
end
def
retry_until
(
max_attempts:
3
,
reload:
false
,
sleep_interval:
0
,
raise_on_failure:
true
)
Support
::
Retrier
.
retry_until
(
max_attempts:
max_attempts
,
reload_page:
(
reload
&&
self
),
sleep_interval:
sleep_interval
,
raise_on_failure:
raise_on_failure
)
do
yield
end
end
def
retry_on_exception
(
max_attempts:
3
,
reload:
false
,
sleep_interval:
0.5
)
Support
::
Retrier
.
retry_on_exception
(
max_attempts:
max_attempts
,
reload_page:
(
reload
&&
self
),
sleep_interval:
sleep_interval
)
do
yield
end
def
retry_until
(
max_attempts:
3
,
reload:
false
,
sleep_interval:
0
,
raise_on_failure:
true
,
message:
nil
,
&
block
)
Support
::
Retrier
.
retry_until
(
max_attempts:
max_attempts
,
reload_page:
(
reload
&&
self
),
sleep_interval:
sleep_interval
,
raise_on_failure:
raise_on_failure
,
message:
message
,
&
block
)
end
def
retry_on_exception
(
max_attempts:
3
,
reload:
false
,
sleep_interval:
0.5
,
message:
nil
,
&
block
)
Support
::
Retrier
.
retry_on_exception
(
max_attempts:
max_attempts
,
reload_page:
(
reload
&&
self
),
sleep_interval:
sleep_interval
,
message:
message
,
&
block
)
end
def
scroll_to
(
selector
,
text:
nil
)
...
...
qa/qa/page/group/bulk_import.rb
View file @
d4f65056
...
...
@@ -34,7 +34,7 @@ module QA
click_element
(
:target_namespace_selector_dropdown
)
click_element
(
:target_group_dropdown_item
,
group_name:
target_group_name
)
retry_until
do
retry_until
(
message:
"Triggering import"
)
do
click_element
(
:import_group_button
)
# Make sure import started before waiting for completion
has_no_element?
(
:import_status_indicator
,
text:
"Not started"
,
wait:
1
)
...
...
qa/qa/support/repeater.rb
View file @
d4f65056
...
...
@@ -18,7 +18,8 @@ module QA
sleep_interval:
0
,
raise_on_failure:
true
,
retry_on_exception:
false
,
log:
true
log:
true
,
message:
nil
)
attempts
=
0
start
=
Time
.
now
...
...
@@ -63,11 +64,14 @@ module QA
unless
remaining_attempts?
(
attempts
,
max_attempts
)
raise
(
RetriesExceededError
,
"
Retry condition not met
after
#{
max_attempts
}
#{
'attempt'
.
pluralize
(
max_attempts
)
}
"
"
#{
message
||
'Retry'
}
failed
after
#{
max_attempts
}
#{
'attempt'
.
pluralize
(
max_attempts
)
}
"
)
end
raise
WaitExceededError
,
"Wait condition not met after
#{
max_duration
}
#{
'second'
.
pluralize
(
max_duration
)
}
"
raise
(
WaitExceededError
,
"
#{
message
||
'Wait'
}
failed after
#{
max_duration
}
#{
'second'
.
pluralize
(
max_duration
)
}
"
)
end
log_completion
(
log
,
attempts
)
...
...
qa/qa/support/retrier.rb
View file @
d4f65056
...
...
@@ -7,14 +7,15 @@ module QA
module_function
def
retry_on_exception
(
max_attempts:
3
,
reload_page:
nil
,
sleep_interval:
0.5
,
log:
true
)
def
retry_on_exception
(
max_attempts:
3
,
reload_page:
nil
,
sleep_interval:
0.5
,
log:
true
,
message:
nil
)
result
=
nil
repeat_until
(
max_attempts:
max_attempts
,
reload_page:
reload_page
,
sleep_interval:
sleep_interval
,
retry_on_exception:
true
,
log:
log
log:
log
,
message:
message
)
do
result
=
yield
...
...
@@ -33,7 +34,8 @@ module QA
sleep_interval:
0
,
raise_on_failure:
true
,
retry_on_exception:
false
,
log:
true
log:
true
,
message:
nil
)
# For backwards-compatibility
max_attempts
=
3
if
max_attempts
.
nil?
&&
max_duration
.
nil?
...
...
@@ -46,7 +48,8 @@ module QA
sleep_interval:
sleep_interval
,
raise_on_failure:
raise_on_failure
,
retry_on_exception:
retry_on_exception
,
log:
log
log:
log
,
message:
message
)
do
result
=
yield
end
...
...
qa/spec/support/repeater_spec.rb
View file @
d4f65056
...
...
@@ -23,7 +23,7 @@ RSpec.describe QA::Support::Repeater do
context
'when retry_on_exception is not provided (default: false)'
do
context
'when max_duration is provided'
do
context
'when max duration is reached'
do
it
'raises an exception'
do
it
'raises an exception
with default message
'
do
expect
do
Timecop
.
freeze
do
subject
.
repeat_until
(
max_duration:
1
)
do
...
...
@@ -31,7 +31,20 @@ RSpec.describe QA::Support::Repeater do
false
end
end
end
.
to
raise_error
(
QA
::
Support
::
Repeater
::
WaitExceededError
,
"Wait condition not met after 1 second"
)
end
.
to
raise_error
(
QA
::
Support
::
Repeater
::
WaitExceededError
,
"Wait failed after 1 second"
)
end
it
'raises an exception with custom message'
do
message
=
'Some custom action'
expect
do
Timecop
.
freeze
do
subject
.
repeat_until
(
max_duration:
1
,
message:
message
)
do
Timecop
.
travel
(
2
)
false
end
end
end
.
to
raise_error
(
QA
::
Support
::
Repeater
::
WaitExceededError
,
"
#{
message
}
failed after 1 second"
)
end
it
'ignores attempts'
do
...
...
@@ -70,14 +83,26 @@ RSpec.describe QA::Support::Repeater do
context
'when max_attempts is provided'
do
context
'when max_attempts is reached'
do
it
'raises an exception'
do
it
'raises an exception
with default message
'
do
expect
do
Timecop
.
freeze
do
subject
.
repeat_until
(
max_attempts:
1
)
do
false
end
end
end
.
to
raise_error
(
QA
::
Support
::
Repeater
::
RetriesExceededError
,
"Retry condition not met after 1 attempt"
)
end
.
to
raise_error
(
QA
::
Support
::
Repeater
::
RetriesExceededError
,
"Retry failed after 1 attempt"
)
end
it
'raises an exception with custom message'
do
message
=
'Some custom action'
expect
do
Timecop
.
freeze
do
subject
.
repeat_until
(
max_attempts:
1
,
message:
message
)
do
false
end
end
end
.
to
raise_error
(
QA
::
Support
::
Repeater
::
RetriesExceededError
,
"
#{
message
}
failed after 1 attempt"
)
end
it
'ignores duration'
do
...
...
@@ -126,7 +151,7 @@ RSpec.describe QA::Support::Repeater do
false
end
end
end
.
to
raise_error
(
QA
::
Support
::
Repeater
::
RetriesExceededError
,
"Retry
condition not met
after 1 attempt"
)
end
.
to
raise_error
(
QA
::
Support
::
Repeater
::
RetriesExceededError
,
"Retry
failed
after 1 attempt"
)
end
end
...
...
@@ -141,7 +166,7 @@ RSpec.describe QA::Support::Repeater do
false
end
end
end
.
to
raise_error
(
QA
::
Support
::
Repeater
::
WaitExceededError
,
"Wait
condition not met
after 1 second"
)
end
.
to
raise_error
(
QA
::
Support
::
Repeater
::
WaitExceededError
,
"Wait
failed
after 1 second"
)
end
end
end
...
...
@@ -210,7 +235,7 @@ RSpec.describe QA::Support::Repeater do
false
end
end
end
.
to
raise_error
(
QA
::
Support
::
Repeater
::
RetriesExceededError
,
"Retry
condition not met
after 1 attempt"
)
end
.
to
raise_error
(
QA
::
Support
::
Repeater
::
RetriesExceededError
,
"Retry
failed
after 1 attempt"
)
end
end
...
...
@@ -225,7 +250,7 @@ RSpec.describe QA::Support::Repeater do
false
end
end
end
.
to
raise_error
(
QA
::
Support
::
Repeater
::
WaitExceededError
,
"Wait
condition not met
after 1 second"
)
end
.
to
raise_error
(
QA
::
Support
::
Repeater
::
WaitExceededError
,
"Wait
failed
after 1 second"
)
end
end
end
...
...
qa/spec/support/retrier_spec.rb
View file @
d4f65056
...
...
@@ -33,6 +33,12 @@ RSpec.describe QA::Support::Retrier do
subject
.
retry_until
(
log:
false
)
end
it
'sets custom error message'
do
expect
(
subject
).
to
receive
(
:repeat_until
).
with
(
hash_including
(
message:
'Custom message'
))
subject
.
retry_until
(
message:
'Custom message'
)
end
end
describe
'.retry_on_exception'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment