oink 0.9.3 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +30 -0
 - data/README.rdoc +11 -1
 - data/Rakefile +2 -2
 - data/lib/oink/instrumentation/active_record.rb +17 -9
 - data/lib/oink/instrumentation/memory_snapshot.rb +3 -2
 - data/lib/oink/middleware.rb +1 -1
 - data/lib/oink/reports/base.rb +20 -0
 - data/lib/oink/reports/memory_usage_report.rb +3 -1
 - metadata +147 -158
 - data/spec/fakes/fake_application_controller.rb +0 -30
 - data/spec/fakes/psuedo_output.rb +0 -7
 - data/spec/helpers/database.rb +0 -20
 - data/spec/oink/instrumentation/instance_type_counter_spec.rb +0 -47
 - data/spec/oink/instrumentation/memory_snapshot_spec.rb +0 -84
 - data/spec/oink/middleware_configuration_spec.rb +0 -65
 - data/spec/oink/middleware_spec.rb +0 -82
 - data/spec/oink/rails/instance_type_counter_spec.rb +0 -52
 - data/spec/oink/rails/memory_usage_logger_spec.rb +0 -23
 - data/spec/oink/reports/active_record_instantiation_report_spec.rb +0 -193
 - data/spec/oink/reports/memory_usage_report_spec.rb +0 -267
 - data/spec/oink/reports/oinked_request_spec.rb +0 -22
 - data/spec/oink/reports/priority_queue_spec.rb +0 -74
 - data/spec/spec_helper.rb +0 -21
 
| 
         @@ -1,30 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            class FakeApplicationController
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
              def initialize(logger = Logger.new(StringIO.new))
         
     | 
| 
       4 
     | 
    
         
            -
                @logger = logger
         
     | 
| 
       5 
     | 
    
         
            -
              end
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
              class << self
         
     | 
| 
       8 
     | 
    
         
            -
                attr_accessor :around_filters
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                def around_filter method
         
     | 
| 
       11 
     | 
    
         
            -
                  (@around_filters ||= []) << method
         
     | 
| 
       12 
     | 
    
         
            -
                end
         
     | 
| 
       13 
     | 
    
         
            -
              end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
              def index
         
     | 
| 
       16 
     | 
    
         
            -
                run_around_filters
         
     | 
| 
       17 
     | 
    
         
            -
              end
         
     | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
              def logger
         
     | 
| 
       20 
     | 
    
         
            -
                @logger
         
     | 
| 
       21 
     | 
    
         
            -
              end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
              protected
         
     | 
| 
       24 
     | 
    
         
            -
              def run_around_filters
         
     | 
| 
       25 
     | 
    
         
            -
                self.class.around_filters.each { |filter| self.send(filter) { perform_action } }
         
     | 
| 
       26 
     | 
    
         
            -
              end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
              def perform_action
         
     | 
| 
       29 
     | 
    
         
            -
              end
         
     | 
| 
       30 
     | 
    
         
            -
            end
         
     | 
    
        data/spec/fakes/psuedo_output.rb
    DELETED
    
    
    
        data/spec/helpers/database.rb
    DELETED
    
    | 
         @@ -1,20 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require 'active_record'
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            def setup_memory_database
         
     | 
| 
       4 
     | 
    
         
            -
              ActiveRecord::Base.establish_connection(
         
     | 
| 
       5 
     | 
    
         
            -
                :adapter  => 'sqlite3',
         
     | 
| 
       6 
     | 
    
         
            -
                :database => ':memory:'
         
     | 
| 
       7 
     | 
    
         
            -
              )
         
     | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
              ActiveRecord::Schema.define(:version => 1) do
         
     | 
| 
       10 
     | 
    
         
            -
                create_table "pigs", :force => true do |t|
         
     | 
| 
       11 
     | 
    
         
            -
                  t.integer "pen_id"
         
     | 
| 
       12 
     | 
    
         
            -
                  t.string "name"
         
     | 
| 
       13 
     | 
    
         
            -
                  t.boolean "smells"
         
     | 
| 
       14 
     | 
    
         
            -
                end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
                create_table "pens", :force => true do |t|
         
     | 
| 
       17 
     | 
    
         
            -
                  t.string "location"
         
     | 
| 
       18 
     | 
    
         
            -
                end
         
     | 
| 
       19 
     | 
    
         
            -
              end
         
     | 
| 
       20 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,47 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            describe Oink::Instrumentation::ActiveRecord do
         
     | 
| 
       4 
     | 
    
         
            -
              before do
         
     | 
| 
       5 
     | 
    
         
            -
                ActiveRecord::Base.reset_instance_type_count
         
     | 
| 
       6 
     | 
    
         
            -
                Pig.delete_all
         
     | 
| 
       7 
     | 
    
         
            -
                Pen.delete_all
         
     | 
| 
       8 
     | 
    
         
            -
              end
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
              describe "hash" do
         
     | 
| 
       11 
     | 
    
         
            -
                it "should not count objects not instantiated" do
         
     | 
| 
       12 
     | 
    
         
            -
                  ActiveRecord::Base.instantiated_hash["Pig"].should == nil
         
     | 
| 
       13 
     | 
    
         
            -
                end
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                it "should include the objects instantiated" do
         
     | 
| 
       16 
     | 
    
         
            -
                  Pig.create(:name => "Babe")
         
     | 
| 
       17 
     | 
    
         
            -
                  Pig.first
         
     | 
| 
       18 
     | 
    
         
            -
                  ActiveRecord::Base.instantiated_hash["Pig"].should == 2
         
     | 
| 
       19 
     | 
    
         
            -
                end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                it "should count instantiations for multiple classes" do
         
     | 
| 
       22 
     | 
    
         
            -
                  Pig.create(:name => "Babe")
         
     | 
| 
       23 
     | 
    
         
            -
                  Pen.create(:location => "Backyard")
         
     | 
| 
       24 
     | 
    
         
            -
                  Pig.first
         
     | 
| 
       25 
     | 
    
         
            -
                  ActiveRecord::Base.instantiated_hash["Pen"].should == 1
         
     | 
