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