Skip to content

Commit

Permalink
Ref wvanbergen#155 - Millisecond measuring units
Browse files Browse the repository at this point in the history
- Altered the labeling of durations when <1 second
- Altered related specs that cover output to email
- Cleaned up a few lines that had trailing whitespace
  • Loading branch information
jefflunt committed Mar 30, 2014
1 parent f86c205 commit 5993793
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
5 changes: 3 additions & 2 deletions lib/request_log_analyzer/tracker/duration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Duration < NumericValue
def prepare
options[:value] = options[:duration] if options[:duration]
super

@number_of_buckets = options[:number_of_buckets] || 1000
@min_bucket_value = options[:min_bucket_value] ? options[:min_bucket_value].to_f : 0.0001
@max_bucket_value = options[:max_bucket_value] ? options[:max_bucket_value].to_f : 1000
Expand All @@ -38,7 +38,8 @@ def prepare
def display_value(time)
case time
when nil then '-'
when 0...60 then "%0.02fs" % time
when 0...1 then "%0.02fms" % (time*1000)
when 1...60 then "%0.02fs" % time
when 60...3600 then "%dm%02ds" % [time / 60, (time % 60).round]
else "%dh%02dm%02ds" % [time / 3600, (time % 3600) / 60, (time % 60).round]
end
Expand Down
26 changes: 13 additions & 13 deletions spec/integration/mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
:format => RequestLogAnalyzer::FileFormat::Rails,
:no_progress => true
).run!

Process.wait # Wait for mailer to complete

find_string_in_file("From: <[email protected]>", @log_file).should_not be_nil
find_string_in_file("To: <root@localhost>", @log_file).should_not be_nil
find_string_in_file("From: Request-log-analyzer reporter <[email protected]>", @log_file).should_not be_nil
find_string_in_file("Subject: Request log analyzer report - generated on", @log_file).should_not be_nil
find_string_in_file("Request summary", @log_file).should_not be_nil
find_string_in_file("PeopleControll | 1 | 0.04s | 0.04s | 0.00s | 0.04s | 0.04s | 0.04s-0.04s", @log_file).should_not be_nil
find_string_in_file("People | 1 | 40.30ms | 40.30ms | 0.00ms | 40.30ms | 40.30ms | 40.18ms-41.50ms", @log_file).should_not be_nil
end

it "should allow a custom mail subject" do
RequestLogAnalyzer::Controller.build(
:mail => 'root@localhost',
Expand All @@ -46,13 +46,13 @@
:format => RequestLogAnalyzer::FileFormat::Rails,
:no_progress => true
).run!

Process.wait # Wait for mailer to complete

find_string_in_file("Subject: TESTSUBJECT", @log_file).should_not be_nil
find_string_in_file("Subject: TESTSUBJECT", @log_file).should_not be_nil
end

it "should send html mail" do
it "should send html mail" do
RequestLogAnalyzer::Controller.build(
:output => 'HTML',
:mail => 'root@localhost',
Expand All @@ -61,14 +61,14 @@
:format => RequestLogAnalyzer::FileFormat::Rails,
:no_progress => true
).run!

Process.wait # Wait for mailer to complete

find_string_in_file("From: <[email protected]>", @log_file).should_not be_nil
find_string_in_file("To: <root@localhost>", @log_file).should_not be_nil
find_string_in_file("From: Request-log-analyzer reporter <[email protected]>", @log_file).should_not be_nil
find_string_in_file('<h1>Request-log-analyzer summary report</h1>', @log_file).should_not be_nil
find_string_in_file('<td class="alt">0.29s-0.30s</td></tr><tr><td>DashboardController#index.html [GET]</td>', @log_file).should_not be_nil
find_string_in_file('<td class="alt">287.08ms-296.48ms</td></tr><tr><td>DashboardController#index.html [GET]</td>', @log_file).should_not be_nil
end
end

Expand All @@ -80,7 +80,7 @@
#
# Included in RLA because original mailtrap puts anoying stuff when called
# through ruby.
#
#
# Mailtrap creates a TCP server that listens on a specified port for SMTP
# clients. Accepts the connection and talks just enough of the SMTP protocol
# for them to deliver a message which it writes to disk.
Expand All @@ -96,7 +96,7 @@ def initialize( host, port, once, msgfile )
@port = port
@once = once
@msgfile = msgfile

File.open( @msgfile, "a" ) do |file|
file.puts "\n* Mailtrap started at #{@host}:#{port}\n"
end
Expand All @@ -113,7 +113,7 @@ class << session
def get_line
line = gets
line.chomp! unless line.nil?
line
line
end
end

Expand All @@ -123,7 +123,7 @@ def get_line
end

break if @once
end
end
end

# Write a plain text dump of the incoming email to a text
Expand Down Expand Up @@ -198,4 +198,4 @@ def serve( connection )

else
p 'Skipping mailer integration specs, because of missing Process.fork()'
end
end

0 comments on commit 5993793

Please sign in to comment.