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
@@ -1,7 +1,8 @@
1
1
  require "socket"
2
+ require "base64"
2
3
 
3
- require File.dirname(__FILE__) + "/option"
4
4
  require File.dirname(__FILE__) + "/options"
5
+ require File.dirname(__FILE__) + "/cpu_info"
5
6
  require File.dirname(__FILE__) + "/test_task"
6
7
  require File.dirname(__FILE__) + "/rspec_detector"
7
8
 
@@ -9,3 +10,4 @@ DeepTest::RSpecDetector.if_rspec_available do
9
10
  require 'spec/rake/spectask'
10
11
  require File.dirname(__FILE__) + "/spec/extensions/spec_task"
11
12
  end
13
+
@@ -1,7 +1,7 @@
1
1
  module DeepTest
2
2
  class ResultReader
3
- def initialize(blackboard)
4
- @blackboard = blackboard
3
+ def initialize(central_command)
4
+ @central_command = central_command
5
5
  end
6
6
 
7
7
  def read(original_work_units_by_id)
@@ -11,10 +11,10 @@ module DeepTest
11
11
  begin
12
12
  until errors == work_units_by_id.size
13
13
  Thread.pass
14
- result = @blackboard.take_result
14
+ result = @central_command.take_result
15
15
  next if result.nil?
16
16
 
17
- if Worker::Error === result
17
+ if Agent::Error === result
18
18
  puts result
19
19
  errors += 1
20
20
  else
@@ -26,8 +26,12 @@ module DeepTest
26
26
  yield [work_unit, result]
27
27
  end
28
28
  end
29
- rescue Server::ResultOverdueError
30
- DeepTest.logger.error("Results are overdue from server, ending run")
29
+ rescue CentralCommand::NoAgentsRunningError
30
+ FailureMessage.show "DeepTest Agents Are Not Running", <<-end_msg
31
+ DeepTest's test running agents have not contacted the
32
+ server to indicate they are still running.
33
+ Shutting down the test run on the assumption that they have died.
34
+ end_msg
31
35
  end
32
36
 
33
37
  work_units_by_id
@@ -5,7 +5,7 @@ module DeepTest
5
5
  require 'spec/version'
6
6
  if ::Spec::VERSION::MAJOR == 1 &&
7
7
  ::Spec::VERSION::MINOR == 1 &&
8
- ::Spec::VERSION::TINY == 8
8
+ ::Spec::VERSION::TINY >= 8
9
9
  yield
10
10
  else
11
11
  require 'spec/rake/spectask'
@@ -1,5 +1,10 @@
1
1
  require 'rubygems'
2
2
  require 'spec/runner/example_group_runner'
3
+ if ::Spec::VERSION::MAJOR == 1 &&
4
+ ::Spec::VERSION::MINOR == 1 &&
5
+ ::Spec::VERSION::TINY >= 12
6
+ require 'spec/example/before_and_after_hooks'
7
+ end
3
8
  require 'spec/example/example_group_methods'
4
9
  require 'spec/rake/spectask'
5
10
 
@@ -7,7 +12,6 @@ require File.dirname(__FILE__) + "/spec/extensions/example_group_methods"
7
12
  require File.dirname(__FILE__) + "/spec/extensions/example_methods"
8
13
  require File.dirname(__FILE__) + "/spec/extensions/spec_task"
9
14
  require File.dirname(__FILE__) + "/spec/extensions/options"
10
- require File.dirname(__FILE__) + "/spec/extensions/reporter"
11
15
  require File.dirname(__FILE__) + "/spec/runner"
12
16
  require File.dirname(__FILE__) + "/spec/work_unit"
13
17
  require File.dirname(__FILE__) + "/spec/work_result"
@@ -2,7 +2,13 @@ module Spec
2
2
  module Example
3
3
  module ExampleMethods
4
4
  def identifier
5
- file, line = implementation_backtrace.first.split(/:/)
5
+ if ::Spec::VERSION::MAJOR == 1 &&
6
+ ::Spec::VERSION::MINOR == 1 &&
7
+ ::Spec::VERSION::TINY >= 12
8
+ file, line = eval("caller", @_implementation).first.split(/:/)
9
+ else
10
+ file, line = implementation_backtrace.first.split(/:/)
11
+ end
6
12
  Identifier.new(file, line.to_i, self.class.description, description)
7
13
  end
8
14
 
@@ -1,10 +1,11 @@
1
+ require File.dirname(__FILE__) + "/../../lib_root"
2
+
1
3
  module Spec
2
4
  module Rake
3
5
  class SpecTask
4
6
  def deep_test(options)
5
7
  deep_test_options = DeepTest::Options.new(options)