| 
       26 
     | 
    
         
            -
                end
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                it "should report the total number of objects instantiated" do
         
     | 
| 
       29 
     | 
    
         
            -
                  Pig.create(:name => "Babe")
         
     | 
| 
       30 
     | 
    
         
            -
                  Pen.create(:location => "Backyard")
         
     | 
| 
       31 
     | 
    
         
            -
                  Pig.first
         
     | 
| 
       32 
     | 
    
         
            -
                  ActiveRecord::Base.total_objects_instantiated.should == 3
         
     | 
| 
       33 
     | 
    
         
            -
                end
         
     | 
| 
       34 
     | 
    
         
            -
              end
         
     | 
| 
       35 
     | 
    
         
            -
             
     | 
| 
       36 
     | 
    
         
            -
              describe "reset" do
         
     | 
| 
       37 
     | 
    
         
            -
                it "should reset the total count" do
         
     | 
| 
       38 
     | 
    
         
            -
                  Pig.create(:name => "Babe")
         
     | 
| 
       39 
     | 
    
         
            -
                  ActiveRecord::Base.instantiated_hash["Pig"].should == 1
         
     | 
| 
       40 
     | 
    
         
            -
                  ActiveRecord::Base.reset_instance_type_count
         
     | 
| 
       41 
     | 
    
         
            -
                  ActiveRecord::Base.total_objects_instantiated.should == 0
         
     | 
| 
       42 
     | 
    
         
            -
                  Pig.create(:name => "Babe")
         
     | 
| 
       43 
     | 
    
         
            -
                  ActiveRecord::Base.total_objects_instantiated.should == 0
         
     | 
| 
       44 
     | 
    
         
            -
                end
         
     | 
| 
       45 
     | 
    
         
            -
              end
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,84 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            module Oink
         
     | 
| 
       4 
     | 
    
         
            -
              module Instrumentation
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
                describe StatmMemorySnapshot do
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
                  before do
         
     | 
| 
       9 
     | 
    
         
            -
                    StatmMemorySnapshot.unset_statm_page_size
         
     | 
| 
       10 
     | 
    
         
            -
                  end
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                  it "returns memory when pagesize is 4096" do
         
     | 
| 
       13 
     | 
    
         
            -
                    pages = 6271
         
     | 
| 
       14 
     | 
    
         
            -
                    statm_file = "#{pages} 1157 411 1 0 763 0\n"
         
     | 
| 
       15 
     | 
    
         
            -
                    File.should_receive(:read).with("/proc/self/statm").and_return(statm_file)
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
                    system_call = mock(SystemCall, :stdout => "4096\n", :success? => true)
         
     | 
| 
       18 
     | 
    
         
            -
                    SystemCall.should_receive(:execute).with('getconf PAGESIZE').and_return(system_call)
         
     | 
| 
       19 
     | 
    
         
            -
                    StatmMemorySnapshot.new.memory.should == (pages * 4)
         
     | 
| 
       20 
     | 
    
         
            -
                  end
         
     | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
                  it "falls back to a 4096 if getconf PAGESIZE is not available" do
         
     | 
| 
       23 
     | 
    
         
            -
                    pages = 6271
         
     | 
| 
       24 
     | 
    
         
            -
                    statm_file = "#{pages} 1157 411 1 0 763 0\n"
         
     | 
| 
       25 
     | 
    
         
            -
                    File.should_receive(:read).with("/proc/self/statm").and_return(statm_file)
         
     | 
| 
       26 
     | 
    
         
            -
                    system_call = mock(SystemCall, :stdout => "", :success? => false)
         
     | 
| 
       27 
     | 
    
         
            -
                    SystemCall.should_receive(:execute).with('getconf PAGESIZE').and_return(system_call)
         
     | 
| 
       28 
     | 
    
         
            -
                    StatmMemorySnapshot.new.memory.should == (pages * 4)
         
     | 
| 
       29 
     | 
    
         
            -
                  end
         
     | 
| 
       30 
     | 
    
         
            -
                end
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
                describe SmapsMemorySnapshot do
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                  it "returns a sum of the sizes in the /proc/$$/smaps file" do
         
     | 
| 
       35 
     | 
    
         
            -
                    proc_file = <<-STR
         
     | 
| 
       36 
     | 
    
         
            -
                        Header
         
     | 
| 
       37 
     | 
    
         
            -
             
     | 
| 
       38 
     | 
    
         
            -
                        Size: 25
         
     | 
| 
       39 
     | 
    
         
            -
                        Size: 13 trailing
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
                  leading Size: 4
         
     | 
| 
       42 
     | 
    
         
            -
             
     | 
| 
       43 
     | 
    
         
            -
                        Footer
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
                        STR
         
     | 
| 
       46 
     | 
    
         
            -
                    File.should_receive(:new).with("/proc/#{$$}/smaps").and_return(proc_file)
         
     | 
| 
       47 
     | 
    
         
            -
                    SmapsMemorySnapshot.new.memory.should == 42
         
     | 
| 
       48 
     | 
    
         
            -
                  end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                end
         
     | 
| 
       51 
     | 
    
         
            -
             
     | 
| 
       52 
     | 
    
         
            -
                describe ProcessStatusMemorySnapshot do
         
     | 
| 
       53 
     | 
    
         
            -
                  it "returns the result of a PS command" do
         
     | 
| 
       54 
     | 
    
         
            -
                    system_call = mock(SystemCall, :stdout => "915")
         
     | 
| 
       55 
     | 
    
         
            -
                    SystemCall.should_receive(:execute).with("ps -o vsz= -p #{$$}").and_return(system_call)
         
     | 
| 
       56 
     | 
    
         
            -
                    ProcessStatusMemorySnapshot.new.memory.should == 915
         
     | 
| 
       57 
     | 
    
         
            -
                  end
         
     | 
| 
       58 
     | 
    
         
            -
             
     | 
| 
       59 
     | 
    
         
            -
                  describe "#available?" do
         
     | 
| 
       60 
     | 
    
         
            -
                    it "returns true if ps succeeds" do
         
     | 
| 
       61 
     | 
    
         
            -
                      system_call = mock(SystemCall, :success? => true)
         
     | 
| 
       62 
     | 
    
         
            -
                      SystemCall.should_receive(:execute).with("ps -o vsz= -p #{$$}").and_return(system_call)
         
     | 
| 
       63 
     | 
    
         
            -
                      ProcessStatusMemorySnapshot.available?.should be_true
         
     | 
| 
       64 
     | 
    
         
            -
                    end
         
     | 
| 
       65 
     | 
    
         
            -
                  end
         
     | 
| 
       66 
     | 
    
         
            -
                end
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                describe MemorySnapshot do
         
     | 
| 
       69 
     | 
    
         
            -
                  describe "#memory_snapshot_class" do
         
     | 
| 
       70 
     | 
    
         
            -
                    it "raises an Oink::MemoryDataUnavailableError if not strategies can be found" do
         
     | 
| 
       71 
     | 
    
         
            -
                      [WindowsMemorySnapshot, StatmMemorySnapshot, SmapsMemorySnapshot, ProcessStatusMemorySnapshot].each { |klass| klass.stub(:available? => false) }
         
     | 
| 
       72 
     | 
    
         
            -
             
     | 
| 
       73 
     | 
    
         
            -
                      lambda { MemorySnapshot.memory_snapshot_class }.should raise_error(MemoryDataUnavailableError)
         
     | 
| 
       74 
     | 
    
         
            -
                    end
         
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
                    it "returns the first available memory snapshot strategy" do
         
     | 
| 
       77 
     | 
    
         
            -
                      [WindowsMemorySnapshot, SmapsMemorySnapshot, ProcessStatusMemorySnapshot].each { |klass| klass.stub(:available? => false) }
         
     | 
| 
       78 
     | 
    
         
            -
                      StatmMemorySnapshot.stub(:available? => true)
         
     | 
| 
       79 
     | 
    
         
            -
                      MemorySnapshot.memory_snapshot_class.should == StatmMemorySnapshot
         
     | 
| 
       80 
     | 
    
         
            -
                    end
         
     | 
| 
       81 
     | 
    
         
            -
                  end
         
     | 
| 
       82 
     | 
    
         
            -
                end
         
     | 
| 
       83 
     | 
    
         
            -
              end
         
     | 
| 
       84 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,65 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
         
     | 
| 
       2 
     | 
    
         
            -
            require "oink/middleware"
         
     | 
| 
       3 
     | 
    
         
            -
            require 'rack/test'
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            describe "Oink::Middleware configuration" do
         
     | 
| 
       6 
     | 
    
         
            -
              include Rack::Test::Methods
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
              class SampleApplication
         
     | 
| 
       9 
     | 
    
         
            -
                def call(env)
         
     | 
| 
       10 
     | 
    
         
            -
                  [200, {}, ""]
         
     | 
| 
       11 
     | 
    
         
            -
                end
         
     | 
| 
       12 
     | 
    
         
            -
              end
         
     | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
              let(:app)         { Oink::Middleware.new(SampleApplication.new, oink_configuration) }
         
     | 
| 
       15 
     | 
    
         
            -
              let(:oink_configuration) { @oink_configuration || {} }
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
              context "instruments options" do
         
     | 
| 
       18 
     | 
    
         
            -
                before do
         
     | 
| 
       19 
     | 
    
         
            -
                  @log_output = StringIO.new
         
     | 
| 
       20 
     | 
    
         
            -
                  Hodel3000CompliantLogger.stub(:new => Hodel3000CompliantLogger.new(@log_output))
         
     | 
| 
       21 
     | 
    
         
            -
                  Oink::Instrumentation::MemorySnapshot.stub(:memory => 4092)
         
     | 
| 
       22 
     | 
    
         
            -
                end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
                context "with the memory instrument specified" do
         
     | 
| 
       25 
     | 
    
         
            -
                  before do
         
     | 
| 
       26 
     | 
    
         
            -
                    @oink_configuration = { :instruments => :memory }
         
     | 
| 
       27 
     | 
    
         
            -
                  end
         
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
                  it "does log memory usage" do
         
     | 
| 
       30 
     | 
    
         
            -
                    get "/"
         
     | 
| 
       31 
     | 
    
         
            -
                    @log_output.string.should include("Memory usage: 4092 | PID: #{$$}")
         
     | 
| 
       32 
     | 
    
         
            -
                  end
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                  it "does not log activerecord objects instantiated" do
         
     | 
| 
       35 
     | 
    
         
            -
                    get "/"
         
     | 
| 
       36 
     | 
    
         
            -
                    @log_output.string.should_not include("Instantiation Breakdown:")
         
     | 
| 
       37 
     | 
    
         
            -
                  end
         
     | 
| 
       38 
     | 
    
         
            -
             
     | 
| 
       39 
     | 
    
         
            -
                  it "does not monkeypatch activerecord" do
         
     | 
| 
       40 
     | 
    
         
            -
                    ActiveRecord::Base.should_not_receive(:include)
         
     | 
| 
       41 
     | 
    
         
            -
                    get "/"
         
     | 
| 
       42 
     | 
    
         
            -
                  end
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                  it "does not call reset_instance_type_count" do
         
     | 
| 
       45 
     | 
    
         
            -
                    ActiveRecord::Base.should_not_receive(:reset_instance_type_count)
         
     | 
| 
       46 
     | 
    
         
            -
                    get "/"
         
     | 
| 
       47 
     | 
    
         
            -
                  end
         
     | 
| 
       48 
     | 
    
         
            -
                end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                context "with the activerecord instrument specified" do
         
     | 
| 
       51 
     | 
    
         
            -
                  before do
         
     | 
| 
       52 
     | 
    
         
            -
                    @oink_configuration = { :instruments => :activerecord }
         
     | 
| 
       53 
     | 
    
         
            -
                    get "/"
         
     | 
