2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 21:27:38 -05:00
|
|
|
RSpec.describe ApplicationRequest do
|
2015-02-03 22:10:54 -06:00
|
|
|
before do
|
2020-05-18 04:22:39 -05:00
|
|
|
ApplicationRequest.enable
|
2022-02-22 10:45:25 -06:00
|
|
|
CachedCounting.reset
|
|
|
|
CachedCounting.enable
|
2015-02-03 22:10:54 -06:00
|
|
|
end
|
|
|
|
|
2017-07-23 21:41:37 -05:00
|
|
|
after do
|
2020-05-18 04:22:39 -05:00
|
|
|
ApplicationRequest.disable
|
2022-02-22 10:45:25 -06:00
|
|
|
CachedCounting.disable
|
2017-07-23 21:41:37 -05:00
|
|
|
end
|
|
|
|
|
2022-02-22 10:45:25 -06:00
|
|
|
def inc(key)
|
|
|
|
ApplicationRequest.increment!(key)
|
2015-02-03 22:10:54 -06:00
|
|
|
end
|
|
|
|
|
2022-02-22 10:45:25 -06:00
|
|
|
it "can log app requests" do
|
|
|
|
freeze_time
|
|
|
|
d1 = Time.now.utc.to_date
|
2017-10-24 21:22:50 -05:00
|
|
|
|
2023-01-09 05:18:21 -06:00
|
|
|
4.times { inc("http_2xx") }
|
2015-02-03 22:10:54 -06:00
|
|
|
|
2022-02-22 10:45:25 -06:00
|
|
|
inc("http_background")
|
2017-10-24 21:19:43 -05:00
|
|
|
|
2022-02-22 10:45:25 -06:00
|
|
|
freeze_time 1.day.from_now
|
|
|
|
d2 = Time.now.utc.to_date
|
2017-10-24 21:19:43 -05:00
|
|
|
|
2022-02-22 10:45:25 -06:00
|
|
|
inc("page_view_crawler")
|
|
|
|
inc("http_2xx")
|
2015-02-05 21:39:04 -06:00
|
|
|
|
2022-02-22 10:45:25 -06:00
|
|
|
CachedCounting.flush
|
2015-02-03 22:10:54 -06:00
|
|
|
|
2022-02-22 10:45:25 -06: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 22:10:54 -06:00
|
|
|
|
2022-02-22 10:45:25 -06: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 22:10:54 -06:00
|
|
|
end
|
|
|
|
end
|