2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-02-03 23:10:54 -05:00
|
|
|
describe ApplicationRequest do
|
|
|
|
before do
|
2020-05-18 05:22:39 -04:00
|
|
|
ApplicationRequest.enable
|
2022-02-22 11:45:25 -05:00
|
|
|
CachedCounting.reset
|
|
|
|
CachedCounting.enable
|
2015-02-03 23:10:54 -05:00
|
|
|
end
|
|
|
|
|
2017-07-23 22:41:37 -04:00
|
|
|
after do
|
2020-05-18 05:22:39 -04:00
|
|
|
ApplicationRequest.disable
|
2022-02-22 11:45:25 -05:00
|
|
|
CachedCounting.disable
|
2017-07-23 22:41:37 -04:00
|
|
|
end
|
|
|
|
|
2022-02-22 11:45:25 -05:00
|
|
|
def inc(key)
|
|
|
|
ApplicationRequest.increment!(key)
|
2015-02-03 23:10:54 -05:00
|
|
|
end
|
|
|
|
|
2022-02-22 11:45:25 -05:00
|
|
|
it "can log app requests" do
|
|
|
|
freeze_time
|
|
|
|
d1 = Time.now.utc.to_date
|
2017-10-24 22:22:50 -04:00
|
|
|
|
2022-02-22 11:45:25 -05:00
|
|
|
4.times do
|
|
|
|
inc("http_2xx")
|
2017-10-24 22:22:50 -04:00
|
|
|
end
|
2015-02-03 23:10:54 -05:00
|
|
|
|
2022-02-22 11:45:25 -05:00
|
|
|
inc("http_background")
|
2017-10-24 22:19:43 -04:00
|
|
|
|
2022-02-22 11:45:25 -05:00
|
|
|
freeze_time 1.day.from_now
|
|
|
|
d2 = Time.now.utc.to_date
|
2017-10-24 22:19:43 -04:00
|
|
|
|
2022-02-22 11:45:25 -05:00
|
|
|
inc("page_view_crawler")
|
|
|
|
inc("http_2xx")
|
2015-02-05 22:39:04 -05:00
|
|
|
|
2022-02-22 11:45:25 -05:00
|
|
|
CachedCounting.flush
|
2015-02-03 23:10:54 -05:00
|
|
|
|
2022-02-22 11:45:25 -05:00
|
|
|
expect(ApplicationRequest.find_by(date: d1, req_type: "http_2xx").count).to eq(4)
|
|
|
|
expect(ApplicationRequest.find_by(date: d1, req_type: "http_background").count).to eq(1)
|
2015-02-03 23:10:54 -05:00
|
|
|
|
2022-02-22 11:45:25 -05:00
|
|
|
expect(ApplicationRequest.find_by(date: d2, req_type: "page_view_crawler").count).to eq(1)
|
|
|
|
expect(ApplicationRequest.find_by(date: d2, req_type: "http_2xx").count).to eq(1)
|
2015-02-03 23:10:54 -05:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|