| 
       54 
     | 
    
         
            -
                  end
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
       56 
     | 
    
         
            -
                  it "does not log memory usage" do
         
     | 
| 
       57 
     | 
    
         
            -
                    @log_output.string.should_not include("Memory usage:")
         
     | 
| 
       58 
     | 
    
         
            -
                  end
         
     | 
| 
       59 
     | 
    
         
            -
             
     | 
| 
       60 
     | 
    
         
            -
                  it "does log activerecord objects instantiated" do
         
     | 
| 
       61 
     | 
    
         
            -
                    @log_output.string.should include("Instantiation Breakdown:")
         
     | 
| 
       62 
     | 
    
         
            -
                  end
         
     | 
| 
       63 
     | 
    
         
            -
                end
         
     | 
| 
       64 
     | 
    
         
            -
              end
         
     | 
| 
       65 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,82 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
         
     | 
| 
       2 
     | 
    
         
            -
            require "oink/middleware"
         
     | 
| 
       3 
     | 
    
         
            -
            require 'rack/test'
         
     | 
| 
       4 
     | 
    
         
            -
             
     | 
| 
       5 
     | 
    
         
            -
            describe Oink::Middleware do
         
     | 
| 
       6 
     | 
    
         
            -
              include Rack::Test::Methods
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
              class SampleApplication
         
     | 
| 
       9 
     | 
    
         
            -
                def call(env)
         
     | 
| 
       10 
     | 
    
         
            -
                  case env['PATH_INFO']
         
     | 
| 
       11 
     | 
    
         
            -
                  when "/no_pigs"
         
     | 
| 
       12 
     | 
    
         
            -
                  when "/two_pigs"
         
     | 
| 
       13 
     | 
    
         
            -
                    Pig.create(:name => "Babe")
         
     | 
| 
       14 
     | 
    
         
            -
                    Pig.first
         
     | 
| 
       15 
     | 
    
         
            -
                  when "/two_pigs_in_a_pen"
         
     | 
| 
       16 
     | 
    
         
            -
                    Pig.create(:name => "Babe")
         
     | 
| 
       17 
     | 
    
         
            -
                    Pen.create(:location => "Backyard")
         
     | 
| 
       18 
     | 
    
         
            -
                    Pig.first
         
     | 
| 
       19 
     | 
    
         
            -
                  end
         
     | 
| 
       20 
     | 
    
         
            -
                  [200, {}, ""]
         
     | 
| 
       21 
     | 
    
         
            -
                end
         
     | 
| 
       22 
     | 
    
         
            -
              end
         
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
              let(:log_output)  { StringIO.new }
         
     | 
| 
       25 
     | 
    
         
            -
              let(:logger)      { Hodel3000CompliantLogger.new(log_output) }
         
     | 
| 
       26 
     | 
    
         
            -
              let(:app)         { Oink::Middleware.new(SampleApplication.new, :logger => logger) }
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
              before do
         
     | 
| 
       29 
     | 
    
         
            -
                Oink::Instrumentation::MemorySnapshot.stub(:memory => 4092)
         
     | 
| 
       30 
     | 
    
         
            -
                Pig.delete_all
         
     | 
| 
       31 
     | 
    
         
            -
                Pen.delete_all
         
     | 
| 
       32 
     | 
    
         
            -
              end
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
              context "support legacy rails log format in transition to oink's own log format" do
         
     | 
| 
       35 
     | 
    
         
            -
                it "writes rails[pid] to the log even if the app isn't a rails app (for now)" do
         
     | 
| 
       36 
     | 
    
         
            -
                  get "/no_pigs"
         
     | 
| 
       37 
     | 
    
         
            -
                  log_output.string.should include("rails[#{$$}]")
         
     | 
| 
       38 
     | 
    
         
            -
                end
         
     | 
| 
       39 
     | 
    
         
            -
             
     | 
| 
       40 
     | 
    
         
            -
                it "writes 'Oink Log Entry Complete' after the request has completed" do
         
     | 
| 
       41 
     | 
    
         
            -
                  get "/no_pigs"
         
     | 
| 
       42 
     | 
    
         
            -
                  log_output.string.should include("Oink Log Entry Complete")
         
     | 
| 
       43 
     | 
    
         
            -
                end
         
     | 
| 
       44 
     | 
    
         
            -
             
     | 
| 
       45 
     | 
    
         
            -
                it "logs the action and controller in rails 3.x" do
         
     | 
| 
       46 
     | 
    
         
            -
                  get "/no_pigs", {}, {'action_dispatch.request.parameters' => {'controller' => 'oinkoink', 'action' => 'piggie'}}
         
     | 
| 
       47 
     | 
    
         
            -
                  log_output.string.should include("Oink Action: oinkoink#piggie")
         
     | 
| 
       48 
     | 
    
         
            -
                end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                it "logs the action and controller in rails 2.3.x" do
         
     | 
| 
       51 
     | 
    
         
            -
                  get "/no_pigs", {}, {'action_controller.request.path_parameters' => {'controller' => 'oinkoink', 'action' => 'piggie'}}
         
     | 
| 
       52 
     | 
    
         
            -
                  log_output.string.should include("Oink Action: oinkoink#piggie")
         
     | 
| 
       53 
     | 
    
         
            -
                end
         
     | 
| 
       54 
     | 
    
         
            -
             
     | 
| 
       55 
     | 
    
         
            -
                it "logs the action and controller within a module" do
         
     | 
| 
       56 
     | 
    
         
            -
                  get "/no_pigs", {}, {'action_dispatch.request.parameters' => {'controller' => 'oinkoink/admin', 'action' => 'piggie'}}
         
     | 
| 
       57 
     | 
    
         
            -
                  log_output.string.should include("Oink Action: oinkoink/admin#piggie")
         
     | 
| 
       58 
     | 
    
         
            -
                end
         
     | 
| 
       59 
     | 
    
         
            -
              end
         
     | 
| 
       60 
     | 
    
         
            -
             
     | 
| 
       61 
     | 
    
         
            -
              it "reports 0 totals" do
         
     | 
