Sha256: bcc71696ca555e69526fc7496bb4cedf27738179c4e5a70593eec71908686076

Contents?: true

Size: 1.28 KB

Versions: 1

Compression:

Stored size: 1.28 KB

Contents

require "spec_helper"
require "coach/request_benchmark"

describe Coach::RequestBenchmark do
  subject(:event) { described_class.new("ENDPOINT") }

  let(:base_time) { Time.now }

  let(:start)     { base_time + 0 }
  let(:a_start)   { base_time + 1 }
  let(:b_start)   { base_time + 2 }
  let(:b_finish)  { base_time + 3 }
  let(:a_finish)  { base_time + 4 }
  let(:finish)    { base_time + 5 }

  before do
    event.notify("B", b_start, b_finish)
    event.notify("A", a_start, a_finish)
    event.complete(start, finish)
  end

  describe "#stats" do
    subject(:stats) { event.stats }

    it "computes overall duration" do
      expect(stats[:duration]).to eq(5000)
    end

    it "captures the endpoint_name" do
      expect(stats[:endpoint_name]).to eq("ENDPOINT")
    end

    it "captures the started_at time" do
      expect(stats[:started_at]).to eq(base_time)
    end

    it "computes duration of middleware with no children" do
      expect(stats[:chain]).to include(name: "B", duration: 1000)
    end

    it "adjusts duration of middleware for their children" do
      expect(stats[:chain]).to include(name: "A", duration: 2000)
    end

    it "correctly orders chain" do
      chain_names = stats[:chain].map { |item| item[:name] }
      expect(chain_names).to eq %w[A B]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
coach-1.0.0 spec/lib/coach/request_benchmark_spec.rb