Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
51a182d2
Commit
51a182d2
authored
9 years ago
by
Cam Saül
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' into my-sql-driver
parents
9fe0376a
bac140ad
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/metabase/api/common/throttle_test.clj
+21
-21
21 additions, 21 deletions
test/metabase/api/common/throttle_test.clj
with
21 additions
and
21 deletions
test/metabase/api/common/throttle_test.clj
+
21
−
21
View file @
51a182d2
...
...
@@ -3,38 +3,38 @@
[
metabase.api.common.throttle
:as
throttle
]
[
metabase.test.util
:refer
[
resolve-private-fns
]]))
(
def
^
:private
test-throttler
(
throttle/make-throttler
:test,
:initial-delay-ms
2
,
:attempts-threshold
3
,
:delay-exponent
2
,
:attempt-ttl-ms
10
))
(
def
^
:private
test-throttler
(
throttle/make-throttler
:test,
:initial-delay-ms
5
,
:attempts-threshold
3
,
:delay-exponent
2
,
:attempt-ttl-ms
25
))
;;; # tests for calculate-delay
(
resolve-private-fns
metabase.api.common.throttle
calculate-delay
)
;; no delay should be calculated for the 3rd attempt
(
expect
nil
(
do
(
reset!
(
:attempts
test-throttler
)
'
([
:x
100
]
,
[
:x
99
]))
(
do
(
reset!
(
:attempts
test-throttler
)
'
([
:x
100
]
,
[
:x
99
]))
(
calculate-delay
test-throttler
:x
101
)))
;;
1
ms delay on 4th attempt 1ms after the last
(
expect
1
;;
4
ms delay on 4th attempt 1ms after the last
(
expect
4
(
do
(
reset!
(
:attempts
test-throttler
)
'
([
:x
100
]
,
[
:x
99
]
,
[
:x
98
]))
(
calculate-delay
test-throttler
:x
101
)))
;;
2
ms after last attempt, they should be allowed to try again
;;
5
ms after last attempt, they should be allowed to try again
(
expect
nil
(
do
(
reset!
(
:attempts
test-throttler
)
'
([
:x
100
]
,
[
:x
99
]
,
[
:x
98
]))
(
calculate-delay
test-throttler
:x
10
2
)))
(
calculate-delay
test-throttler
:x
10
5
)))
;; However if this was instead the 5th attempt delay should grow exponentially (
2
* 2^2 =
8
), - 2
ms =
6
(
expect
6
;; However if this was instead the 5th attempt delay should grow exponentially (
5
* 2^2 =
20
), - 2ms =
18ms
(
expect
18
(
do
(
reset!
(
:attempts
test-throttler
)
'
([
:x
100
]
,
[
:x
99
]
,
[
:x
98
]
,
[
:x
97
]))
(
calculate-delay
test-throttler
:x
102
)))
;; Should be allowed after
6
more secs
;; Should be allowed after
18
more secs
(
expect
nil
(
do
(
reset!
(
:attempts
test-throttler
)
'
([
:x
100
]
,
[
:x
99
]
,
[
:x
98
]
,
[
:x
97
]))
(
calculate-delay
test-throttler
:x
10
8
)))
(
calculate-delay
test-throttler
:x
1
2
0
)))
;; Check that delay keeps growing according to delay-exponent (
2
* 3^2 =
2
* 9 =
18
)
(
expect
18
;; Check that delay keeps growing according to delay-exponent (
5
* 3^2 =
5
* 9 =
45
)
(
expect
45
(
do
(
reset!
(
:attempts
test-throttler
)
'
([
:x
108
]
,
[
:x
100
]
,
[
:x
99
]
,
[
:x
98
]
,
[
:x
97
]))
(
calculate-delay
test-throttler
:x
108
)))
...
...
@@ -70,32 +70,32 @@
[
:success
]]
[(
attempt
4
:a
)
(
do
(
Thread/sleep
2
)
(
Thread/sleep
5
)
(
attempt
1
:a
))])
;; Next attempt should be throttled, however
(
expect
[
:success
"Too many attempts! You must wait 0 seconds before trying again."
]
(
do
(
attempt
4
:b
)
(
Thread/sleep
2
)
(
Thread/sleep
5
)
(
attempt
2
:b
)))
;; Sleeping
2
ms after that shouldn't work due to exponential growth
;; Sleeping
5
ms after that shouldn't work due to exponential growth
(
expect
[
"Too many attempts! You must wait 0 seconds before trying again."
]
(
do
(
attempt
4
:c
)
(
Thread/sleep
2
)
(
Thread/sleep
5
)
(
attempt
2
:c
)
(
Thread/sleep
2
)
(
Thread/sleep
5
)
(
attempt
1
:c
)))
;; Sleeping
8
ms however should work
;; Sleeping
20
ms however should work
(
expect
[
:success
]
(
do
(
attempt
4
:d
)
(
Thread/sleep
2
)
(
Thread/sleep
5
)
(
attempt
2
:d
)
(
Thread/sleep
8
)
(
Thread/sleep
20
)
(
attempt
1
:d
)))
;; Check that the interal list for the throttler doesn't keep growing after throttling starts
...
...
@@ -111,6 +111,6 @@
(
count
@
(
:attempts
test-throttler
)))
(
do
(
attempt
3
)
(
count
@
(
:attempts
test-throttler
)))
(
do
(
Thread/sleep
10
)
(
do
(
Thread/sleep
25
)
(
attempt
1
)
(
count
@
(
:attempts
test-throttler
)))])
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment