god 0.13.4 → 0.13.5

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.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/History.txt +13 -0
  3. data/doc/god.asciidoc +50 -8
  4. data/ext/god/extconf.rb +1 -0
  5. data/ext/god/kqueue_handler.c +9 -1
  6. data/ext/god/netlink_handler.c +17 -0
  7. data/god.gemspec +12 -3
  8. data/lib/god.rb +3 -1
  9. data/lib/god/contacts/slack.rb +100 -0
  10. data/lib/god/contacts/statsd.rb +46 -0
  11. data/lib/god/contacts/webhook.rb +1 -0
  12. data/lib/god/process.rb +10 -5
  13. data/test/helper.rb +8 -3
  14. data/test/test_airbrake.rb +1 -1
  15. data/test/test_behavior.rb +2 -2
  16. data/test/test_campfire.rb +1 -1
  17. data/test/test_condition.rb +3 -3
  18. data/test/test_conditions_disk_usage.rb +1 -1
  19. data/test/test_conditions_http_response_code.rb +1 -1
  20. data/test/test_conditions_process_running.rb +1 -1
  21. data/test/test_conditions_socket_responding.rb +1 -1
  22. data/test/test_conditions_tries.rb +3 -3
  23. data/test/test_contact.rb +9 -9
  24. data/test/test_driver.rb +4 -3
  25. data/test/test_email.rb +1 -1
  26. data/test/test_event_handler.rb +2 -2
  27. data/test/test_god.rb +9 -7
  28. data/test/test_handlers_kqueue_handler.rb +1 -1
  29. data/test/test_hipchat.rb +1 -1
  30. data/test/test_jabber.rb +1 -1
  31. data/test/test_logger.rb +3 -3
  32. data/test/test_metric.rb +1 -1
  33. data/test/test_process.rb +7 -3
  34. data/test/test_prowl.rb +1 -1
  35. data/test/test_registry.rb +1 -1
  36. data/test/test_slack.rb +56 -0
  37. data/test/test_socket.rb +1 -1
  38. data/test/test_statsd.rb +22 -0
  39. data/test/test_sugar.rb +1 -1
  40. data/test/test_system_portable_poller.rb +1 -1
  41. data/test/test_system_process.rb +1 -1
  42. data/test/test_task.rb +4 -4
  43. data/test/test_timeline.rb +1 -1
  44. data/test/test_trigger.rb +5 -1
  45. data/test/test_watch.rb +1 -1
  46. data/test/test_webhook.rb +1 -1
  47. metadata +240 -223
@@ -7,7 +7,8 @@ require File.join(File.dirname(__FILE__), *%w[.. lib god sys_logger])
7
7
  require File.join(File.dirname(__FILE__), *%w[.. lib god])
8
8
  God::EventHandler.load
9
9
 
10
- require 'test/unit'
10
+ require 'minitest/autorun'
11
+ require 'minitest/unit'
11
12
  require 'set'
12
13
 
13
14
  include God
@@ -115,12 +116,16 @@ end
115
116
  # end
116
117
  # end
117
118
 
118
- module Test::Unit::Assertions
119
+ module Minitest::Assertions
119
120
  def assert_abort
120
- assert_raise SystemExit do
121
+ assert_raises SystemExit do
121
122
  yield
122
123
  end
123
124
  end
125
+
126
+ def assert_nothing_raised
127
+ yield
128
+ end
124
129
  end
125
130
 
126
131
  # This allows you to be a good OOP citizen and honor encapsulation, but
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require File.dirname(__FILE__) + '/helper'
3
3
 
4
- class TestAirbrake < Test::Unit::TestCase
4
+ class TestAirbrake < Minitest::Test
5
5
  def test_notify
6
6
  airbrake = God::Contacts::Airbrake.new
7
7
  airbrake.apikey = "put_your_apikey_here"
@@ -1,12 +1,12 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
- class TestBehavior < Test::Unit::TestCase
3
+ class TestBehavior < Minitest::Test
4
4
  def test_generate_should_return_an_object_corresponding_to_the_given_type
5
5
  assert_equal Behaviors::FakeBehavior, Behavior.generate(:fake_behavior, nil).class
6
6
  end
7
7
 
8
8
  def test_generate_should_raise_on_invalid_type
9
- assert_raise NoSuchBehaviorError do
9
+ assert_raises NoSuchBehaviorError do
10
10
  Behavior.generate(:foo, nil)
11
11
  end
12
12
  end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
- class TestCampfire < Test::Unit::TestCase
3
+ class TestCampfire < Minitest::Test
4
4
  def setup
5
5
  @campfire = God::Contacts::Campfire.new
6
6
  end