| 
       62 
     | 
    
         
            -
                get "/no_pigs"
         
     | 
| 
       63 
     | 
    
         
            -
                log_output.string.should include("Instantiation Breakdown: Total: 0")
         
     | 
| 
       64 
     | 
    
         
            -
              end
         
     | 
| 
       65 
     | 
    
         
            -
             
     | 
| 
       66 
     | 
    
         
            -
              it "reports totals first even if it's a tie" do
         
     | 
| 
       67 
     | 
    
         
            -
                get "/two_pigs"
         
     | 
| 
       68 
     | 
    
         
            -
                log_output.string.should include("Instantiation Breakdown: Total: 2 | Pig: 2")
         
     | 
| 
       69 
     | 
    
         
            -
              end
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
              it "reports pigs and pens instantiated" do
         
     | 
| 
       72 
     | 
    
         
            -
                get "/two_pigs_in_a_pen"
         
     | 
| 
       73 
     | 
    
         
            -
                log_output.string.should include("Instantiation Breakdown: Total: 3 | Pig: 2 | Pen: 1")
         
     | 
| 
       74 
     | 
    
         
            -
              end
         
     | 
| 
       75 
     | 
    
         
            -
             
     | 
| 
       76 
     | 
    
         
            -
              it "logs memory usage" do
         
     | 
| 
       77 
     | 
    
         
            -
                Oink::Instrumentation::MemorySnapshot.should_receive(:memory).and_return(4092)
         
     | 
| 
       78 
     | 
    
         
            -
                get "/two_pigs_in_a_pen"
         
     | 
| 
       79 
     | 
    
         
            -
                log_output.string.should include("Memory usage: 4092 | PID: #{$$}")
         
     | 
| 
       80 
     | 
    
         
            -
              end
         
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,52 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class ARCountApplicationController < FakeApplicationController
         
     | 
| 
       4 
     | 
    
         
            -
              include Oink::InstanceTypeCounter
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
              def no_pigs
         
     | 
| 
       7 
     | 
    
         
            -
                run_around_filters
         
     | 
| 
       8 
     | 
    
         
            -
              end
         
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
              def two_pigs_in_a_pen
         
     | 
| 
       11 
     | 
    
         
            -
                Pig.create!
         
     | 
| 
       12 
     | 
    
         
            -
                Pig.create!
         
     | 
| 
       13 
     | 
    
         
            -
                Pen.create!
         
     | 
| 
       14 
     | 
    
         
            -
                run_around_filters
         
     | 
| 
       15 
     | 
    
         
            -
              end
         
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
              def two_pigs
         
     | 
| 
       18 
     | 
    
         
            -
                Pig.create!
         
     | 
| 
       19 
     | 
    
         
            -
                Pig.create!
         
     | 
| 
       20 
     | 
    
         
            -
                run_around_filters
         
     | 
| 
       21 
     | 
    
         
            -
              end
         
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
            end
         
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
       25 
     | 
    
         
            -
            describe Oink::InstanceTypeCounter do
         
     | 
| 
       26 
     | 
    
         
            -
             
     | 
| 
       27 
     | 
    
         
            -
              before do
         
     | 
| 
       28 
     | 
    
         
            -
                Pig.delete_all
         
     | 
| 
       29 
     | 
    
         
            -
                Pen.delete_all
         
     | 
| 
       30 
     | 
    
         
            -
              end
         
     | 
| 
       31 
     | 
    
         
            -
             
     | 
| 
       32 
     | 
    
         
            -
              let(:log_output)  { StringIO.new }
         
     | 
| 
       33 
     | 
    
         
            -
              let(:logger)      { Logger.new(log_output) }
         
     | 
| 
       34 
     | 
    
         
            -
             
     | 
| 
       35 
     | 
    
         
            -
              it "reports no AR objects instantiated" do
         
     | 
| 
       36 
     | 
    
         
            -
                controller = ARCountApplicationController.new(logger)
         
     | 
| 
       37 
     | 
    
         
            -
                controller.no_pigs
         
     | 
| 
       38 
     | 
    
         
            -
                log_output.string.should include("Instantiation Breakdown: Total: 0")
         
     | 
| 
       39 
     | 
    
         
            -
              end
         
     | 
| 
       40 
     | 
    
         
            -
             
     | 
| 
       41 
     | 
    
         
            -
              it "reports AR objects instantiated by type" do
         
     | 
| 
       42 
     | 
    
         
            -
                controller = ARCountApplicationController.new(logger)
         
     | 
| 
       43 
     | 
    
         
            -
                controller.two_pigs_in_a_pen
         
     | 
| 
       44 
     | 
    
         
            -
                log_output.string.should include("Instantiation Breakdown: Total: 3 | Pig: 2 | Pen: 1")
         
     | 
| 
       45 
     | 
    
         
            -
              end
         
     | 
| 
       46 
     | 
    
         
            -
             
     | 
| 
       47 
     | 
    
         
            -
              it "reports totals first even if its a tie" do
         
     | 
| 
       48 
     | 
    
         
            -
                controller = ARCountApplicationController.new(logger)
         
     | 
| 
       49 
     | 
    
         
            -
                controller.two_pigs
         
     | 
| 
       50 
     | 
    
         
            -
                log_output.string.should include("Instantiation Breakdown: Total: 2 | Pig: 2")
         
     | 
| 
       51 
     | 
    
         
            -
              end
         
     | 
| 
       52 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,23 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            class MemoryLoggerApplicationController < FakeApplicationController
         
     | 
| 
       4 
     | 
    
         
            -
              include Oink::MemoryUsageLogger
         
     | 
| 
       5 
     | 
    
         
            -
            end
         
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
            describe Oink::MemoryUsageLogger do
         
     | 
| 
       8 
     | 
    
         
            -
              it "should return memory usage info from the snapshot" do
         
     | 
| 
       9 
     | 
    
         
            -
                Oink::Instrumentation::MemorySnapshot.should_receive("memory").and_return(42)
         
     | 
| 
       10 
     | 
    
         
            -
                log_output = StringIO.new
         
     | 
