Tests for new throttle policy
parent
fa6c6196bb
commit
33ebb628f5
|
@ -3,6 +3,9 @@ class ThrottlePolicy
|
|||
TTL = { min: 60,
|
||||
hour: 60 * 60,
|
||||
day: 60 * 60 * 24 }
|
||||
ROUNDING_HELPERS = { min: :beginning_of_minute,
|
||||
hour: :beginning_of_hour,
|
||||
day: :beginning_of_day }
|
||||
|
||||
TIME_UNITS = TTL.keys
|
||||
VIOLATION_TPL = "more than %{limit} / %{period}"
|
||||
|
@ -56,10 +59,6 @@ class ThrottlePolicy
|
|||
(redis.get(cache_key(id, period)) || "0").to_i
|
||||
end
|
||||
|
||||
ROUNDING_HELPERS = { min: :beginning_of_minute,
|
||||
hour: :beginning_of_hour,
|
||||
day: :beginning_of_day }
|
||||
|
||||
def next_window(period, now = Time.now)
|
||||
helper = ROUNDING_HELPERS.fetch(period)
|
||||
offset = TTL.fetch(period).seconds
|
||||
|
|
|
@ -74,6 +74,14 @@ describe LogService do
|
|||
end.to raise_error(Mutations::ValidationException)
|
||||
end
|
||||
|
||||
it "throttles a device that sends too many logs" do
|
||||
violation = ThrottlePolicy::Violation.new(Time.now, "whatever")
|
||||
return_error = receive(:violation_for).with(any_args).and_return(violation)
|
||||
expect(LogService::THROTTLE_POLICY).to(return_error)
|
||||
j = normal_hash[].to_json
|
||||
LogService.new.process(fake_delivery_info, j)
|
||||
end
|
||||
|
||||
it "does not save `fun`, `debug` or `nil` logs" do
|
||||
["fun", "debug", nil].map do |type|
|
||||
Log.destroy_all
|
||||
|
|
Loading…
Reference in New Issue