Sha256: ac04ed7250b032fbe1d09e218da4cec1887556e4fe2520800c9dac3303d1981d

Contents?: true

Size: 995 Bytes

Versions: 15

Compression:

Stored size: 995 Bytes

Contents

require 'rhosync'
STATS_RECORD_RESOLUTION = 2 unless defined? STATS_RECORD_RESOLUTION
STATS_RECORD_SIZE = 8 unless defined? STATS_RECORD_SIZE

include Rhosync
include Rhosync::Stats

describe "Middleware" do
  
  before(:each) do
    @now = 10.0
    Store.db.flushdb
    app = mock('app')
    app.stub!(:call)
    @middleware = Middleware.new(app)
    Store.stub!(:lock).and_yield
  end
  
  it "should compute http average" do
    Time.stub!(:now).and_return { @now += 0.3; @now }
    env = {
      'rack.request.query_hash' => {
        'source_name' => 'SampleAdapter'
      },
      'REQUEST_METHOD' => 'GET',
      'PATH_INFO' => '/application'
    }
    10.times { @middleware.call(env) }
    metric = 'http:GET:/application:SampleAdapter'
    Record.key(metric).should == "stat:#{metric}"
    Record.range(metric, 0, -1).should == [
      "2.0,0.600000000000002:12", 
      "2.0,0.600000000000002:14", 
      "2.0,0.600000000000002:16", 
      "2.0,0.600000000000002:18"
    ]
  end  
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
rhosync-2.1.16 spec/stats/middleware_spec.rb
rhosync-2.1.15 spec/stats/middleware_spec.rb
rhosync-2.1.14 spec/stats/middleware_spec.rb
rhosync-2.1.13 spec/stats/middleware_spec.rb
rhosync-2.1.12 spec/stats/middleware_spec.rb
rhosync-2.1.11 spec/stats/middleware_spec.rb
rhosync-2.1.10 spec/stats/middleware_spec.rb
rhosync-2.1.7 spec/stats/middleware_spec.rb
rhosync-2.1.6 spec/stats/middleware_spec.rb
rhosync-2.1.3 spec/stats/middleware_spec.rb
rhosync-2.1.2 spec/stats/middleware_spec.rb
rhosync-2.1.1 spec/stats/middleware_spec.rb
rhosync-2.1.0 spec/stats/middleware_spec.rb
rhosync-2.1.0.beta.2 spec/stats/middleware_spec.rb
rhosync-2.1.0.beta.1 spec/stats/middleware_spec.rb