@@ -3,7 +3,7 @@ require File.dirname(__FILE__) + '/helper'
3
3
  class BadlyImplementedCondition < PollCondition
4
4
  end
5
5
 
6
- class TestCondition < Test::Unit::TestCase
6
+ class TestCondition < Minitest::Test
7
7
 
8
8
  # generate
9
9
 
@@ -12,7 +12,7 @@ class TestCondition < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def test_generate_should_raise_on_invalid_type
15
- assert_raise NoSuchConditionError do
15
+ assert_raises NoSuchConditionError do
16
16
  Condition.generate(:foo, nil)
17
17
  end
18
18
  end
@@ -45,7 +45,7 @@ class TestCondition < Test::Unit::TestCase
45
45
  def test_test_should_raise_if_not_defined_in_subclass
46
46
  c = BadlyImplementedCondition.new
47
47
 
48
- assert_raise AbstractMethodNotOverriddenError do
48
+ assert_raises AbstractMethodNotOverriddenError do
49
49
  c.test
50
50
  end
51
51
  end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
- class TestConditionsDiskUsage < Test::Unit::TestCase
3
+ class TestConditionsDiskUsage < Minitest::Test
4
4
  # valid?
5
5
 
6
6
  def test_valid_should_return_false_if_no_above_given
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
- class TestHttpResponseCode < Test::Unit::TestCase
3
+ class TestHttpResponseCode < Minitest::Test
4
4
  def valid_condition
5
5
  c = Conditions::HttpResponseCode.new()
6
6
  c.watch = stub(:name => 'foo')
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
- class TestConditionsProcessRunning < Test::Unit::TestCase
3
+ class TestConditionsProcessRunning < Minitest::Test
4
4
  def test_missing_pid_file_returns_opposite
5
5
  [true, false].each do |r|
6
6
  c = Conditions::ProcessRunning.new
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
- class TestConditionsSocketResponding < Test::Unit::TestCase
3
+ class TestConditionsSocketResponding < Minitest::Test
4
4
  # valid?
5
5
 
6
6
  def test_valid_should_return_false_if_no_options_set
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
- class TestConditionsTries < Test::Unit::TestCase
3
+ class TestConditionsTries < Minitest::Test
4
4
  # valid?
5
5
 
6
6
  def test_valid_should_return_false_if_times_not_set
@@ -11,7 +11,7 @@ class TestConditionsTries < Test::Unit::TestCase
11
11
  end
12
12
 
13
13
 
14
- class TestConditionsTries < Test::Unit::TestCase
14
+ class TestConditionsTries < Minitest::Test
15
15
  def setup
16
16
  @c = Conditions::Tries.new
17
17
  @c.times = 3
@@ -42,7 +42,7 @@ class TestConditionsTries < Test::Unit::TestCase
42
42
  end
43
43
 
44
44
 
45
- class TestConditionsTriesWithin < Test::Unit::TestCase
45
+ class TestConditionsTriesWithin < Minitest::Test
46
46
  def setup
47
47
  @c = Conditions::Tries.new
48
48
  @c.times = 3
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
- class TestContact < Test::Unit::TestCase
3
+ class TestContact < Minitest::Test
4
4
  def test_exists
5
5
  God::Contact
6
6
  end
@@ -8,7 +8,7 @@ class TestContact < Test::Unit::TestCase
8
8
  # generate
9
9
 
10
10
  def test_generate_should_raise_on_invalid_kind
11
- assert_raise(NoSuchContactError) do
11
+ assert_raises(NoSuchContactError) do
12
12
  Contact.generate(:invalid)
13
13
  end
14
14
  end
@@ -59,42 +59,42 @@ class TestContact < Test::Unit::TestCase
59
59
 
60
60
  def test_normalize_should_raise_on_non_string_array_hash
61
61
  input = 1
62
- assert_raise ArgumentError do
62
+ assert_raises ArgumentError do
63
63
  Contact.normalize(input)
64
64
  end
65
65
  end
66
66
 
67
67
  def test_normalize_should_raise_on_non_string_array_contacts_key
68
68
  input = {:contacts => 1}
69
- assert_raise ArgumentError do
69
+ assert_raises ArgumentError do
70
70
  Contact.normalize(input)
71
71
  end
72
72
  end
73
73
 
74
74
  def test_normalize_should_raise_on_non_string_containing_array
75
75
  input = [1]
76
- assert_raise ArgumentError do
76
+ assert_raises ArgumentError do
77
77
  Contact.normalize(input)
78
78
  end
79
79
  end
80
80
 
81
81
  def test_normalize_should_raise_on_non_string_containing_array_contacts_key