6
- deep_test_path = File.expand_path(File.dirname(__FILE__) +
7
- "/../../../deep_test")
8
+ deep_test_path = File.expand_path(DeepTest::LIB_ROOT + "/deep_test")
8
9
  @deep_test_spec_opts = [
9
10
  "--require #{deep_test_path}",
10
11
  "--runner 'DeepTest::Spec::Runner:#{deep_test_options.to_command_line}'"
@@ -1,51 +1,66 @@
1
1
  module DeepTest
2
2
  module Spec
3
3
  class Runner < ::Spec::Runner::ExampleGroupRunner
4
- def initialize(options, deep_test_options, blackboard = nil)
4
+ def initialize(options, deep_test_options)
5
5
  super(options)
6
+ if ::Spec::VERSION::MAJOR == 1 &&
7
+ ::Spec::VERSION::MINOR == 1 &&
8
+ ::Spec::VERSION::TINY >= 12
9
+ @runner_options = options # added to make work with 1.1.12
10
+ end
6
11
  @deep_test_options = DeepTest::Options.from_command_line(deep_test_options)
7
- DeepTest.init(@deep_test_options)
8
- @blackboard = blackboard
9
- @workers = @deep_test_options.new_workers
10
12
  end
11
13
 
12
- def blackboard
13
- # Can't create blackboard as default argument to initialize
14
- # because ProcessOrchestrator hasn't been invoked at
14
+ def main
15
+ @main ||= Main.new @deep_test_options, @deep_test_options.new_deployment, self
16
+ end
17
+
18
+ def central_command
19
+ # Can't create central_command as default argument to initialize
20
+ # because Main hasn't been invoked at
15
21
  # instantiation time
16
- @blackboard ||= @deep_test_options.server
22
+ @central_command ||= main.central_command
17
23
  end
18
24
 
19
25
  def load_files(files)
20
- @workers.load_files files
26
+ main.load_files files
21
27
  end
22
28
 
23
29
  def run
24
- ProcessOrchestrator.run(@deep_test_options, @workers, self)
30
+ main.run
25
31
  end
26
32
 
27
- def process_work_units
33
+ def process_work_units(central_command)
28
34
  prepare
29
35
 
30
- examples = example_groups.map {|g| g.send(:examples_to_run)}.flatten
36
+ examples = (example_groups.map do |g|
37
+ if ::Spec::VERSION::MAJOR == 1 &&
38
+ ::Spec::VERSION::MINOR == 1 &&
39
+ ::Spec::VERSION::TINY >= 12
40
+ g.send(:examples_to_run, @runner_options) # added @runner_options to make wiork with 1.1.12
41
+ else
42
+ g.send(:examples_to_run)
43
+ end
44
+ end).flatten
31
45
  examples_by_location = {}
32
46
  examples.each do |example|
33
47
  raise "duplicate example: #{example.identifier}" if examples_by_location[example.identifier]
34
48
  examples_by_location[example.identifier] = example
35
- blackboard.write_work Spec::WorkUnit.new(example.identifier)
49
+ central_command.write_work Spec::WorkUnit.new(example.identifier)
36
50
  end
37
51
 
38
52
  success = true
39
53
 
40
- missing_exmaples = ResultReader.new(blackboard).read(examples_by_location) do |example, result|
54
+ missing_examples = ResultReader.new(central_command).read(examples_by_location) do |example, result|
41
55
  @options.reporter.example_finished(example, result.error)
42
56
  success &= result.success?
43
57
  end
44
58
 
45
- success &= missing_exmaples.empty?
59
+ success &= missing_examples.empty?
46
60
 
47
- missing_exmaples.each do |identifier, example|
48
- @options.reporter.example_finished(example, WorkUnitNeverReceivedError.new)
61
+ if missing_examples.any?
62
+ @options.reporter.example_finished(examples_by_location[missing_examples.keys.first],
63
+ IncompleteTestRunError.new(missing_examples.size))
49
64
  end
50
65
 
51
66
  success
@@ -1,6 +1,8 @@
1
1
  module DeepTest
2
2
  module Spec
3
3
  class WorkResult
4
+ include CentralCommand::Result
5
+
4
6
  attr_reader :identifier, :output
5
7
 
6
8
  def initialize(identifier, error, output)
@@ -0,0 +1,5 @@
1
+ require File.dirname(__FILE__) + "/../../deep_test"
2
+ options = DeepTest::Options.from_command_line(ARGV[0])
3
+ main = DeepTest::Main.new options, options.new_deployment, DeepTest::Test::Runner.new(options)
4
+ main.load_files Dir.glob(options.pattern)
5
+ main.run
@@ -12,9 +12,9 @@ module DeepTest
12
12
  @options = options
13
13
  end
14
14
 
15
- def process_work_units
15
+ def process_work_units(central_command)
16
16
  suite = ::Test::Unit::AutoRunner::COLLECTORS[:objectspace].call NO_FILTERS
17
- supervised_suite = DeepTest::Test::SupervisedTestSuite.new(suite, @options.server)
17
+ supervised_suite = DeepTest::Test::SupervisedTestSuite.new(suite, central_command)
18
18
  require 'test/unit/ui/console/testrunner'
19
19
  result = ::Test::Unit::UI::Console::TestRunner.run(supervised_suite, ::Test::Unit::UI::NORMAL)
20
20
  result.passed?
@@ -1,9 +1,9 @@
1
1
  module DeepTest
2
2
  module Test
3
3
  class SupervisedTestSuite
4
- def initialize(suite, blackboard)
4
+ def initialize(suite, central_command)
5
5
  @suite = suite
6
- @blackboard = blackboard
6
+ @central_command = central_command
7
7
  end
8
8
 
9
9
  def run(result, &progress_block)
@@ -25,24 +25,23 @@ module DeepTest
25
25
  end
26
26
  else
27
27
  tests_by_name[test_suite.name] = test_suite
28
- @blackboard.write_work Test::WorkUnit.new(test_suite)
28
+ @central_command.write_work Test::WorkUnit.new(test_suite)
29
29
  end
30
30
  end
31
31
 
32
32
  def read_results(result, tests_by_name)
33
- DeepTest.logger.debug("SupervisedTestSuite: going to read #{tests_by_name.size} results")
34
-
35
- missing_tests =
36
- ResultReader.new(@blackboard).read(tests_by_name) do |test, remote_result|
33
+ DeepTest.logger.debug { "SupervisedTestSuite: going to read #{tests_by_name.size} results" }
34
+ missing_tests =
35
+ ResultReader.new(@central_command).read(tests_by_name) do |test, remote_result|
37
36
  remote_result.add_to result
38
37
  yield ::Test::Unit::TestCase::FINISHED, test.name if block_given?
39
38
  end
40
39
 
41
- missing_tests.each do |name, test_case|
42
- result.add_error ::Test::Unit::Error.new(name, WorkUnitNeverReceivedError.new)
40
+ if missing_tests.any?
41
+ result.add_error ::Test::Unit::Error.new("DeepTest Test Run", IncompleteTestRunError.new(missing_tests.size))
43
42
  end
44
43
  ensure
45
- DeepTest.logger.debug("SupervisedTestSuite: exiting with #{missing_tests.size} results left")
44
+ DeepTest.logger.debug { "SupervisedTestSuite: exiting with #{missing_tests.size} results left" }
46
45
  end
47
46
  end
48
47
  end
@@ -1,6 +1,7 @@
1
1
  module DeepTest
2
2
  module Test
3
3
  class WorkResult < ::Test::Unit::TestResult
4
+ include CentralCommand::Result
4
5
  attr_reader :identifier
5
6
  attr_accessor :output
6
7
 
@@ -41,7 +41,7 @@ module DeepTest
41
41
  private
42
42
 
43
43
  def runner
44
- File.expand_path(File.dirname(__FILE__) + "/../../script/internal/run_test_suite.rb")
44
+ File.expand_path(File.dirname(__FILE__) + "/test/run_test_suite.rb")
45
45
  end
46
46
  end
47
47
  end
@@ -5,20 +5,18 @@ module DeepTest
5
5
  end
6
6
 
7
7
  METHOD_DESCRIPTIONS = {
8
- :sync => "Synchronizing working copies on worker machines",
9
- :spawn_worker_server => "Spawning test environment processes",
10
- :load_files => "Loading test files for workers",
11
- :start_all => "Starting workers",
12
- :stop_all => "Stopping workers"
8
+ :push_code => "Synchronizing working copies on distributed machines",
9
+ :establish_beachhead => "Spawning test environment processes",
10
+ :load_files => "Loading test files for agents",
11
+ :deploy_agents => "Deploying agents",
13
12
  } unless defined?(METHOD_DESCRIPTIONS)
14
13
 
15
14
  def distributed_failover_to_local(method, exception)
16
- width = 70
17
- puts " Distributed DeepTest Failure ".center(width, '*')
18
- puts "* Failed during #{method}".ljust(width - 1) + "*"
19
- puts "* #{exception.message}".ljust(width - 1) + "*"
20
- puts "* Failing over to local run".ljust(width - 1) + "*"
21
- puts "*" * width
15
+ FailureMessage.show "Distributed DeepTest Failure", <<-end_msg
16
+ Failed during #{method}
17
+ #{exception.message}
18
+ Failing over to local run
19
+ end_msg
22
20
  end
23
21
 
24
22
  def dispatch_starting(method_name)
@@ -1,20 +1,21 @@
1
1
  module DeepTest
2
2
  class Warlock
3
- def initialize
3
+ def initialize(options)
4
+ @options = options
4
5
  @demons_semaphore = Mutex.new
5
6
  @demons = []
6
7
  @reapers = []
7
8
  end
8
9
 
9
- def start(name, &block)
10
+ def start(name, demon, *demon_args)
10
11
  # Not synchronizing for the fork seems to cause
11
12
  # random errors (Bus Error, Segfault, and GC non-object)
12
- # in RemoteWorkerServer processes.
13
+ # in Beachhead processes.
13
14
  #
14
15
  begin
15
16
  pid = nil
16
17
  @demons_semaphore.synchronize do
17
- pid = DeepTest.drb_safe_fork do
18
+ pid = fork do
18
19
  # Fork leaves the semaphore locked and we'll never make it
19
20
  # to end of synchronize block.
20
21
  #
@@ -24,12 +25,8 @@ module DeepTest
24
25
  #
25
26
  @demons_semaphore.unlock if @demons_semaphore.locked?
26
27
 
27
- begin
28
- yield
29
- rescue Exception => e
30
- DeepTest.logger.debug "Exception in #{name} (#{Process.pid}): #{e.message}"
31
- raise
32
- end
28
+ close_open_network_connections
29
+ demon.forked name, @options, demon_args
33
30
 
34
31
  exit
35
32
  end
@@ -46,14 +43,23 @@ module DeepTest
46
43
  end
47
44
  end
48
45
 
46
+ def close_open_network_connections
47
+ ObjectSpace.each_object(BasicSocket) do |sock|
48
+ begin
49
+ sock.close
50
+ rescue IOError
51
+ end
52
+ end
53
+ end
54
+
49
55
  def demon_count
50
56
  @demons_semaphore.synchronize do
51
57
  @demons.size
52
58
  end
53
59
  end
54
60
 
55
- def stop_all
56
- DeepTest.logger.debug("stopping all demons")
61
+ def stop_demons
62
+ DeepTest.logger.debug { "stopping all demons" }
57
63
  receivers = @demons_semaphore.synchronize do
58
64
  @demons.reverse
59
65
  end
@@ -61,25 +67,31 @@ module DeepTest
61
67
  receivers.reverse.each do |demon|
62
68
  name, pid = demon
63
69
  if running?(pid)
64
- DeepTest.logger.debug("Sending SIGTERM to #{name}, #{pid}")
70
+ DeepTest.logger.debug { "Sending SIGTERM to #{name}, #{pid}" }
65
71
  Process.kill("TERM", pid)
66
72
  end
67
73
  end
68
- DeepTest.logger.debug("Warlock: Stopped all receivers")
74
+ DeepTest.logger.debug { "Warlock: Stopped all receivers" }
69
75
 
70
- DeepTest.logger.debug("waiting for reapers")
76
+ DeepTest.logger.debug { "waiting for reapers" }
71
77
  @reapers.each {|r| r.join}
72
78
 
73
- DeepTest.logger.debug("Warlock: done reaping processes")
79
+ DeepTest.logger.debug { "Warlock: done reaping processes" }
74
80
  end
75
81
 
76
82
  def exit_when_none_running
77
83
  Thread.new do
78
- loop do
79
- Thread.pass
80
- exit(0) unless any_running?
81
- sleep(0.01)
82
- end
84
+ wait_for_all_to_finish
85
+ DeepTest.logger.debug { "exiting #{Process.pid} with all demons finished" }
86
+ exit(0)
87
+ end
88
+ end
89
+
90
+ def wait_for_all_to_finish
91
+ loop do
92
+ Thread.pass
93
+ return unless any_running?
94
+ sleep(0.01)
83
95
  end
84
96
  end
85
97
 
@@ -110,22 +122,22 @@ module DeepTest
110
122
  protected
111
123
 
112
124
  def add_demon(name, pid)
113
- DeepTest.logger.debug "Started: #{name} (#{pid})"
125
+ DeepTest.logger.debug { "Started: #{name} (#{pid})" }
114
126
  @demons << [name, pid]
115
127
  end
116
128
 
117
129
  def remove_demon(name, pid)
118
130
  @demons.delete [name, pid]
119
- DeepTest.logger.debug "Stopped: #{name} (#{pid})"
131
+ DeepTest.logger.debug { "Stopped: #{name} (#{pid})" }
120
132
  end
121
133
 
122
134
 
123
135
  def launch_reaper_thread(name, pid)
124
136
  @reapers << Thread.new do
125
137
  Process.detach(pid).join
126
- DeepTest.logger.debug("#{name} (#{pid}) reaped")
138
+ DeepTest.logger.debug { "#{name} (#{pid}) reaped" }
127
139
  @demons_semaphore.synchronize do
128
- DeepTest.logger.debug("Warlock Reaper: removing #{name} (#{pid}) from demon list")
140
+ DeepTest.logger.debug { "Warlock Reaper: removing #{name} (#{pid}) from demon list" }
129
141
  remove_demon name, pid
130
142
  end
131
143
  end