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
12356670
Commit
12356670
authored
9 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
code cleanup
parent
39caff96
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
+22
-22
22 additions, 22 deletions
test/metabase/api/common/throttle_test.clj
with
22 additions
and
22 deletions
test/metabase/api/common/throttle_test.clj
+
22
−
22
View file @
12356670
...
...
@@ -41,76 +41,76 @@
;;; # tests for check
(
defn-
login
(
defn-
attempt
([
n
]
(
login
n
(
gensym
)))
(
attempt
n
(
gensym
)))
([
n
k
]
(
let
[
login
-once
(
fn
[]
(
let
[
attempt
-once
(
fn
[]
(
try
(
throttle/check
test-throttler
k
)
:success
(
catch
Throwable
e
(
:test
(
:errors
(
ex-data
e
))))))]
(
vec
(
repeatedly
n
login
-once
)))))
(
vec
(
repeatedly
n
attempt
-once
)))))
;; a couple of quick "
login
s" shouldn't trigger the throttler
;; a couple of quick "
attempt
s" shouldn't trigger the throttler
(
expect
[
:success
:success
]
(
login
2
))
(
attempt
2
))
;; nor should 3
(
expect
[
:success
:success
:success
]
(
login
3
))
(
attempt
3
))
;; 4 in quick succession should trigger it
(
expect
[
:success
:success
:success
"Too many attempts! You must wait 0 seconds before trying again."
]
; rounded down
(
login
4
))
(
attempt
4
))
;; Check that throttling correctly lets you try again after certain delay
(
expect
[[
:success
:success
:success
"Too many attempts! You must wait 0 seconds before trying again."
]
[
:success
]]
[(
login
4
:a
)
[(
attempt
4
:a
)
(
do
(
Thread/sleep
2
)
(
login
1
:a
))])
(
attempt
1
:a
))])
;; Next attempt should be throttled, however
(
expect
[
:success
"Too many attempts! You must wait 0 seconds before trying again."
]
(
do
(
login
4
:b
)
(
attempt
4
:b
)
(
Thread/sleep
2
)
(
login
2
:b
)))
(
attempt
2
:b
)))
;; Sleeping 2 ms after that shouldn't work due to exponential growth
(
expect
[
"Too many attempts! You must wait 0 seconds before trying again."
]
(
do
(
login
4
:c
)
(
attempt
4
:c
)
(
Thread/sleep
2
)
(
login
2
:c
)
(
attempt
2
:c
)
(
Thread/sleep
2
)
(
login
1
:c
)))
(
attempt
1
:c
)))
;; Sleeping 8 ms however should work
(
expect
[
:success
]
(
do
(
login
4
:d
)
(
attempt
4
:d
)
(
Thread/sleep
2
)
(
login
2
:d
)
(
attempt
2
:d
)
(
Thread/sleep
8
)
(
login
1
:d
)))
(
attempt
1
:d
)))
;; Check that the interal list for the throttler doesn't keep growing after throttling starts
(
expect
[
0
4
]
[(
do
(
reset!
(
:attempts
test-throttler
)
'
())
; reset it to 0
(
count
@
(
:attempts
test-throttler
)))
(
do
(
login
1000
)
(
do
(
attempt
1000
)
(
count
@
(
:attempts
test-throttler
)))])
;; Check that
login
attempts clear after the TTL
;; Check that attempts clear after the TTL
(
expect
[
0
3
1
]
[(
do
(
reset!
(
:attempts
test-throttler
)
'
())
; reset it to 0
(
count
@
(
:attempts
test-throttler
)))
(
do
(
login
3
)
(
do
(
attempt
3
)
(
count
@
(
:attempts
test-throttler
)))
(
do
(
Thread/sleep
10
)
(
login
1
)
(
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