82
82
  input = {:contacts => [1]}
83
- assert_raise ArgumentError do
83
+ assert_raises ArgumentError do
84
84
  Contact.normalize(input)
85
85
  end
86
86
  end
87
87
 
88
88
  def test_normalize_should_raise_on_absent_contacts_key
89
89
  input = {}
90
- assert_raise ArgumentError do
90
+ assert_raises ArgumentError do
91
91
  Contact.normalize(input)
92
92
  end
93
93
  end
94
94
 
95
95
  def test_normalize_should_raise_on_extra_keys
96
96
  input = {:contacts => ['tom'], :priority => 1, :category => 'product', :extra => 'foo'}
97
- assert_raise ArgumentError do
97
+ assert_raises ArgumentError do
98
98
  Contact.normalize(input)
99
99
  end
100
100
  end
@@ -102,7 +102,7 @@ class TestContact < Test::Unit::TestCase
102
102
  # notify
103
103
 
104
104
  def test_notify_should_be_abstract
105
- assert_raise(AbstractMethodNotOverriddenError) do
105
+ assert_raises(AbstractMethodNotOverriddenError) do
106
106
  Contact.new.notify(:a, :b, :c, :d, :e)
107
107
  end
108
108
  end
@@ -1,14 +1,15 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
- class TestDriver < Test::Unit::TestCase
3
+ class TestDriver < Minitest::Test
4
4
  def setup
5
5
 
6
6
  end
7
7
 
8
8
  def test_push_pop_wait
9
- eq = God::DriverEventQueue.new
10
9
 
11
- MonitorMixin::ConditionVariable.any_instance.expects(:wait).times(1)
10
+ eq = God::DriverEventQueue.new
11
+ cond = eq.instance_variable_get(:@resource)
12
+ cond.expects(:wait).times(1)
12
13
 
13
14
  eq.push(God::TimedEvent.new(0))
14
15
  eq.push(God::TimedEvent.new(0.1))
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
- class TestEmail < Test::Unit::TestCase
3
+ class TestEmail < Minitest::Test
4
4
  def setup
5
5
  God::Contacts::Email.to_email = 'dev@example.com'
6
6
  God::Contacts::Email.from_email = 'god@example.com'
@@ -17,7 +17,7 @@ module God
17
17
  end
18
18
  end
19
19
 
20
- class TestEventHandler < Test::Unit::TestCase
20
+ class TestEventHandler < Minitest::Test
21
21
  def setup
22
22
  @h = God::EventHandler
23
23
  end
@@ -74,7 +74,7 @@ end
74
74
 
75
75
  # This doesn't currently work:
76
76
  #
77
- # class TestEventHandlerOperational < Test::Unit::TestCase
77
+ # class TestEventHandlerOperational < Minitest::Test
78
78
  # def test_operational
79
79
  # God::EventHandler.start
80
80
  # assert God::EventHandler.loaded?
@@ -1,6 +1,5 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
-
3
- class TestGod < Test::Unit::TestCase
2
+ class TestGod < MiniTest::Test
4
3
  def setup
5
4
  God::Socket.stubs(:new).returns(true)
6
5
  God.stubs(:setup).returns(true)
@@ -16,6 +15,10 @@ class TestGod < Test::Unit::TestCase
16
15
  w.driver.thread.kill
17
16
  end
18
17
  end
18
+ God.reset
19
+ #Some of the tests in this file intentionally set pid_file_directory to an invalid value
20
+ #This can cause a later test failure since God will call abort if pid_file_directory is not writable
21
+ God.pid_file_directory = '~/.god/pids'
19
22
  end
20
23
 
21
24
  # applog
@@ -32,11 +35,10 @@ class TestGod < Test::Unit::TestCase
32
35
  assert_equal Hash.new, God.watches
33
36
  end
34
37
 
35
- # init
38
+ # # init
36
39
 
37
40
  def test_pid_file_directory_should_abort_if_called_after_watch
38
41
  God.watch { |w| w.name = 'foo'; w.start = 'bar' }
39
-
40
42
  assert_abort do
41
43
  God.pid_file_directory = 'foo'
42
44
  end
@@ -313,7 +315,7 @@ class TestGod < Test::Unit::TestCase
313
315
  def test_control_should_raise_on_invalid_command
314
316
  God.watch { |w| w.name = 'foo'; w.start = 'bar' }
315
317
 
316
- assert_raise InvalidCommandError do
318
+ assert_raises InvalidCommandError do
317
319
  God.control('foo', 'invalid')
318
320
  end
319
321
  end
@@ -451,7 +453,7 @@ class TestGod < Test::Unit::TestCase
451
453
 
