Merge pull request #26 from Microsoft/master

Merge master to develop
This commit is contained in:
Aaron 2017-07-03 04:36:40 -07:00 коммит произвёл GitHub
Родитель 58bfe53227 c78bb54c8b
Коммит c92bf756c7
2 изменённых файлов: 12 добавлений и 10 удалений

Просмотреть файл

@ -75,13 +75,12 @@ 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.
return "%d:%02d:%02d:%02d.%07d" % [1, 0, 0, 0, 0]
if duration_seconds >= 86400
# just return 1 day when it takes more than 1 day which should not happen for requests.
return "%d.%02d:%02d:%02d.%07d" % [1, 0, 0, 0, 0]
end
Time.at(duration_seconds).gmtime.strftime("0:%H:%M:%S.%7N")
Time.at(duration_seconds).gmtime.strftime("0.%H:%M:%S.%7N")
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{1})\.(?<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!"]]}
@ -31,7 +34,7 @@ class TestTrackRequest < Test::Unit::TestCase
assert_equal true, request_data.success
assert_equal http_method, request_data.http_method
assert_equal url, request_data.url
assert_equal true, request_data.duration.start_with?("0:00:00:02")
assert_equal true, request_data.duration.start_with?("0.00:00:02")
assert Time.parse(request_data.start_time) - start_time < 0.01
end
@ -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{1}):(?<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{1}):(?<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