Merge remote-tracking branch 'upstream/develop' into fix-track-request
This commit is contained in:
Коммит
1aa2f4f3e0
|
@ -75,9 +75,8 @@ module ApplicationInsights
|
|||
end
|
||||
|
||||
def format_request_duration(duration_seconds)
|
||||
if duration_seconds >= 86_400
|
||||
# just return 1 day when it takes more than 1 day which should not
|
||||
# happen for requests.
|
||||
if duration_seconds >= 86400
|
||||
# just return 1 day when it takes more than 1 day which should not happen for requests.
|
||||
return "%02d.%02d:%02d:%02d.%07d" % [1, 0, 0, 0, 0]
|
||||
end
|
||||
|
||||
|
@ -85,4 +84,4 @@ module ApplicationInsights
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,6 +6,9 @@ require_relative '../../../lib/application_insights/rack/track_request'
|
|||
include ApplicationInsights::Rack
|
||||
|
||||
class TestTrackRequest < Test::Unit::TestCase
|
||||
|
||||
TIME_SPAN_FORMAT = /^(?<day>\d{2})\.(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2}).(?<fraction>\d{7})$/
|
||||
|
||||
def test_call_works_as_expected
|
||||
response_code = rand(200..204)
|
||||
app = Proc.new {|env| sleep(2); [response_code, {"Content-Type" => "text/html"}, ["Hello Rack!"]]}
|
||||
|
@ -107,8 +110,8 @@ class TestTrackRequest < Test::Unit::TestCase
|
|||
track_request = TrackRequest.new app, 'one'
|
||||
duration_seconds = rand(86400) + rand
|
||||
time_span = track_request.send(:format_request_duration, duration_seconds)
|
||||
time_span_format = /^(?<day>\d{2}).(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2}).(?<fraction>\d{7})$/
|
||||
match = time_span_format.match time_span
|
||||
|
||||
match = TIME_SPAN_FORMAT.match time_span
|
||||
assert_not_nil match
|
||||
days = duration_seconds.to_i/86400
|
||||
assert_equal days, match['day'].to_i
|
||||
|
@ -127,8 +130,8 @@ class TestTrackRequest < Test::Unit::TestCase
|
|||
track_request = TrackRequest.new app, 'one'
|
||||
duration_seconds = rand(86400..240000) + rand
|
||||
time_span = track_request.send(:format_request_duration, duration_seconds)
|
||||
time_span_format = /^(?<day>\d{2}).(?<hour>\d{2}):(?<minute>\d{2}):(?<second>\d{2}).(?<fraction>\d{7})$/
|
||||
match = time_span_format.match time_span
|
||||
|
||||
match = TIME_SPAN_FORMAT.match time_span
|
||||
assert_not_nil match
|
||||
assert_equal 1, match['day'].to_i
|
||||
assert_equal 0, match['hour'].to_i
|
||||
|
@ -136,4 +139,4 @@ class TestTrackRequest < Test::Unit::TestCase
|
|||
assert_equal 0, match['second'].to_i
|
||||
assert_equal 0, match['fraction'].to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче