Test case: LogService throttle
parent
93d0428e7f
commit
39d461296e
|
@ -19,9 +19,9 @@ class ThrottlePolicy
|
|||
def is_throttled(unique_id)
|
||||
rules
|
||||
.map do |rule|
|
||||
is_violation = rule.time_period.usage_count_for(unique_id) > rule.limit
|
||||
is_violation ? Violation.new(rule) : nil
|
||||
end
|
||||
is_violation = rule.time_period.usage_count_for(unique_id) > rule.limit
|
||||
is_violation ? Violation.new(rule) : nil
|
||||
end
|
||||
.compact
|
||||
.max
|
||||
end
|
||||
|
|
|
@ -54,6 +54,20 @@ describe LogService do
|
|||
LogService.new.warn_user(data, time)
|
||||
end
|
||||
|
||||
it "triggers a throttle" do
|
||||
tp = LogService::THROTTLE_POLICY
|
||||
ls = LogService.new
|
||||
data = AmqpLogParser::DeliveryInfo.new
|
||||
data.device_id = FactoryBot.create(:device).id
|
||||
violation = ThrottlePolicy::Violation.new(Object.new)
|
||||
allow(ls).to receive(:deliver)
|
||||
expect(ls).to receive(:warn_user)
|
||||
expect(tp).to receive(:is_throttled)
|
||||
.with(data.device_id)
|
||||
.and_return(violation)
|
||||
ls.maybe_deliver(data)
|
||||
end
|
||||
|
||||
it "handles bad params" do
|
||||
expect do
|
||||
LogService.new.process(fake_delivery_info, {})
|
||||
|
|
Loading…
Reference in New Issue