jstorimer-deep-test 1.4.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (170) hide show
  1. data/.gitignore +1 -0
  2. data/README.rdoc +41 -70
  3. data/Rakefile +47 -119
  4. data/TODO +2 -2
  5. data/VERSION +1 -1
  6. data/infrastructure/dynamic_teardown.rb +22 -0
  7. data/{test → infrastructure}/fake_deadlock_error.rb +0 -0
  8. data/infrastructure/load.rb +11 -0
  9. data/infrastructure/test_central_command.rb +15 -0
  10. data/infrastructure/test_exception.rb +7 -0
  11. data/{test → infrastructure}/test_factory.rb +0 -0
  12. data/infrastructure/test_logger.rb +11 -0
  13. data/infrastructure/test_operator.rb +15 -0
  14. data/infrastructure/test_result.rb +15 -0
  15. data/infrastructure/thread_agent.rb +21 -0
  16. data/infrastructure/timewarp/Rakefile +14 -0
  17. data/infrastructure/timewarp/lib/timewarp.rb +21 -0
  18. data/infrastructure/timewarp/test/timewarp_test.rb +45 -0
  19. data/lib/deep_test.rb +28 -40
  20. data/lib/deep_test/agent.rb +108 -0
  21. data/lib/deep_test/central_command.rb +165 -0
  22. data/lib/deep_test/cpu_info.rb +22 -0
  23. data/lib/deep_test/database/mysql_setup_listener.rb +11 -12
  24. data/lib/deep_test/database/setup_listener.rb +23 -23
  25. data/lib/deep_test/demon.rb +25 -0
  26. data/lib/deep_test/distributed/beachhead.rb +104 -0
  27. data/lib/deep_test/distributed/dispatch_controller.rb +17 -10
  28. data/lib/deep_test/distributed/establish_beachhead.rb +19 -0
  29. data/lib/deep_test/distributed/landing_fleet.rb +30 -0
  30. data/lib/deep_test/distributed/landing_ship.rb +60 -0
  31. data/lib/deep_test/distributed/remote_deployment.rb +56 -0
  32. data/lib/deep_test/distributed/rsync.rb +25 -12
  33. data/lib/deep_test/distributed/shell_environment.rb +50 -0
  34. data/lib/deep_test/distributed/ssh_client_connection_info.rb +14 -0
  35. data/lib/deep_test/failure_message.rb +19 -0
  36. data/lib/deep_test/lib_root.rb +4 -0
  37. data/lib/deep_test/listener_list.rb +1 -1
  38. data/lib/deep_test/local_deployment.rb +46 -0
  39. data/lib/deep_test/logger.rb +17 -2
  40. data/lib/deep_test/main.rb +41 -0
  41. data/lib/deep_test/marshallable_exception_wrapper.rb +4 -4
  42. data/lib/deep_test/metrics/data.rb +34 -0
  43. data/lib/deep_test/metrics/measurement.rb +39 -0
  44. data/lib/deep_test/{null_worker_listener.rb → null_listener.rb} +14 -14
  45. data/lib/deep_test/options.rb +41 -56
  46. data/lib/deep_test/proxy_io.rb +77 -0
  47. data/lib/deep_test/rake_tasks.rb +3 -1
  48. data/lib/deep_test/result_reader.rb +10 -6
  49. data/lib/deep_test/rspec_detector.rb +1 -1
  50. data/lib/deep_test/spec.rb +5 -1
  51. data/lib/deep_test/spec/extensions/example_methods.rb +7 -1
  52. data/lib/deep_test/spec/extensions/spec_task.rb +3 -2
  53. data/lib/deep_test/spec/runner.rb +32 -17
  54. data/lib/deep_test/spec/work_result.rb +2 -0
  55. data/lib/deep_test/test/run_test_suite.rb +5 -0
  56. data/lib/deep_test/test/runner.rb +2 -2
  57. data/lib/deep_test/test/supervised_test_suite.rb +9 -10
  58. data/lib/deep_test/test/work_result.rb +1 -0
  59. data/lib/deep_test/test_task.rb +1 -1
  60. data/lib/deep_test/ui/console.rb +9 -11
  61. data/lib/deep_test/warlock.rb +37 -25
  62. data/lib/telegraph.rb +29 -0
  63. data/lib/telegraph/ack_sequence.rb +14 -0
  64. data/lib/telegraph/logging.rb +20 -0
  65. data/lib/telegraph/message.rb +39 -0
  66. data/lib/telegraph/operator.rb +47 -0
  67. data/lib/telegraph/switchboard.rb +57 -0
  68. data/lib/telegraph/wire.rb +73 -0
  69. data/negative_acceptance_tests/dying_spec.rb +13 -0
  70. data/negative_acceptance_tests/dying_test.rb +13 -0
  71. data/negative_acceptance_tests/failing_spec.rb +9 -0
  72. data/{test/failing.rb → negative_acceptance_tests/failing_test.rb} +3 -1
  73. data/negative_acceptance_tests/kill_agent_one_on_start_work.rb +16 -0
  74. data/negative_acceptance_tests/passing_spec.rb +10 -0
  75. data/negative_acceptance_tests/passing_test.rb +12 -0
  76. data/negative_acceptance_tests/tasks.rake +87 -0
  77. data/negative_acceptance_tests/tests.rb +60 -0
  78. data/sample_rails_project/deep_test.rb +4 -0
  79. data/sample_rails_project/lib/{foreign_host_worker_simulation_listener.rb → foreign_host_agent_simulation_listener.rb} +6 -4
  80. data/sample_rails_project/lib/tasks/deep_test.rake +13 -4
  81. data/spec/deep_test/options_spec.rb +80 -59
  82. data/spec/deep_test/spec/extensions/example_methods_spec.rb +5 -4
  83. data/spec/deep_test/spec/extensions/spec_task_spec.rb +4 -6
  84. data/spec/deep_test/spec/runner_spec.rb +59 -32
  85. data/spec/spec_helper.rb +14 -6
  86. data/test/deep_test/agent_test.rb +175 -0
  87. data/test/deep_test/central_command_test.rb +147 -0
  88. data/test/deep_test/cpu_info_test.rb +33 -0
  89. data/test/deep_test/database/mysql_setup_listener_test.rb +13 -9
  90. data/test/deep_test/demon_test.rb +23 -0
  91. data/test/deep_test/distributed/beachhead_test.rb +67 -0
  92. data/test/deep_test/distributed/dispatch_controller_test.rb +130 -177
  93. data/test/deep_test/distributed/filename_resolver_test.rb +38 -34
  94. data/test/deep_test/distributed/landing_fleet_test.rb +55 -0
  95. data/test/deep_test/distributed/landing_ship_test.rb +48 -0
  96. data/test/deep_test/distributed/remote_deployment_test.rb +134 -0
  97. data/test/deep_test/distributed/rsync_test.rb +42 -62
  98. data/test/deep_test/distributed/shell_environment_fixtures/set_bar_to_foo +1 -0
  99. data/test/deep_test/distributed/shell_environment_fixtures/set_foo_to_bar +1 -0
  100. data/test/deep_test/distributed/shell_environment_fixtures/set_foo_to_baz +1 -0
  101. data/test/deep_test/distributed/shell_environment_test.rb +108 -0
  102. data/test/deep_test/distributed/ssh_client_connection_info_test.rb +34 -0
  103. data/test/deep_test/listener_list_test.rb +17 -15
  104. data/test/deep_test/local_deployment_test.rb +19 -0
  105. data/test/deep_test/logger_test.rb +34 -7
  106. data/test/deep_test/main_test.rb +12 -0
  107. data/test/deep_test/marshallable_exception_wrapper_test.rb +31 -29
  108. data/test/deep_test/metrics/data_test.rb +22 -0
  109. data/test/deep_test/metrics/measurement_test.rb +18 -0
  110. data/test/deep_test/proxy_io_test.rb +104 -0
  111. data/test/deep_test/result_reader_test.rb +95 -95
  112. data/test/deep_test/test/extensions/error_test.rb +38 -36
  113. data/test/deep_test/test/runner_test.rb +7 -3
  114. data/test/deep_test/test/supervised_test_suite_test.rb +89 -61
  115. data/test/deep_test/test/work_result_test.rb +80 -76
  116. data/test/deep_test/test/work_unit_test.rb +53 -51
  117. data/test/deep_test/test_task_test.rb +10 -38
  118. data/test/deep_test/ui/console_test.rb +8 -4
  119. data/test/deep_test/warlock_test.rb +33 -31
  120. data/test/test_helper.rb +20 -5
  121. data/test/test_task_test.rb +60 -57
  122. metadata +94 -84
  123. data/bin/deep_test +0 -15
  124. data/jstorimer-deep-test-0.1.0.gem +0 -0
  125. data/jstorimer-deep-test.gemspec +0 -1425
  126. data/lib/deep_test/distributed/drb_client_connection_info.rb +0 -15
  127. data/lib/deep_test/distributed/master_test_server.rb +0 -52
  128. data/lib/deep_test/distributed/multi_test_server_proxy.rb +0 -44
  129. data/lib/deep_test/distributed/null_work_unit.rb +0 -12
  130. data/lib/deep_test/distributed/remote_worker_client.rb +0 -54
  131. data/lib/deep_test/distributed/remote_worker_server.rb +0 -82
  132. data/lib/deep_test/distributed/show_status.rhtml +0 -41
  133. data/lib/deep_test/distributed/test_server.rb +0 -78
  134. data/lib/deep_test/distributed/test_server_status.rb +0 -9
  135. data/lib/deep_test/distributed/test_server_workers.rb +0 -24
  136. data/lib/deep_test/distributed/throughput_runner.rb +0 -42
  137. data/lib/deep_test/distributed/throughput_statistics.rb +0 -26
  138. data/lib/deep_test/distributed/throughput_worker_client.rb +0 -19
  139. data/lib/deep_test/extensions/drb_extension.rb +0 -34
  140. data/lib/deep_test/local_workers.rb +0 -55
  141. data/lib/deep_test/metrics/gatherer.rb +0 -67
  142. data/lib/deep_test/metrics/queue_lock_wait_time_measurement.rb +0 -133
  143. data/lib/deep_test/option.rb +0 -60
  144. data/lib/deep_test/process_orchestrator.rb +0 -49
  145. data/lib/deep_test/server.rb +0 -75
  146. data/lib/deep_test/spec/extensions/reporter.rb +0 -29
  147. data/lib/deep_test/worker.rb +0 -57
  148. data/script/internal/run_test_suite.rb +0 -7
  149. data/script/public/master_test_server.rb +0 -24
  150. data/script/public/test_server.rb +0 -18
  151. data/script/public/test_throughput.rb +0 -29
  152. data/spec/deep_test/option_spec.rb +0 -33
  153. data/spec/thread_worker.rb +0 -25
  154. data/test/deep_test/distributed/drb_client_connection_info_test.rb +0 -42
  155. data/test/deep_test/distributed/master_test_server_test.rb +0 -32
  156. data/test/deep_test/distributed/multi_test_server_proxy_test.rb +0 -96
  157. data/test/deep_test/distributed/remote_worker_client_test.rb +0 -180
  158. data/test/deep_test/distributed/remote_worker_server_test.rb +0 -99
  159. data/test/deep_test/distributed/test_server_test.rb +0 -94
  160. data/test/deep_test/distributed/test_server_workers_test.rb +0 -26
  161. data/test/deep_test/distributed/throughput_runner_test.rb +0 -68
  162. data/test/deep_test/distributed/throughput_worker_client_test.rb +0 -28
  163. data/test/deep_test/local_workers_test.rb +0 -22
  164. data/test/deep_test/metrics/gatherer_test.rb +0 -66
  165. data/test/deep_test/process_orchestrator_test.rb +0 -11
  166. data/test/deep_test/server_test.rb +0 -58
  167. data/test/deep_test/worker_test.rb +0 -94
  168. data/test/failing.rake +0 -11
  169. data/test/simple_test_blackboard.rb +0 -45
  170. data/test/simple_test_blackboard_test.rb +0 -33
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,9 @@
1
1
  require 'rubygems'