452
454
  def test_running_log_should_raise_on_unknown_watch
453
455
  God.internal_init
454
- assert_raise(NoSuchWatchError) do
456
+ assert_raises(NoSuchWatchError) do
455
457
  God.running_log('foo', Time.now)
456
458
  end
457
459
  end
@@ -662,7 +664,7 @@ class TestGod < Test::Unit::TestCase
662
664
  end
663
665
 
664
666
 
665
- # class TestGodOther < Test::Unit::TestCase
667
+ # class TestGodOther < Minitest::Test
666
668
  # def setup
667
669
  # God::Socket.stubs(:new).returns(true)
668
670
  # God.internal_init
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/helper'
2
2
 
3
3
  if God::EventHandler.event_system == "kqueue"
4
4
 
5
- class TestHandlersKqueueHandler < Test::Unit::TestCase
5
+ class TestHandlersKqueueHandler < Minitest::Test
6
6
  def test_register_process
7
7
  KQueueHandler.expects(:monitor_process).with(1234, 2147483648)
8
8
  KQueueHandler.register_process(1234, [:proc_exit])
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
- class TestHipchat < Test::Unit::TestCase
3
+ class TestHipchat < Minitest::Test
4
4
  def setup
5
5
  @hipchat = God::Contacts::Hipchat.new
6
6
  end
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require File.dirname(__FILE__) + '/helper'
3
3
 
4
- class TestJabber < Test::Unit::TestCase
4
+ class TestJabber < Minitest::Test
5
5
 
6
6
  def setup
7
7
  @jabber = God::Contacts::Jabber.new
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
- class TestLogger < Test::Unit::TestCase
3
+ class TestLogger < Minitest::Test
4
4
  def setup
5
5
  @log = God::Logger.new(StringIO.new('/dev/null'))
6
6
  end
@@ -41,8 +41,8 @@ class TestLogger < Test::Unit::TestCase
41
41
 
42
42
  out = @log.watch_log_since('foo', t2)
43
43
 
44
- assert_no_match(/one/, out)
45
- assert_no_match(/two/, out)
44
+ assert(/one/ !~ out)
45
+ assert(/two/ !~ out)
46
46
  assert_match(/three/, out)
47
47
  end
48
48
 
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
- class TestMetric < Test::Unit::TestCase
3
+ class TestMetric < Minitest::Test
4
4
  def setup
5
5
  @metric = Metric.new(stub(:interval => 10), nil)
6
6
  end
@@ -12,7 +12,7 @@ module God
12
12
  end
13
13
  end
14
14
 
15
- class TestProcessChild < Test::Unit::TestCase
15
+ class TestProcessChild < Minitest::Test
16
16
  def setup
17
17
  God.internal_init
18
18
  @p = God::Process.new
@@ -45,6 +45,9 @@ class TestProcessChild < Test::Unit::TestCase
45
45
  @p.log = '/tmp/foo.log'
46
46
  @p.uid = 'root'
47
47
 
48
+ ::Process.stubs(:groups=)
49
+ ::Process.stubs(:initgroups)
50
+
48
51
  assert @p.valid?
49
52
  end
50
53
 
@@ -142,13 +145,14 @@ end
142
145
  #
143
146
  ###############################################################################
144
147
 
145
- class TestProcessDaemon < Test::Unit::TestCase
148
+ class TestProcessDaemon < Minitest::Test
146
149
  def setup
147
150
  God.internal_init
148
151
  @p = God::Process.new
149
152
  @p.name = 'foo'
150
153
  @p.pid_file = 'blah.pid'
151
154
  @p.stubs(:test).returns true # so we don't try to mkdir_p
155
+ God::System::Process.stubs(:fetch_system_poller).returns(God::System::PortablePoller)
152
156
  Process.stubs(:detach) # because we stub fork
153
157
  end
154
158
 
@@ -243,7 +247,7 @@ class TestProcessDaemon < Test::Unit::TestCase
243
247
 
244
248
  assert @p.valid?
245
249
 
246
- assert_raise NotImplementedError do
250
+ assert_raises NotImplementedError do
247
251
  @p.call_action(:start)
248
252
  end
249
253
  end
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require File.dirname(__FILE__) + '/helper'
3
3
 
4
- class TestProwl < Test::Unit::TestCase
4
+ class TestProwl < Minitest::Test
5
5
  def test_live_notify
6
6
  prowl = God::Contacts::Prowl.new
7
7
  prowl.name = "Prowly"
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/helper'
2
2
 
3
- class TestRegistry < Test::Unit::TestCase
3
+ class TestRegistry < Minitest::Test
4
4
  def setup
5
5
  God.registry.reset
6
6
  end