| 
       11 
     | 
    
         
            -
                controller = MemoryLoggerApplicationController.new(Logger.new(log_output))
         
     | 
| 
       12 
     | 
    
         
            -
                controller.index
         
     | 
| 
       13 
     | 
    
         
            -
                log_output.string.should include("Memory usage: 42 | PID: #{$$}")
         
     | 
| 
       14 
     | 
    
         
            -
              end
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
              it "should log an error message if cannot find a memory snapshot strategy" do
         
     | 
| 
       17 
     | 
    
         
            -
                Oink::Instrumentation::MemorySnapshot.should_receive("memory").and_raise(Oink::Instrumentation::MemoryDataUnavailableError)
         
     | 
| 
       18 
     | 
    
         
            -
                controller = MemoryLoggerApplicationController.new
         
     | 
| 
       19 
     | 
    
         
            -
                lambda {
         
     | 
| 
       20 
     | 
    
         
            -
                  controller.index
         
     | 
| 
       21 
     | 
    
         
            -
                }.should_not raise_error
         
     | 
| 
       22 
     | 
    
         
            -
              end
         
     | 
| 
       23 
     | 
    
         
            -
            end
         
     | 
| 
         @@ -1,193 +0,0 @@ 
     | 
|
| 
       1 
     | 
    
         
            -
            require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
         
     | 
| 
       2 
     | 
    
         
            -
             
     | 
| 
       3 
     | 
    
         
            -
            module Oink::Reports
         
     | 
| 
       4 
     | 
    
         
            -
              describe ActiveRecordInstantiationReport do
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
                describe "short summary with frequent offenders" do
         
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
       8 
     | 
    
         
            -
                  it "should report actions which exceed the threshold once" do
         
     | 
| 
       9 
     | 
    
         
            -
                    str = <<-STR
         
     | 
| 
       10 
     | 
    
         
            -
                    Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
         
     | 
| 
       11 
     | 
    
         
            -
                    Feb 01 01:58:30 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 51 | User: 51
         
     | 
| 
       12 
     | 
    
         
            -
                    Feb 01 01:58:31 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       13 
     | 
    
         
            -
                    STR
         
     | 
| 
       14 
     | 
    
         
            -
             
     | 
| 
       15 
     | 
    
         
            -
                    io = StringIO.new(str)
         
     | 
| 
       16 
     | 
    
         
            -
                    output = PsuedoOutput.new
         
     | 
| 
       17 
     | 
    
         
            -
                    ActiveRecordInstantiationReport.new(io, 50).print(output)
         
     | 
| 
       18 
     | 
    
         
            -
                    output.should include("1, Users#show")
         
     | 
| 
       19 
     | 
    
         
            -
                  end
         
     | 
| 
       20 
     | 
    
         
            -
             
     | 
| 
       21 
     | 
    
         
            -
                  it "should not report actions which do not exceed the threshold" do
         
     | 
| 
       22 
     | 
    
         
            -
                    str = <<-STR
         
     | 
| 
       23 
     | 
    
         
            -
                    Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
         
     | 
| 
       24 
     | 
    
         
            -
                    Feb 01 01:58:30 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 50 | User: 50
         
     | 
| 
       25 
     | 
    
         
            -
                    Feb 01 01:58:31 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       26 
     | 
    
         
            -
                    STR
         
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
                    io = StringIO.new(str)
         
     | 
| 
       29 
     | 
    
         
            -
                    output = PsuedoOutput.new
         
     | 
| 
       30 
     | 
    
         
            -
                    ActiveRecordInstantiationReport.new(io, 50).print(output)
         
     | 
| 
       31 
     | 
    
         
            -
                    output.should_not include("1, Users#show")
         
     | 
| 
       32 
     | 
    
         
            -
                  end
         
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                  it "should report actions which exceed the threshold multiple times" do
         
     | 
| 
       35 
     | 
    
         
            -
                    str = <<-STR
         
     | 
| 
       36 
     | 
    
         
            -
                    Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
         
     | 
| 
       37 
     | 
    
         
            -
                    Feb 01 01:58:30 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 51 | User: 51
         
     | 
| 
       38 
     | 
    
         
            -
                    Feb 01 01:58:31 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       39 
     | 
    
         
            -
                    Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
         
     | 
| 
       40 
     | 
    
         
            -
                    Feb 01 01:58:30 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 51 | User: 51
         
     | 
| 
       41 
     | 
    
         
            -
                    Feb 01 01:58:31 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       42 
     | 
    
         
            -
                    STR
         
     | 
| 
       43 
     | 
    
         
            -
             
     | 
| 
       44 
     | 
    
         
            -
                    io = StringIO.new(str)
         
     | 
| 
       45 
     | 
    
         
            -
                    output = PsuedoOutput.new
         
     | 
| 
       46 
     | 
    
         
            -
                    ActiveRecordInstantiationReport.new(io, 50).print(output)
         
     | 
| 
       47 
     | 
    
         
            -
                    output.should include("2, Users#show")
         
     | 
| 
       48 
     | 
    
         
            -
                  end
         
     | 
| 
       49 
     | 
    
         
            -
             
     | 
| 
       50 
     | 
    
         
            -
                  it "should order actions by most exceeded" do
         
     | 
| 
       51 
     | 
    
         
            -
                    str = <<-STR
         
     | 
| 
       52 
     | 
    
         
            -
                    Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
         
     | 
| 
       53 
     | 
    
         
            -
                    Feb 01 01:58:30 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 51 | User: 51
         
     | 
| 
       54 
     | 
    
         
            -
                    Feb 01 01:58:31 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       55 
     | 
    
         
            -
                    Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
         
     | 
| 
       56 
     | 
    
         
            -
                    Feb 01 01:58:30 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 51 | User: 51
         
     | 
| 
       57 
     | 
    
         
            -
                    Feb 01 01:58:31 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       58 
     | 
    
         
            -
                    Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
         
     | 
| 
       59 
     | 
    
         
            -
                    Feb 01 01:58:30 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 51 | User: 51
         
     | 
