Skip to content
This repository
Browse code

Added test

  • Loading branch information...
commit 2b1c0a878e009b590c32dc8744ae5cd6f28e4526 1 parent 346c5aa
Derek Haynes authored November 06, 2012
10  apache_load/fixtures/initial.txt
... ...
@@ -0,0 +1,10 @@
  1
+Total Accesses: 10
  2
+Total kBytes: 37785
  3
+CPULoad: .0235016
  4
+Uptime: 701143
  5
+ReqPerSec: .60533
  6
+BytesPerSec: 55.1839
  7
+BytesPerReq: 91.1634
  8
+BusyWorkers: 1
  9
+IdleWorkers: 49
  10
+Scoreboard: ________________________W......................................................................................................._________________________.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
8  apache_load/fixtures/restart.txt
... ...
@@ -0,0 +1,8 @@
  1
+Total Accesses: 0
  2
+Total kBytes: 0
  3
+Uptime: 2
  4
+ReqPerSec: 0
  5
+BytesPerSec: 0
  6
+BusyWorkers: 1
  7
+IdleWorkers: 49
  8
+Scoreboard: _________________________.......................................W________________________.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
10  apache_load/fixtures/second_run.txt
... ...
@@ -0,0 +1,10 @@
  1
+Total Accesses: 20
  2
+Total kBytes: 37789
  3
+CPULoad: .0235202
  4
+Uptime: 701482
  5
+ReqPerSec: .605333
  6
+BytesPerSec: 55.1631
  7
+BytesPerReq: 91.1286
  8
+BusyWorkers: 1
  9
+IdleWorkers: 49
  10
+Scoreboard: _________________________.......................................................................................................____________W____________.......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
38  apache_load/test.rb
... ...
@@ -0,0 +1,38 @@
  1
+require File.expand_path('../../test_helper.rb', __FILE__)
  2
+require File.expand_path('../apache_load.rb', __FILE__)
  3
+
  4
+class ApacheLoadTest < Test::Unit::TestCase
  5
+  
  6
+  def setup
  7
+    @options=parse_defaults("apache_load")
  8
+  end
  9
+  
  10
+  def teardown
  11
+    FakeWeb.clean_registry
  12
+  end
  13
+  
  14
+  def test_run
  15
+    time = Time.parse("12/1/12 12:00")
  16
+    Timecop.travel(time) do 
  17
+      plugin=ApacheLoad.new(nil,{},@options)
  18
+      FakeWeb.register_uri(:get, 'http://localhost/server-status?auto', :body => File.read(File.dirname(__FILE__)+'/fixtures/initial.txt'))
  19
+
  20
+      res= plugin.run()
  21
+
  22
+      assert res[:alerts].empty?, res[:alerts]
  23
+      assert res[:errors].empty?, res[:errors]
  24
+      assert_equal 49, res[:reports].first[:idle_workers]
  25
+      assert_equal 1, res[:reports].first[:busy_workers]
  26
+      memory=res[:memory]
  27
+      assert memory.any?
  28
+      
  29
+      Timecop.travel(time+60) do
  30
+        plugin=ApacheLoad.new(nil,memory,@options)
  31
+        FakeWeb.register_uri(:get, 'http://localhost/server-status?auto', :body => File.read(File.dirname(__FILE__)+'/fixtures/second_run.txt'))
  32
+        res= plugin.run()
  33
+        assert_in_delta 10/60.to_f, res[:reports].first[:current_load], 0.001
  34
+      end
  35
+    end  
  36
+  end
  37
+  
  38
+end

0 notes on commit 2b1c0a8

Please sign in to comment.
Something went wrong with that request. Please try again.