Sha256: f432b9e8f859b7a595e55aa35e3877cf02294be2947b4d43564c8750fb81d5cd

Contents?: true

Size: 1.25 KB

Versions: 10

Compression:

Stored size: 1.25 KB

Contents

require File.join(File.dirname(__FILE__),'..','spec_helper')
require File.join(File.dirname(__FILE__),'..','..','lib','rhosync','server.rb')
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)
    Rhosync.stats = true
    Rhosync::Server.enable :stats
    @middleware = Middleware.new(app)
    Store.stub!(:lock).and_yield
  end

  after(:each) do
    Rhosync.stats = false
    Rhosync::Server.disable :stats
  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

10 entries across 10 versions & 1 rubygems

Version Path
rhosync-2.1.18.beta2 spec/stats/middleware_spec.rb
rhosync-2.1.18.beta1 spec/stats/middleware_spec.rb
rhosync-2.1.17 spec/stats/middleware_spec.rb
rhosync-2.1.17.beta7 spec/stats/middleware_spec.rb
rhosync-2.1.17.beta6 spec/stats/middleware_spec.rb
rhosync-2.1.17.beta5 spec/stats/middleware_spec.rb
rhosync-2.1.17.beta4 spec/stats/middleware_spec.rb
rhosync-2.1.17.beta3 spec/stats/middleware_spec.rb
rhosync-2.1.17.beta2 spec/stats/middleware_spec.rb
rhosync-2.1.17.beta1 spec/stats/middleware_spec.rb