2
- gem 'rspec', '=1.1.8'
2
+ gem('rspec', ENV['RSPEC_VERSION'] || '1.1.12')
3
3
  require 'spec'
4
4
 
5
- require File.dirname(__FILE__) + "/../lib/deep_test"
6
- require File.dirname(__FILE__) + "/../test/fake_deadlock_error"
7
- require File.dirname(__FILE__) + "/../test/simple_test_blackboard"
8
- require File.dirname(__FILE__) + "/thread_worker"
5
+ require File.dirname(__FILE__) + '/../lib/deep_test'
6
+ require File.dirname(__FILE__) + "/../infrastructure/load"
9
7
 
10
8
  describe "sandboxed rspec_options", :shared => true do
11
9
  attr_reader :options
@@ -17,8 +15,18 @@ describe "sandboxed rspec_options", :shared => true do
17
15
  ::Spec::Runner.use @options
18
16
  end
19
17
 
18
+ after(:each) { ::Spec::Runner.use @original_rspec_options }
19
+
20
+ before(:each) { DynamicTeardown.setup }
21
+ after(:each) { DynamicTeardown.teardown }
22
+
23
+ before(:each) do
24
+ @old_logger = DeepTest.logger
25
+ DeepTest.logger = TestLogger.new
26
+ end
27
+
20
28
  after(:each) do
