Sha256: 7d652a72c649d5c6ad6d2fdb7956ecc0c4f5af626ee9ed0b4e67920be129af7e
Contents?: true
Size: 1.71 KB
Versions: 4
Compression:
Stored size: 1.71 KB
Contents
describe WBench::Timings::Latency do subject(:latency) { described_class.new(browser) } let(:browser) { double 'browser' } let(:resource_urls) do JSON.dump([ "http://3.example.com/path", "https://1.example.com/path", "http://2.example.com:3000/path", ]) end before do allow(browser).to receive(:evaluate_script).with('WBench.resourceURLs()') { resource_urls } allow(::Benchmark).to receive(:measure).and_yield.and_return(30, 10, 20) end describe "#result" do shared_examples_for "result" do it "measures latency for every host" do expect(::Benchmark).to receive(:measure).and_yield.and_return(30, 10, 20) expect(::TCPSocket).to receive(:new).with("1.example.com", 443) expect(::TCPSocket).to receive(:new).with("2.example.com", 3000) expect(::TCPSocket).to receive(:new).with("3.example.com", 80) latency.result end it "returns a hash of the measurement results, sorted by hostname" do expect(latency.result).to eq expected_result end end context "when no SocketError" do before do allow(::TCPSocket).to receive(:new) end let(:expected_result) do { "1.example.com:443" => 10000, "2.example.com:3000" => 20000, "3.example.com:80" => 30000, } end it_behaves_like "result" end context "on SocketError" do before do allow(TCPSocket).to receive(:new).and_raise(SocketError.new) end let(:expected_result) do { "1.example.com:443" => nil, "2.example.com:3000" => nil, "3.example.com:80" => nil, } end it_behaves_like "result" end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
wbench-1.1.1 | spec/wbench/latency_spec.rb |
wbench-1.1.0 | spec/wbench/latency_spec.rb |
wbench-1.0.0 | spec/wbench/latency_spec.rb |
wbench-0.4.0 | spec/wbench/latency_spec.rb |