-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replicate counter identity rules #51
Conversation
… no test failure due to external side effects. 2) Remove automatic test case detection due to test dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
counterKey2 :: CounterKey | ||
counterKey2 = counterKey1 { counterKeyUnit = Hour } | ||
|
||
fromMaybe' :: Maybe a -> a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this different from fromJust
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It prints the stack trace when something goes wrong, so that it's at least clear where the error happened. fromJust
outputs
*** Exception: Maybe.fromJust: Nothing
and no indication whatsoever where things went wrong.
@@ -71,6 +81,78 @@ test_loadRulesRecursively = | |||
(sortOn domainDefinitionId [domain1, domain2]) | |||
(sortOn domainDefinitionId definitions) | |||
|
|||
-- | Test that a rule limit unit change adds a new counter and leaves | |||
-- the old one intact. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have several suggestions regarding this test.
First of all, it does not test the actual logic used by the server. It does the lookup on its own instead of using getLimit
. To make it more faithful, I would propose:
- moving
shouldRateLimitDescriptor
toFencer.AppState
and renaming it - perhaps also renaming
Fencer.AppState
toFencer.Logic
or something - removing the export of
recordHits
and not usingrecordHits
in the test
Then the test would also get moved to Fencer.Logic.Test
since it's not related to the Fencer.Rules
module.
Secondly, here's what this test does:
load definitions1
hit counterKey1
load definitions2
assert (counterKey1 hasn't changed after 'load definitions2')
assert (counterKey2 doesn't exist after 'load definitions2')
This does not match the description of the test ("Test that a rule limit unit change adds a new counter [...]"). Also, there are bad implementations it does not catch – for instance, what if counters are removed during recordHits
and not during loadRules
?
Here's a scenario I would propose instead:
// change the limit to e.g. 4 instead of 400000
load definitions1
status <- hit "generic_key/dream11_order_create"
assert (counterRemainingLimit status == 3)
load definitions2
status <- hit "generic_key/dream11_order_create"
assert (counterRemainingLimit status == 3) // unaffected by the previous 'hit'
load definitions1
status <- hit "generic_key/dream11_order_create"
assert (counterRemainingLimit status == 2) // the old counter has persisted!
tests = testGroup "All tests" | ||
[ types | ||
, rules | ||
-- 'after' is needed to avoid running the 'rules' and 'server' tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the reason why you got rid of tasty-discover
? If yes, perhaps let's instead disable the parallelism by running tests with +RTS -N1 -RTS
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I couldn't set the order of test execution when tasty-discover
was used.
If I am not missing anything, +RTS -N1 -RTS
would mean the program hangs because it would not be able to fork a thread and start a gRPC server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If yes, perhaps let's instead disable the parallelism by running tests with
+RTS -N1 -RTS
.
I don't think it's a good idea as it solves a pretty much already solved problem, but also makes tests slower.
If I am not missing anything,
+RTS -N1 -RTS
would mean the program hangs because it would not be able to fork a thread and start a gRPC server.
Threads are forkable with -threaded
even with a single core.
There should be a comment about this behavior, then.
…On 21. Oct 2019, 18:08 +0300, effectfully ***@***.***>, wrote:
@effectfully commented on this pull request.
In test/Fencer/Rules/Test.hs:
> + TIO.writeFile (tempDir </> dir </> cfgFile) txt
+ loadRulesFromDirectory (#directory tempDir) (#ignoreDotFiles True)
+
+ ruleKey = RuleKey "generic_key"
+ ruleValue = RuleValue "dream11_order_create"
+ domainId = DomainId "merchant_rate_limits"
+
+ counterKey1 = CounterKey
+ { counterKeyDomain = domainId
+ , counterKeyDescriptor = [ (ruleKey, ruleValue) ]
+ , counterKeyUnit = Minute }
+
+ counterKey2 :: CounterKey
+ counterKey2 = counterKey1 { counterKeyUnit = Hour }
+
+ fromMaybe' :: Maybe a -> a
It prints the stack trace when something goes wrong, so that it's at least clear where the error happened. fromJust outputs
*** Exception: Maybe.fromJust: Nothing
and no indication whatsoever where things went wrong.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
This patch closes #13. It introduces a time unit to
CounterKey
to differentiate rules that are the same in everything but the time unit. If the time unit stays the same, but the rate limit changes,fencer
does the same aslyft/ratelimit
.