Skip to content

Commit

Permalink
specs pass on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Apr 24, 2010
1 parent 422242c commit 2cb181a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions spec/tracing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
# XXX must require upfront before tracers are installed
require 'socket'
require 'open-uri'
require 'mysql' rescue nil
require 'memcached' rescue nil
begin; require 'mysql'; rescue LoadError; end
begin; require 'memcached'; rescue LoadError; end

describe 'Memprof tracers' do
@tempfile = Tempfile.new('tracing_spec')
Expand Down Expand Up @@ -38,7 +38,9 @@ def filedata
select(nil, nil, nil, 0.15)
end

filedata.should =~ /"select":\{"calls":1,"time":0\.15/
filedata.should =~ /"select":\{"calls":1,"time":0\.1[567]/
time = filedata[/"select":\{"calls":\d+,"time":([\d.]+)/, 1].to_f
time.should.be.close(0.15, 0.1)
end

should 'trace objects created for block' do
Expand Down Expand Up @@ -68,14 +70,16 @@ def filedata

if defined? Mysql
begin
conn = Mysql.connect
conn = Mysql.connect('localhost', 'root')

should 'trace mysql calls for block' do
Memprof.trace(filename) do
5.times{ conn.query("select sleep(0.05)") }
end

filedata.should =~ /"mysql":\{"queries":5,"time":0.2[567]/
filedata.should =~ /"mysql":\{"queries":5,"time":([\d.]+)/
time = filedata[/"mysql":\{"queries":5,"time":([\d.]+)/, 1].to_f
time.should.be.close(0.25, 0.1)
end
rescue Mysql::Error => e
raise unless e.message =~ /connect/
Expand Down Expand Up @@ -128,4 +132,4 @@ def filedata

filedata.should =~ /"HEADER":"value"/
end
end
end

0 comments on commit 2cb181a

Please sign in to comment.