| 
       60 
     | 
    
         
            -
                    Feb 01 01:58:31 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       61 
     | 
    
         
            -
                    STR
         
     | 
| 
       62 
     | 
    
         
            -
             
     | 
| 
       63 
     | 
    
         
            -
                    io = StringIO.new(str)
         
     | 
| 
       64 
     | 
    
         
            -
                    output = PsuedoOutput.new
         
     | 
| 
       65 
     | 
    
         
            -
                    ActiveRecordInstantiationReport.new(io, 50).print(output)
         
     | 
| 
       66 
     | 
    
         
            -
                    output[-2].should == "2, Media#show"
         
     | 
| 
       67 
     | 
    
         
            -
                    output[-1].should == "1, Users#show"
         
     | 
| 
       68 
     | 
    
         
            -
                  end
         
     | 
| 
       69 
     | 
    
         
            -
             
     | 
| 
       70 
     | 
    
         
            -
                  it "should not be bothered by incomplete requests" do
         
     | 
| 
       71 
     | 
    
         
            -
                    str = <<-STR
         
     | 
| 
       72 
     | 
    
         
            -
                    Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
         
     | 
| 
       73 
     | 
    
         
            -
                    Feb 01 01:58:30 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 24 | User: 24
         
     | 
| 
       74 
     | 
    
         
            -
                    Feb 01 01:58:31 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       75 
     | 
    
         
            -
                    Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
         
     | 
| 
       76 
     | 
    
         
            -
                    Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
         
     | 
| 
       77 
     | 
    
         
            -
                    Feb 01 01:58:30 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 51 | User: 51
         
     | 
| 
       78 
     | 
    
         
            -
                    Feb 01 01:58:31 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       79 
     | 
    
         
            -
                    STR
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
                    io = StringIO.new(str)
         
     | 
| 
       82 
     | 
    
         
            -
                    output = PsuedoOutput.new
         
     | 
| 
       83 
     | 
    
         
            -
                    ActiveRecordInstantiationReport.new(io, 50).print(output)
         
     | 
| 
       84 
     | 
    
         
            -
                    output.should include("1, Users#show")
         
     | 
| 
       85 
     | 
    
         
            -
                  end
         
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
       87 
     | 
    
         
            -
                end
         
     | 
| 
       88 
     | 
    
         
            -
             
     | 
| 
       89 
     | 
    
         
            -
                describe "summary with top 10 offenses" do
         
     | 
| 
       90 
     | 
    
         
            -
             
     | 
| 
       91 
     | 
    
         
            -
                  it "should only report requests over threshold" do
         
     | 
| 
       92 
     | 
    
         
            -
                    str = <<-STR
         
     | 
| 
       93 
     | 
    
         
            -
                    Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
         
     | 
| 
       94 
     | 
    
         
            -
                    Feb 01 01:58:30 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 51 | User: 51
         
     | 
| 
       95 
     | 
    
         
            -
                    Feb 01 01:58:31 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       96 
     | 
    
         
            -
                    STR
         
     | 
| 
       97 
     | 
    
         
            -
             
     | 
| 
       98 
     | 
    
         
            -
                    io = StringIO.new(str)
         
     | 
| 
       99 
     | 
    
         
            -
                    output = PsuedoOutput.new
         
     | 
| 
       100 
     | 
    
         
            -
                    ActiveRecordInstantiationReport.new(io, 50).print(output)
         
     | 
| 
       101 
     | 
    
         
            -
                    output.should include("1. Feb 01 01:58:31, 51, Users#show")
         
     | 
| 
       102 
     | 
    
         
            -
                  end
         
     | 
| 
       103 
     | 
    
         
            -
             
     | 
| 
       104 
     | 
    
         
            -
                  it "should not include requests which are not over threshold" do
         
     | 
| 
       105 
     | 
    
         
            -
                    str = <<-STR
         
     | 
| 
       106 
     | 
    
         
            -
                    Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
         
     | 
| 
       107 
     | 
    
         
            -
                    Feb 01 01:58:30 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 50 | User: 50
         
     | 
| 
       108 
     | 
    
         
            -
                    Feb 01 01:58:31 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       109 
     | 
    
         
            -
                    STR
         
     | 
| 
       110 
     | 
    
         
            -
             
     | 
| 
       111 
     | 
    
         
            -
                    io = StringIO.new(str)
         
     | 
| 
       112 
     | 
    
         
            -
                    output = PsuedoOutput.new
         
     | 
| 
       113 
     | 
    
         
            -
                    ActiveRecordInstantiationReport.new(io, 50).print(output)
         
     | 
| 
       114 
     | 
    
         
            -
                    output.should_not include("1. Feb 01 01:58:31, 50, Users#show")
         
     | 
| 
       115 
     | 
    
         
            -
                  end
         
     | 
| 
       116 
     | 
    
         
            -
             
     | 
| 
       117 
     | 
    
         
            -
                  it "should order offenses from biggest to smallest" do
         
     | 
| 
       118 
     | 
    
         
            -
                    str = <<-STR
         
     | 
| 
       119 
     | 
    
         
            -
                    Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Details#show
         
     | 
| 
       120 
     | 
    
         
            -
                    Feb 01 01:58:30 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 75 | User: 75
         
     | 
| 
       121 
     | 
    
         
            -
                    Feb 01 01:58:31 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       122 
     | 
    
         
            -
                    Feb 01 01:58:32 ey04-s00297 rails[4413]: Oink Action: Media#show
         
     | 
| 
       123 
     | 
    
         
            -
                    Feb 01 01:58:33 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 100 | User: 100
         
     | 
| 
       124 
     | 
    
         
            -
                    Feb 01 01:58:34 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       125 
     | 
    
         
            -
                    STR
         
     | 
| 
       126 
     | 
    
         
            -
             
     | 
| 
       127 
     | 
    
         
            -
                    io = StringIO.new(str)
         
     | 
| 
       128 
     | 
    
         
            -
                    output = PsuedoOutput.new
         
     | 
| 
       129 
     | 
    
         
            -
                    ActiveRecordInstantiationReport.new(io, 50).print(output)
         
     | 
