Sha256: 007121b886f2506ecdf2b12f8a5572af9277e62ba9e957c9ab87622b734d3264

Contents?: true

Size: 1.62 KB

Versions: 5

Compression:

Stored size: 1.62 KB

Contents

require 'rhoconnect'
require File.join(File.dirname(__FILE__),'..','spec_helper')
require File.join(File.dirname(__FILE__),'..','..','lib','rhoconnect','server.rb')

STATS_RECORD_RESOLUTION = 2 unless defined? STATS_RECORD_RESOLUTION
STATS_RECORD_SIZE = 8 unless defined? STATS_RECORD_SIZE

include Rhoconnect

describe "Middleware" do

  before(:each) do
    @now = 10.0
    Store.flush_all
    app = double('app')
    allow(app).to receive(:call)
    Rhoconnect.stats = true
    Rhoconnect::Server.enable :stats
    @middleware_new_routes = Rhoconnect::Middleware::Stats.new(app)
    allow(Store).to receive(:lock).and_yield
  end

  after(:each) do
    Rhoconnect.stats = false
    Rhoconnect::Server.disable :stats
  end

  it "should compute http average" do
    @incr = 0
    allow(Time).to receive(:now) do
      if @incr > 0
        @now += 0.3
        @incr -= 1
      end
      @now
    end
    env = {
      'rack.request.query_hash' => {
        'source_name' => 'SampleAdapter'
      },
      'REQUEST_METHOD' => 'GET',
      'PATH_INFO' => '/api/application/query'
    }
    10.times { @incr = 3; @middleware_new_routes.call(env) }
    metric = 'http:GET:/api/application/query:SampleAdapter'
    expect(Rhoconnect::Stats::Record.key(metric)).to eq("stat:#{metric}")

    # The conversion algorithm (float to string) currently checks two precisions.
    # it tries 16 digits and if that's not enough it then uses 17.
    expect(Rhoconnect::Stats::Record.range(metric, 0, -1)).to eq([
      "2.0,0.6000000000000014:12",
      "2.0,0.6000000000000014:14",
      "2.0,0.6000000000000014:16",
      "2.0,0.6000000000000014:18"
    ])
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rhoconnect-7.6.0 spec/server/stats_spec.rb
rhoconnect-7.5.1 spec/server/stats_spec.rb
rhoconnect-7.4.1 spec/server/stats_spec.rb
rhoconnect-7.1.17 spec/server/stats_spec.rb
rhoconnect-6.2.0 spec/server/stats_spec.rb