21
- ::Spec::Runner.use @original_rspec_options
29
+ DeepTest.logger = @old_logger if @old_logger
22
30
  end
23
31
 
24
32
  class FakeReporter
@@ -0,0 +1,175 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ module DeepTest
4
+ unit_tests do
5
+ test "puts result on central_command with acknowledgement of work" do
6
+ options = Options.new({})
7
+ central_command = TestCentralCommand.start options
8
+ central_command.write_work Test::WorkUnit.new(TestFactory.passing_test)
9
+ central_command.done_with_work
10
+
11
+ Agent.new(0, options, stub_everything).execute(StringIO.new, StringIO.new)
12
+
13
+ assert_equal [], central_command.switchboard.live_wires.first.unacked_messages
14
+ assert_kind_of ::Test::Unit::TestResult, central_command.take_result
15
+ end
16
+
17
+ test "puts passing and failing tests on central_command for each test" do
18
+ options = Options.new({})
19
+ central_command = TestCentralCommand.start options
20
+ central_command.write_work Test::WorkUnit.new(TestFactory.passing_test)
21
+ central_command.write_work Test::WorkUnit.new(TestFactory.failing_test)
22
+ central_command.done_with_work
23
+
24
+ Agent.new(0, options, stub_everything).execute(StringIO.new, StringIO.new)
25
+
26
+ result_1 = central_command.take_result
27
+ result_2 = central_command.take_result
28
+
29
+ assert_equal true, (result_1.passed? || result_2.passed?)
30
+ assert_equal false, (result_1.passed? && result_2.passed?)
31
+ end
32
+
33
+ test "notifies listener that it is starting" do
34
+ options = Options.new({})
35
+ central_command = TestCentralCommand.start options
36
+ central_command.done_with_work
37
+ listener = stub_everything
38
+ agent = Agent.new(0, options, listener)
39
+ listener.expects(:starting).with(agent)
40
+ agent.execute(StringIO.new, StringIO.new)
41
+ end
42
+
43
+ test "notifies listener that it is about to do work" do
44
+ options = Options.new({})
45
+ central_command = TestCentralCommand.start options
46
+ work_unit = Test::WorkUnit.new(TestFactory.passing_test)
47
+ central_command.write_work work_unit
48
+ central_command.done_with_work
49
+ listener = stub_everything
50
+ agent = Agent.new(0, options, listener)
51
+ listener.expects(:starting_work).with(agent, work_unit)
52
+ agent.execute(StringIO.new, StringIO.new)
53
+ end
54
+
55
+ test "notifies listener that it has done work" do
56
+ options = Options.new({})
57
+ central_command = TestCentralCommand.start(options)
58
+ work_unit = ResultWorkUnit.new(:result)
59
+ central_command.write_work work_unit
60
+ central_command.done_with_work
61
+ listener = stub_everything
62
+ agent = Agent.new(0, options, listener)
63
+ listener.expects(:finished_work).with(agent, work_unit, TestResult.new(:result))
64
+ agent.execute(StringIO.new, StringIO.new)
65
+ end
66
+
67
+ test "connect indicates it has connected" do
68
+ options = Options.new({})
69
+ central_command = TestCentralCommand.start(options)
70
+ agent = Agent.new(0, options, stub_everything)
71
+ yielded = false
72
+ agent.connect(io = StringIO.new) do
73
+ yielded = true
74
+ assert_equal "Connected\n", io.string
75
+ assert_equal true, io.closed?
76
+ end
77
+ assert yielded, "connect didn't yield"
78
+ end
79
+
80
+ test "connect closes stream even if there is an error" do
81
+ options = Options.new({})
82
+ agent = Agent.new(0, options, stub_everything)
83
+ io = StringIO.new
84
+ assert_raises(Errno::EADDRNOTAVAIL) { agent.connect io }
85
+ assert_equal true, io.closed?
86
+ end
87
+
88
+ class ResultWorkUnit
89
+ attr_reader :result
90
+
91
+ def initialize(result)
92
+ @result = result
93
+ end
94
+
95
+ def run
96
+ TestResult.new(result)
97
+ end
98
+
99
+ def ==(other)
100
+ other.class == self.class && other.result == result
101
+ end
102
+ end
103
+
104
+ class ErrorWorkUnit
105
+ attr_reader :exception
106
+
107
+ def initialize(exception)
108
+ @exception = exception
109
+ end
110
+
111
+ def run
112
+ raise @exception
113
+ end
114
+
115
+ def ==(other)
116
+ other.class == self.class && other.exception == exception
117
+ end
118
+ end
119
+
120
+ test "exception raised by work unit gives in Agent::Error" do
121
+ options = Options.new({})
122
+ central_command = TestCentralCommand.start options
123
+ work_unit = ErrorWorkUnit.new(exception = TestException.new)
124
+ central_command.write_work work_unit
125
+ central_command.done_with_work
126
+
127
+ Agent.new(0, options, stub_everything).execute(StringIO.new, StringIO.new)
128
+
129
+ assert_equal Agent::Error.new(work_unit, exception), central_command.take_result
130
+ end
131
+
132
+ test "Agent::Error can marshal itself even if the contents are not marshallable" do
133
+ o = Object.new
134
+ def o._dump; raise "error"; end
135
+
136
+ error = Agent::Error.new o, Exception.new("my error")
137
+ error_through_marshalling = Marshal.load Marshal.dump(error)
138
+ assert_equal Exception, error_through_marshalling.error.class
139
+ assert_equal "my error", error_through_marshalling.error.message
140
+ assert_equal "<< Undumpable >>", error_through_marshalling.work_unit
141
+ end
142
+
143
+ test "requests work until it finds some" do
144
+ options = Options.new({})
145
+ central_command = TestCentralCommand.start(options)
146
+
147
+ t = Thread.new { Agent.new(0, options, stub_everything).execute(StringIO.new, StringIO.new) }
148
+ Thread.pass
149
+ central_command.write_work stub(:run => TestResult.new(:result))
150
+ central_command.done_with_work
151
+ t.join
152
+ assert_equal TestResult.new(:result), central_command.take_result
153
+ end
154
+
155
+ test "finish running if a connection error is received" do
156
+ options = Options.new({})
157
+ central_command = TestCentralCommand.start(options)
158
+ begin
159
+ t = Thread.new { Agent.new(0, options, stub_everything).execute(StringIO.new, StringIO.new) }
160
+ sleep 0.1
161
+ ensure
162
+ central_command.stop
163
+ end
164
+ t.join
165
+ end
166
+
167
+ test "number is available to indentify agent" do
168
+ assert_equal 1, Agent.new(1, Options.new({}), nil).number
169
+ end
170
+
171
+ test "does not fork from rake" do
172
+ assert !defined?($rakefile)
173
+ end
174
+ end
175
+ end
@@ -0,0 +1,147 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ module DeepTest
4
+ unit_tests do
5
+ test "take_work returns result of push_work when it is available" do
6
+ central_command = CentralCommand.new Options.new({})
7
+ central_command.write_work :work
8
+ assert_equal :work, central_command.take_work
9
+ end
10
+
11
+ test "take_work raises error when no work is currently available" do
12
+ assert_raises(CentralCommand::NoWorkUnitsAvailableError) do
13
+ CentralCommand.new(Options.new({})).take_work
14
+ end
15
+ end
16
+
17
+ test "take_work raises error when there is no work left to" do
18
+ central_command = CentralCommand.new Options.new({})
19
+ central_command.done_with_work
20
+
21
+ assert_raises(CentralCommand::NoWorkUnitsRemainingError) do
22
+ central_command.take_work
23
+ end
24
+ end
25
+
26
+ test "take_result raises NoAgentsRunningError if agents are connected" do
27
+ central_command = CentralCommand.start Options.new({})
28
+ DynamicTeardown.on_teardown { central_command.stop }
29
+ assert_raises(CentralCommand::NoAgentsRunningError) {central_command.take_result}
30
+ end
31
+
32
+ test "start returns instance of central_command" do
33
+ central_command = CentralCommand.start Options.new({})
34
+ DynamicTeardown.on_teardown { central_command.stop }
35
+ assert_kind_of CentralCommand, central_command
36
+ end
37
+
38
+ test "after starting CentralCommand responds to NeedWork messages by supplying new units of work" do
39
+ central_command = CentralCommand.start(options = Options.new({}))
40
+ DynamicTeardown.on_teardown { central_command.stop }
41
+ central_command.write_work(:a)
42
+ central_command.write_work(:b)
43
+ central_command.write_work(:c)
44
+
45
+ wire = Telegraph::Wire.connect("localhost", options.server_port)
46
+ [:a, :b, :c].each do |work_unit|
47
+ Thread.pass
48
+ wire.send_message CentralCommand::NeedWork
49
+ assert_equal work_unit, wire.next_message(:timeout => 2.0).body
50
+ end
51
+ end
52
+
53
+ test "after starting CentralCommand responds to Result messages adding results to the queue" do
54
+ central_command = CentralCommand.start(options = Options.new({}))
55
+ DynamicTeardown.on_teardown { central_command.stop }
56
+ wire = Telegraph::Wire.connect("localhost", options.server_port)
57
+ result_1, result_2, result_3 = TestResult.new(1), TestResult.new(2), TestResult.new(3)
58
+
59
+ [result_1, result_2, result_3].each do |result|
60
+ wire.send_message result
61
+ end
62
+
63
+ assert_equal result_1, central_command.take_result
64
+ assert_equal result_2, central_command.take_result
65
+ assert_equal result_3, central_command.take_result
66
+ end
67
+
68
+ test "after starting CentralCommand responds to Result by supplying a new unit of work" do
69
+ central_command = CentralCommand.start(options = Options.new({}))
70
+ DynamicTeardown.on_teardown { central_command.stop }
71
+ central_command.write_work(:a)
72
+ central_command.write_work(:b)
73
+ central_command.write_work(:c)
74
+
75
+ wire = Telegraph::Wire.connect("localhost", options.server_port)
76
+ result_1, result_2, result_3 = TestResult.new(1), TestResult.new(2), TestResult.new(3)
77
+ [[result_1, :a], [result_2, :b], [result_3, :c]].each do |result, work_unit|
78
+ Thread.pass
79
+ wire.send_message result_1
80
+ assert_equal work_unit, wire.next_message(:timeout => 2.0).body
81
+ end
82
+ end
83
+
84
+ test "will add results to queue with a worker waiting for work that is not available" do
85
+ central_command = CentralCommand.start(options = Options.new({}))
86
+ DynamicTeardown.on_teardown { central_command.stop }
87
+
88
+ Telegraph::Wire.connect("localhost", options.server_port) do |wire|
89
+ wire.send_message CentralCommand::NeedWork
90
+ wire.send_message TestResult.new(1)
91
+ end
92
+
93
+ assert_equal TestResult.new(1), central_command.take_result
94
+ end
95
+
96
+ test "will distribute work units that have not received results from dead workers when other work runs out" do
97
+ central_command = CentralCommand.start(options = Options.new({}))
98
+ DynamicTeardown.on_teardown { central_command.stop }
99
+
100
+ central_command.write_work(:a)
101
+
102
+ Telegraph::Wire.connect("localhost", options.server_port) do |wire|
103
+ wire.send_message CentralCommand::NeedWork
104
+ assert_equal :a, wire.next_message(:timeout => 1).body
105
+ end
106
+
107
+ Telegraph::Wire.connect("localhost", options.server_port) do |wire|
108
+ wire.send_message CentralCommand::NeedWork
109
+ assert_equal :a, wire.next_message(:timeout => 1).body
110
+ end
111
+ end
112
+
113
+ test "will add measurements to data when received over the wire" do
114
+ central_command = CentralCommand.start(options = Options.new({}))
115
+ DynamicTeardown.on_teardown { central_command.stop }
116
+
117
+ Telegraph::Wire.connect("localhost", options.server_port) do |wire|
118
+ wire.send_message Metrics::Measurement.new("category", 1, "units")
119
+ end
120
+
121
+ sleep 0.05
122
+
123
+ assert_match /category: 1.0 avg/, central_command.data.summary
124
+ end
125
+
126
+ class SetCalledGlobalToTrue
127
+ include CentralCommand::Operation
128
+ def execute; $called = true; end
129
+ end
130
+
131
+ test "will execute Operations read from the wire" do
132
+ $called = false
133
+ DynamicTeardown.on_teardown { $called = nil }
134
+ central_command = CentralCommand.start(options = Options.new({}))
135
+ DynamicTeardown.on_teardown { central_command.stop }
136
+ wire = Telegraph::Wire.connect("localhost", options.server_port)
137
+ wire.send_message SetCalledGlobalToTrue.new
138
+
139
+ Timeout.timeout(2) do
140
+ loop do
141
+ break if $called
142
+ sleep 0.25
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,33 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ module DeepTest
4
+ unit_tests do
5
+ test "count parses sysctl output on darwin" do
6
+ cpu_info = CpuInfo.new("foodarwinbar")
7
+ cpu_info.expects(:`).with("sysctl -n hw.ncpu").returns("2\n")
8
+ assert_equal 2, cpu_info.count
9
+ end
10
+
11
+ test "count parses /proc/cpuinfo on linux" do
12
+ cpu_info = CpuInfo.new("foolinuxbar")
13
+ File.expects(:readlines).with("/proc/cpuinfo").returns [
14
+ "processor : 0",
15
+ "vendor_id : GenuineIntel",
16
+ "cpu family : 6",
17
+ "",
18
+ "processor : 1",
19
+ "vendor_id : GenuineIntel",
20
+ "cpu family : 6",
21
+ ]
22
+ assert_equal 2, cpu_info.count
23
+ end
24
+
25
+ test "count returns nil on other platforms" do
26
+ assert_equal nil, CpuInfo.new("foobar").count
27
+ end
28
+
29
+ test "platform defaults to the current ruby_platform" do
30
+ assert_equal RUBY_PLATFORM, CpuInfo.new.platform
31
+ end
32
+ end
33
+ end
@@ -1,14 +1,18 @@
1
1
  require File.dirname(__FILE__) + "/../../test_helper"
2
2
 
3
- unit_tests do
4
- test "dump_schema includes procedures" do
5
- listener = DeepTest::Database::MysqlSetupListener.new
6
- listener.expects(:system).with do |command|
7
- command =~ / -R /
3
+ module DeepTest
4
+ module Database
5
+ unit_tests do
6
+ test "dump_schema includes procedures" do
7
+ listener = MysqlSetupListener.new
8
+ listener.expects(:system).with do |command|
9
+ command =~ / -R /
10
+ end
11
+ listener.expects(:master_database_config).returns({})
12
+ listener.expects(:dump_file_name).returns("")
13
+ $?.expects(:success?).returns(true)
14
+ listener.dump_schema
15
+ end
8
16
  end
9
- listener.expects(:master_database_config).returns({})
10
- listener.expects(:dump_file_name).returns("")
11
- $?.expects(:success?).returns(true)
12
- listener.dump_schema
13
17
  end
14
18
  end
@@ -0,0 +1,23 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ module DeepTest
4
+ unit_tests do
5
+ class ProcDemon
6
+ include Demon
7
+ def initialize(block); @block = block; end
8
+ def execute; @block.call; end
9
+ end
10
+
11
+ test "forked redirects output back to central command" do
12
+ options = Options.new({})
13
+ operator = TestOperator.listen(options)
14
+ ProcDemon.new(proc do
15
+ puts "hello stdout"
16
+ end).forked("name", options, [])
17
+
18
+ assert_equal ProxyIO::Stdout::Output.new("hello stdout"), operator.next_message[0].body
19
+ assert_equal ProxyIO::Stdout::Output.new("\n"), operator.next_message[0].body
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,67 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ module DeepTest
4
+ module Distributed
5
+ unit_tests do
6
+ test "load_files loads each file in list, resolving each filename with resolver" do
7
+ FilenameResolver.expects(:new).with("/mirror/dir").returns(resolver = mock)
8
+
9
+ beachhead = Beachhead.new "/mirror/dir", Options.new({})
10
+
11
+ resolver.expects(:resolve).with("/source/path/my/file.rb").returns("/mirror/dir/my/file.rb")
12
+ beachhead.expects(:load).with("/mirror/dir/my/file.rb")
13
+ Dir.expects(:chdir).with("/mirror/dir")
14
+
15
+ beachhead.load_files(["/source/path/my/file.rb"])
16
+ end
17
+
18
+ test "service is removed after grace period if agents have not been started" do
19
+ options = Options.new({:number_of_agents => 0})
20
+ TestCentralCommand.start options
21
+ begin
22
+ beachhead = Beachhead.new "", options
23
+ beachhead.daemonize(0.25)
24
+ # Have to sleep long enough to warlock to reap dead process
25
+ sleep 2.0
26
+ assert_equal 0, beachhead.warlock.demon_count
27
+ ensure
28
+ beachhead.warlock.stop_demons
29
+ end
30
+ end
31
+
32
+ test "service is not removed after grace period if agents have been started" do
33
+ options = Options.new({:number_of_agents => 0})
34
+ TestCentralCommand.start options
35
+ begin
36
+ beachhead = Beachhead.new "", options
37
+ # Since we're not actually starting agents, we don't want to exit when none are running for this test
38
+ beachhead.warlock.stubs(:exit_when_none_running)
39
+ port = beachhead.daemonize(0.25)
40
+ Telegraph::Wire.connect("localhost", port).send_message Beachhead::DeployAgents
41
+ # Have to sleep long enough to warlock to reap dead process
42
+ sleep 1.0
43
+ assert_equal 1, beachhead.warlock.demon_count
44
+ ensure
45
+ beachhead.warlock.stop_demons
46
+ end
47
+ end
48
+
49
+ test "responds with Done after receiving LoadFiles and DeployAgents" do
50
+ options = Options.new({:number_of_agents => 0})
51
+ TestCentralCommand.start options
52
+ begin
53
+ beachhead = Beachhead.new File.dirname(__FILE__), options
54
+ # Since we're not actually starting agents, we don't want to exit when none are running for this test
55
+ beachhead.warlock.stubs(:exit_when_none_running)
56
+ port = beachhead.daemonize(0.25)
57
+ wire = Telegraph::Wire.connect("localhost", port)
58
+ wire.send_message Beachhead::LoadFiles.new([])
59
+ wire.send_message Beachhead::DeployAgents
60
+ assert_equal Beachhead::Done, wire.next_message(:timeout => 1).body
61
+ ensure
62
+ beachhead.warlock.stop_demons
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end