require_relative "./helpers" describe BigBench::Benchmark do it "should add an empty benchmark with a name" do BigBench.benchmark "a test page" => "http://localhost:3001" BigBench.benchmark "a second test page" => "http://localhost:3001" BigBench.benchmarks.size.should == 0 end it "should add a benchmark block with a get fragment" do BigBench.benchmark "a test page" => "http://localhost:3001" do get "/" end BigBench.benchmarks.size.should == 1 BigBench.benchmarks.first.fragments.size.should == 1 BigBench.benchmarks.first.users.should == 1 BigBench.benchmarks.first.fragments.first.uri.to_s.should == "http://localhost:3001/" end it "should add a benchmark with custom users" do BigBench.benchmark "a test page" => "http://localhost:3001", :users => 20 do get "/" end BigBench.benchmarks.size.should == 1 BigBench.benchmarks.first.fragments.size.should == 1 BigBench.benchmarks.first.users.should == 20 end it "should return the longest duration of all benchmarks" do BigBench.benchmark "a test page" => "http://localhost:3001", :duration => 1.second do get "/" end BigBench.benchmark "a test page" => "http://localhost:3001", :duration => 3.minutes do get "/" end BigBench.benchmark "a test page" => "http://localhost:3001", :duration => 20.seconds do get "/" end BigBench.duration.should == 3.minutes end context "should run an entire benchmark" do it "make 3 GETs" do benchmark = BigBench.benchmark "a test page" => "http://localhost:3001", :users => 5 do get "/" get "/index" get "/blog" end EventMachine.run{ Thread.new{ sleep(2); EventMachine.stop } benchmark.run! } benchmark.tracker.trackings.size.should > 100 benchmark.runs.should == 1 EventMachine.run{ Thread.new{ sleep(2); EventMachine.stop } benchmark.run! } benchmark.tracker.trackings.size.should > 100 benchmark.runs.should == 2 end end end