|
| 1 | +require "spec_helper" |
| 2 | +require "promenade/pitchfork/stats" |
| 3 | + |
| 4 | +RSpec.describe Promenade::Pitchfork::Stats do |
| 5 | + let(:pitchfork_info) { class_double("Pitchfork::Info") } |
| 6 | + let(:raindrops_stats) { instance_double("Promenade::Raindrops::Stats", active_workers: 6, queued_requests: 2) } |
| 7 | + |
| 8 | + before do |
| 9 | + stub_const("Pitchfork::Info", pitchfork_info) |
| 10 | + allow(pitchfork_info).to receive(:workers_count).and_return(10) |
| 11 | + allow(pitchfork_info).to receive(:live_workers_count).and_return(8) |
| 12 | + |
| 13 | + allow(Promenade::Raindrops::Stats).to receive(:new).and_return(raindrops_stats) |
| 14 | + end |
| 15 | + |
| 16 | + describe "#instrument" do |
| 17 | + let(:metric) { instance_double("Promenade::Metric") } |
| 18 | + |
| 19 | + before do |
| 20 | + allow(Promenade).to receive(:metric).and_return(metric) |
| 21 | + allow(metric).to receive(:set) |
| 22 | + end |
| 23 | + |
| 24 | + it "sets the metrics correctly" do |
| 25 | + stats = Promenade::Pitchfork::Stats.new |
| 26 | + |
| 27 | + expect(Promenade).to receive(:metric).with(:pitchfork_workers_count).and_return(metric) |
| 28 | + expect(Promenade).to receive(:metric).with(:pitchfork_live_workers_count).and_return(metric) |
| 29 | + expect(Promenade).to receive(:metric).with(:pitchfork_capacity).and_return(metric) |
| 30 | + expect(Promenade).to receive(:metric).with(:pitchfork_busy_percent).and_return(metric) |
| 31 | + |
| 32 | + expect(metric).to receive(:set).with({}, 10) |
| 33 | + expect(metric).to receive(:set).with({}, 8) |
| 34 | + expect(metric).to receive(:set).with({}, 2) |
| 35 | + expect(metric).to receive(:set).with({}, 75.0) |
| 36 | + |
| 37 | + stats.instrument |
| 38 | + end |
| 39 | + end |
| 40 | + |
| 41 | + describe ".instrument" do |
| 42 | + it "calls the instance method instrument" do |
| 43 | + stats_instance = instance_double("Promenade::Pitchfork::Stats") |
| 44 | + allow(Promenade::Pitchfork::Stats).to receive(:new).and_return(stats_instance) |
| 45 | + allow(stats_instance).to receive(:instrument) |
| 46 | + |
| 47 | + Promenade::Pitchfork::Stats.instrument |
| 48 | + |
| 49 | + expect(stats_instance).to have_received(:instrument) |
| 50 | + end |
| 51 | + end |
| 52 | +end |
| 53 | + |
0 commit comments