| 
       130 
     | 
    
         
            -
                    output[4].should == "1. Feb 01 01:58:34, 100, Media#show"
         
     | 
| 
       131 
     | 
    
         
            -
                    output[5].should == "2. Feb 01 01:58:31, 75, Details#show"
         
     | 
| 
       132 
     | 
    
         
            -
                  end
         
     | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
                end
         
     | 
| 
       135 
     | 
    
         
            -
             
     | 
| 
       136 
     | 
    
         
            -
                describe "verbose format" do
         
     | 
| 
       137 
     | 
    
         
            -
                  it "should print the full lines of actions exceeding the threshold" do
         
     | 
| 
       138 
     | 
    
         
            -
                    str = <<-STR
         
     | 
| 
       139 
     | 
    
         
            -
                    Feb 01 01:58:32 ey04-s00297 rails[4413]: Oink Action: Media#show
         
     | 
| 
       140 
     | 
    
         
            -
                    Feb 01 01:58:33 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 100 | User: 100
         
     | 
| 
       141 
     | 
    
         
            -
                    Feb 01 01:58:34 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       142 
     | 
    
         
            -
                    STR
         
     | 
| 
       143 
     | 
    
         
            -
                    io = StringIO.new(str)
         
     | 
| 
       144 
     | 
    
         
            -
                    output = PsuedoOutput.new
         
     | 
| 
       145 
     | 
    
         
            -
                    ActiveRecordInstantiationReport.new(io, 50, :format => :verbose).print(output)
         
     | 
| 
       146 
     | 
    
         
            -
                    output[3..5].should == str.split("\n")[0..2].map { |o| o.strip }
         
     | 
| 
       147 
     | 
    
         
            -
                  end
         
     | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
       149 
     | 
    
         
            -
                  it "should handle actions which do not complete properly" do
         
     | 
| 
       150 
     | 
    
         
            -
                    str = <<-STR
         
     | 
| 
       151 
     | 
    
         
            -
                    Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
         
     | 
| 
       152 
     | 
    
         
            -
                    Feb 01 01:58:30 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 24 | User: 24
         
     | 
| 
       153 
     | 
    
         
            -
                    Feb 01 01:58:31 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       154 
     | 
    
         
            -
                    Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Media#show
         
     | 
| 
       155 
     | 
    
         
            -
                    Feb 01 01:58:29 ey04-s00297 rails[4413]: Oink Action: Users#show
         
     | 
| 
       156 
     | 
    
         
            -
                    Feb 01 01:58:30 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 51 | User: 51
         
     | 
| 
       157 
     | 
    
         
            -
                    Feb 01 01:58:31 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       158 
     | 
    
         
            -
                    STR
         
     | 
| 
       159 
     | 
    
         
            -
             
     | 
| 
       160 
     | 
    
         
            -
                    io = StringIO.new(str)
         
     | 
| 
       161 
     | 
    
         
            -
                    output = PsuedoOutput.new
         
     | 
| 
       162 
     | 
    
         
            -
                    ActiveRecordInstantiationReport.new(io, 50, :format => :verbose).print(output)
         
     | 
| 
       163 
     | 
    
         
            -
                    output[3..5].should == str.split("\n")[4..6].map { |o| o.strip }
         
     | 
| 
       164 
     | 
    
         
            -
                  end
         
     | 
| 
       165 
     | 
    
         
            -
                end
         
     | 
| 
       166 
     | 
    
         
            -
             
     | 
| 
       167 
     | 
    
         
            -
                describe "multiple io streams" do
         
     | 
| 
       168 
     | 
    
         
            -
                  it "should accept multiple files" do
         
     | 
| 
       169 
     | 
    
         
            -
             
     | 
| 
       170 
     | 
    
         
            -
                    str1 = <<-STR
         
     | 
| 
       171 
     | 
    
         
            -
                    Feb 01 01:58:32 ey04-s00297 rails[4413]: Oink Action: Media#show
         
     | 
| 
       172 
     | 
    
         
            -
                    Feb 01 01:58:33 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 100 | User: 100
         
     | 
| 
       173 
     | 
    
         
            -
                    Feb 01 01:58:34 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       174 
     | 
    
         
            -
                    STR
         
     | 
| 
       175 
     | 
    
         
            -
             
     | 
| 
       176 
     | 
    
         
            -
                    str2 = <<-STR
         
     | 
| 
       177 
     | 
    
         
            -
                    Feb 01 01:58:32 ey04-s00297 rails[4413]: Oink Action: Media#show
         
     | 
| 
       178 
     | 
    
         
            -
                    Feb 01 01:58:33 ey04-s00297 rails[4413]: Instantiation Breakdown: Total: 100 | User: 100
         
     | 
| 
       179 
     | 
    
         
            -
                    Feb 01 01:58:34 ey04-s00297 rails[4413]: Oink Log Entry Complete
         
     | 
| 
       180 
     | 
    
         
            -
                    STR
         
     | 
| 
       181 
     | 
    
         
            -
             
     | 
| 
       182 
     | 
    
         
            -
                    io1 = StringIO.new(str1)
         
     | 
| 
       183 
     | 
    
         
            -
                    io2 = StringIO.new(str2)
         
     | 
| 
       184 
     | 
    
         
            -
                    output = PsuedoOutput.new
         
     | 
| 
       185 
     | 
    
         
            -
                    ActiveRecordInstantiationReport.new([io1, io2], 50).print(output)
         
     | 
| 
       186 
     | 
    
         
            -
                    output.should include("2, Media#show")
         
     | 
| 
       187 
     | 
    
         
            -
                  end
         
     | 
| 
       188 
     | 
    
         
            -
             
     | 
| 
       189 
     | 
    
         
            -
                end
         
     | 
| 
       190 
     | 
    
         
            -
             
     | 
| 
       191 
     | 
    
         
            -
             
     | 
| 
       192 
     | 
    
         
            -
              end
         
     | 
| 
       193 
     | 
    
         
            -
            end
         
     |