jstorimer-deep-test 0.2.0 → 1.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 +0 -1
  2. data/README.rdoc +70 -41
  3. data/Rakefile +104 -32
  4. data/TODO +2 -2
  5. data/VERSION +1 -1
  6. data/bin/deep_test +15 -0
  7. data/jstorimer-deep-test-0.1.0.gem +0 -0
  8. data/jstorimer-deep-test.gemspec +1425 -0
  9. data/lib/deep_test.rb +40 -28
  10. data/lib/deep_test/database/mysql_setup_listener.rb +12 -12
  11. data/lib/deep_test/database/setup_listener.rb +23 -23
  12. data/lib/deep_test/distributed/dispatch_controller.rb +10 -17
  13. data/lib/deep_test/distributed/drb_client_connection_info.rb +15 -0
  14. data/lib/deep_test/distributed/master_test_server.rb +52 -0
  15. data/lib/deep_test/distributed/multi_test_server_proxy.rb +44 -0
  16. data/lib/deep_test/distributed/null_work_unit.rb +12 -0
  17. data/lib/deep_test/distributed/remote_worker_client.rb +54 -0
  18. data/lib/deep_test/distributed/remote_worker_server.rb +82 -0
  19. data/lib/deep_test/distributed/rsync.rb +12 -25
  20. data/lib/deep_test/distributed/show_status.rhtml +41 -0
  21. data/lib/deep_test/distributed/test_server.rb +78 -0
  22. data/lib/deep_test/distributed/test_server_status.rb +9 -0
  23. data/lib/deep_test/distributed/test_server_workers.rb +24 -0
  24. data/lib/deep_test/distributed/throughput_runner.rb +42 -0
  25. data/lib/deep_test/distributed/throughput_statistics.rb +26 -0
  26. data/lib/deep_test/distributed/throughput_worker_client.rb +19 -0
  27. data/lib/deep_test/extensions/drb_extension.rb +34 -0
  28. data/lib/deep_test/listener_list.rb +1 -1
  29. data/lib/deep_test/local_workers.rb +55 -0
  30. data/lib/deep_test/logger.rb +2 -17
  31. data/lib/deep_test/marshallable_exception_wrapper.rb +4 -4
  32. data/lib/deep_test/metrics/gatherer.rb +67 -0
  33. data/lib/deep_test/metrics/queue_lock_wait_time_measurement.rb +133 -0
  34. data/lib/deep_test/{null_listener.rb → null_worker_listener.rb} +14 -14
  35. data/lib/deep_test/option.rb +60 -0
  36. data/lib/deep_test/options.rb +42 -45
  37. data/lib/deep_test/process_orchestrator.rb +49 -0
  38. data/lib/deep_test/rake_tasks.rb +1 -3
  39. data/lib/deep_test/result_reader.rb +6 -10
  40. data/lib/deep_test/rspec_detector.rb +1 -1
  41. data/lib/deep_test/server.rb +75 -0
  42. data/lib/deep_test/spec.rb +1 -5
  43. data/lib/deep_test/spec/extensions/example_methods.rb +1 -7
  44. data/lib/deep_test/spec/extensions/reporter.rb +29 -0
  45. data/lib/deep_test/spec/extensions/spec_task.rb +2 -3
  46. data/lib/deep_test/spec/runner.rb +17 -32
  47. data/lib/deep_test/spec/work_result.rb +0 -2
  48. data/lib/deep_test/test/runner.rb +2 -2
  49. data/lib/deep_test/test/supervised_test_suite.rb +10 -9
  50. data/lib/deep_test/test/work_result.rb +0 -1
  51. data/lib/deep_test/test_task.rb +1 -1
  52. data/lib/deep_test/ui/console.rb +11 -9
  53. data/lib/deep_test/warlock.rb +25 -37
  54. data/lib/deep_test/worker.rb +57 -0
  55. data/sample_rails_project/deep_test.rb +0 -4
  56. data/sample_rails_project/lib/{foreign_host_agent_simulation_listener.rb → foreign_host_worker_simulation_listener.rb} +4 -6
  57. data/sample_rails_project/lib/tasks/deep_test.rake +4 -13
  58. data/script/internal/run_test_suite.rb +7 -0
  59. data/script/public/master_test_server.rb +24 -0
  60. data/script/public/test_server.rb +18 -0
  61. data/script/public/test_throughput.rb +29 -0
  62. data/spec/deep_test/option_spec.rb +33 -0
  63. data/spec/deep_test/options_spec.rb +59 -80
  64. data/spec/deep_test/spec/extensions/example_methods_spec.rb +4 -5
  65. data/spec/deep_test/spec/extensions/spec_task_spec.rb +6 -4
  66. data/spec/deep_test/spec/runner_spec.rb +32 -59
  67. data/spec/spec_helper.rb +6 -14
  68. data/spec/thread_worker.rb +25 -0
  69. data/test/deep_test/database/mysql_setup_listener_test.rb +9 -13
  70. data/test/deep_test/distributed/dispatch_controller_test.rb +177 -130
  71. data/test/deep_test/distributed/drb_client_connection_info_test.rb +42 -0
  72. data/test/deep_test/distributed/filename_resolver_test.rb +34 -38
  73. data/test/deep_test/distributed/master_test_server_test.rb +32 -0
  74. data/test/deep_test/distributed/multi_test_server_proxy_test.rb +96 -0
  75. data/test/deep_test/distributed/remote_worker_client_test.rb +180 -0
  76. data/test/deep_test/distributed/remote_worker_server_test.rb +99 -0
  77. data/test/deep_test/distributed/rsync_test.rb +62 -42
  78. data/test/deep_test/distributed/test_server_test.rb +94 -0
  79. data/test/deep_test/distributed/test_server_workers_test.rb +26 -0
  80. data/test/deep_test/distributed/throughput_runner_test.rb +68 -0
  81. data/test/deep_test/distributed/throughput_worker_client_test.rb +28 -0
  82. data/test/deep_test/listener_list_test.rb +15 -17
  83. data/test/deep_test/local_workers_test.rb +22 -0
  84. data/test/deep_test/logger_test.rb +7 -34
  85. data/test/deep_test/marshallable_exception_wrapper_test.rb +29 -31
  86. data/test/deep_test/metrics/gatherer_test.rb +66 -0
  87. data/test/deep_test/process_orchestrator_test.rb +11 -0
  88. data/test/deep_test/result_reader_test.rb +95 -95
  89. data/test/deep_test/server_test.rb +58 -0
  90. data/test/deep_test/test/extensions/error_test.rb +36 -38
  91. data/test/deep_test/test/runner_test.rb +3 -7
  92. data/test/deep_test/test/supervised_test_suite_test.rb +61 -89
  93. data/test/deep_test/test/work_result_test.rb +76 -80
  94. data/test/deep_test/test/work_unit_test.rb +51 -53
  95. data/test/deep_test/test_task_test.rb +38 -10
  96. data/test/deep_test/ui/console_test.rb +4 -8
  97. data/test/deep_test/warlock_test.rb +31 -33
  98. data/test/deep_test/worker_test.rb +94 -0
  99. data/test/failing.rake +11 -0
  100. data/{negative_acceptance_tests/failing_test.rb → test/failing.rb} +1 -3
  101. data/{infrastructure → test}/fake_deadlock_error.rb +0 -0
  102. data/test/simple_test_blackboard.rb +45 -0
  103. data/test/simple_test_blackboard_test.rb +33 -0
  104. data/{infrastructure → test}/test_factory.rb +0 -0
  105. data/test/test_helper.rb +5 -20
  106. data/test/test_task_test.rb +57 -60
  107. metadata +78 -87
  108. data/infrastructure/dynamic_teardown.rb +0 -22
  109. data/infrastructure/load.rb +0 -11
  110. data/infrastructure/test_central_command.rb +0 -15
  111. data/infrastructure/test_exception.rb +0 -7
  112. data/infrastructure/test_logger.rb +0 -11
  113. data/infrastructure/test_operator.rb +0 -15
  114. data/infrastructure/test_result.rb +0 -15
  115. data/infrastructure/thread_agent.rb +0 -21
  116. data/infrastructure/timewarp/Rakefile +0 -14
  117. data/infrastructure/timewarp/lib/timewarp.rb +0 -21
  118. data/infrastructure/timewarp/test/timewarp_test.rb +0 -45
  119. data/lib/deep_test/agent.rb +0 -108
  120. data/lib/deep_test/central_command.rb +0 -165
  121. data/lib/deep_test/cpu_info.rb +0 -22
  122. data/lib/deep_test/demon.rb +0 -25
  123. data/lib/deep_test/distributed/beachhead.rb +0 -104
  124. data/lib/deep_test/distributed/establish_beachhead.rb +0 -19
  125. data/lib/deep_test/distributed/landing_fleet.rb +0 -30
  126. data/lib/deep_test/distributed/landing_ship.rb +0 -60
  127. data/lib/deep_test/distributed/remote_deployment.rb +0 -56
  128. data/lib/deep_test/distributed/shell_environment.rb +0 -50
  129. data/lib/deep_test/distributed/ssh_client_connection_info.rb +0 -14
  130. data/lib/deep_test/failure_message.rb +0 -19
  131. data/lib/deep_test/lib_root.rb +0 -4
  132. data/lib/deep_test/local_deployment.rb +0 -46
  133. data/lib/deep_test/main.rb +0 -41
  134. data/lib/deep_test/metrics/data.rb +0 -34
  135. data/lib/deep_test/metrics/measurement.rb +0 -39
  136. data/lib/deep_test/proxy_io.rb +0 -77
  137. data/lib/deep_test/test/run_test_suite.rb +0 -5
  138. data/lib/telegraph.rb +0 -29
  139. data/lib/telegraph/ack_sequence.rb +0 -14
  140. data/lib/telegraph/logging.rb +0 -20
  141. data/lib/telegraph/message.rb +0 -39
  142. data/lib/telegraph/operator.rb +0 -47
  143. data/lib/telegraph/switchboard.rb +0 -57
  144. data/lib/telegraph/wire.rb +0 -73
  145. data/negative_acceptance_tests/dying_spec.rb +0 -13
  146. data/negative_acceptance_tests/dying_test.rb +0 -13
  147. data/negative_acceptance_tests/failing_spec.rb +0 -9
  148. data/negative_acceptance_tests/kill_agent_one_on_start_work.rb +0 -16
  149. data/negative_acceptance_tests/passing_spec.rb +0 -10
  150. data/negative_acceptance_tests/passing_test.rb +0 -12
  151. data/negative_acceptance_tests/tasks.rake +0 -87
  152. data/negative_acceptance_tests/tests.rb +0 -60
  153. data/test/deep_test/agent_test.rb +0 -175
  154. data/test/deep_test/central_command_test.rb +0 -147
  155. data/test/deep_test/cpu_info_test.rb +0 -33
  156. data/test/deep_test/demon_test.rb +0 -23
  157. data/test/deep_test/distributed/beachhead_test.rb +0 -67
  158. data/test/deep_test/distributed/landing_fleet_test.rb +0 -55
  159. data/test/deep_test/distributed/landing_ship_test.rb +0 -48
  160. data/test/deep_test/distributed/remote_deployment_test.rb +0 -134
  161. data/test/deep_test/distributed/shell_environment_fixtures/set_bar_to_foo +0 -1
  162. data/test/deep_test/distributed/shell_environment_fixtures/set_foo_to_bar +0 -1
  163. data/test/deep_test/distributed/shell_environment_fixtures/set_foo_to_baz +0 -1
  164. data/test/deep_test/distributed/shell_environment_test.rb +0 -108
  165. data/test/deep_test/distributed/ssh_client_connection_info_test.rb +0 -34
  166. data/test/deep_test/local_deployment_test.rb +0 -19
  167. data/test/deep_test/main_test.rb +0 -12
  168. data/test/deep_test/metrics/data_test.rb +0 -22
  169. data/test/deep_test/metrics/measurement_test.rb +0 -18
  170. data/test/deep_test/proxy_io_test.rb +0 -104
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  require 'rubygems'
2
- gem('rspec', ENV['RSPEC_VERSION'] || '1.1.12')
2
+ gem 'rspec', '=1.1.8'
3
3
  require 'spec'
4
4
 
5
- require File.dirname(__FILE__) + '/../lib/deep_test'
6
- require File.dirname(__FILE__) + "/../infrastructure/load"
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"
7
9
 
8
10
  describe "sandboxed rspec_options", :shared => true do
9
11
  attr_reader :options
@@ -15,18 +17,8 @@ describe "sandboxed rspec_options", :shared => true do
15
17
  ::Spec::Runner.use @options
16
18
  end
17
19
 
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
-
28
20
  after(:each) do
29
- DeepTest.logger = @old_logger if @old_logger
21
+ ::Spec::Runner.use @original_rspec_options
30
22
  end
31
23
 
32
24
  class FakeReporter
@@ -0,0 +1,25 @@
1
+ class ThreadWorker
2
+ attr_reader :work_done
3
+
4
+ def initialize(blackboard, expected_work)
5
+ @blackboard, @expected_work = blackboard, expected_work
6
+ @thread = Thread.new {run}
7
+ end
8
+
9
+ def wait_until_done
10
+ Timeout.timeout(5) {@thread.join}
11
+ @thread.kill if @thread.alive?
12
+ end
13
+
14
+ def run
15
+ @work_done = 0
16
+ until @work_done >= @expected_work
17
+ Thread.pass
18
+ work = @blackboard.take_work
19
+ if work
20
+ @blackboard.write_result work.run
21
+ @work_done += 1
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,18 +1,14 @@
1
1
  require File.dirname(__FILE__) + "/../../test_helper"
2
2
 
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
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 /
16
8
  end
9
+ listener.expects(:master_database_config).returns({})
10
+ listener.expects(:dump_file_name).returns("")
11
+ $?.expects(:success?).returns(true)
12
+ listener.dump_schema
17
13
  end
18
14
  end
@@ -1,162 +1,209 @@
1
1
  require File.dirname(__FILE__) + "/../../test_helper"
2
2
 
3
- module DeepTest
4
- module Distributed
5
- unit_tests do
6
- test "dispatch invokes each receiver once" do
7
- receiver_1, receiver_2 = mock, mock
3
+ unit_tests do
4
+ test "dispatch invokes each receiver once" do
5
+ receiver_1, receiver_2 = mock, mock
8
6
 
9
- controller = DispatchController.new(
10
- Options.new({:ui => "UI::Null"}),
11
- [receiver_1, receiver_2]
12
- )
7
+ controller = DeepTest::Distributed::DispatchController.new(
8
+ DeepTest::Options.new({:ui => "DeepTest::UI::Null"}),
9
+ [receiver_1, receiver_2]
10
+ )
13
11
 
14
- receiver_1.expects(:a_method).with(:args)
15
- receiver_2.expects(:a_method).with(:args)
12
+ receiver_1.expects(:a_method).with(:args)
13
+ receiver_2.expects(:a_method).with(:args)
16
14
 
17
- controller.dispatch(:a_method, :args)
18
- end
15
+ controller.dispatch(:a_method, :args)
16
+ end
19
17
 
20
- test "dispatch returns array of all results" do
21
- receiver_1, receiver_2 = mock, mock
18
+ test "dispatch returns array of all results" do
19
+ receiver_1, receiver_2 = mock, mock
22
20
 
23
- controller = DispatchController.new(
24
- Options.new({:ui => "UI::Null"}),
25
- [receiver_1, receiver_2]
26
- )
21
+ controller = DeepTest::Distributed::DispatchController.new(
22
+ DeepTest::Options.new({:ui => "DeepTest::UI::Null"}),
23
+ [receiver_1, receiver_2]
24
+ )
27
25
 
28
- receiver_1.expects(:a_method).returns(:result_1)
29
- receiver_2.expects(:a_method).returns(:result_2)
26
+ receiver_1.expects(:a_method).returns(:result_1)
27
+ receiver_2.expects(:a_method).returns(:result_2)
30
28
 
31
- results = controller.dispatch(:a_method)
32
- assert_equal 2, results.size
33
- assert_equal [:result_1, :result_2].to_set, results.to_set
34
- end
29
+ results = controller.dispatch(:a_method)
30
+ assert_equal 2, results.size
31
+ assert_equal [:result_1, :result_2].to_set, results.to_set
32
+ end
35
33
 
36
- test "dispatch calls all receivers in parallel" do
37
- options = Options.new({:ui => "UI::Null"})
38
- waiter = Waiter.new(tracker = Tracker.new)
34
+ test "dispatch calls all receivers in parallel" do
35
+ options = DeepTest::Options.new({:ui => "DeepTest::UI::Null"})
36
+ waiter = Waiter.new(tracker = Tracker.new)
39
37
 
40
- Timeout.timeout(1) do
41
- DispatchController.new(options,[tracker, waiter]).
42
- dispatch(:tracked_method)
43
- end
38
+ Timeout.timeout(1) do
39
+ DeepTest::Distributed::DispatchController.new(options,[tracker, waiter]).
40
+ dispatch(:tracked_method)
41
+ end
44
42
 
45
- waiter = Waiter.new(tracker = Tracker.new)
43
+ waiter = Waiter.new(tracker = Tracker.new)
46
44
 
47
- Timeout.timeout(1) do
48
- DispatchController.new(options,[waiter, tracker]).
49
- dispatch(:tracked_method)
50
- end
51
- end
45
+ Timeout.timeout(1) do
46
+ DeepTest::Distributed::DispatchController.new(options,[waiter, tracker]).
47
+ dispatch(:tracked_method)
48
+ end
49
+ end
52
50
 
53
- test "receiver is dropped when any exception occurs" do
54
- receiver = mock
55
- receiver.expects(:method_call).raises(Exception)
51
+ test "dispatch omits results that are taking too long" do
52
+ receiver = Object.new
53
+ def receiver.__drburi; ""; end
54
+ def receiver.sleep_100_millis
55
+ sleep 0.1
56
+ end
56
57
 
57
- controller = DispatchController.new(
58
- Options.new({:ui => "UI::Null"}),
59
- [receiver]
60
- )
58
+ controller = DeepTest::Distributed::DispatchController.new(
59
+ DeepTest::Options.new({:ui => "DeepTest::UI::Null", :timeout_in_seconds => 0.05}),
60
+ [receiver]
61
+ )
61
62
 
62
- controller.dispatch(:method_call)
63
- assert_raises(NoDispatchReceiversError) {controller.dispatch(:another_call)}
64
- end
63
+ DeepTest.logger.expects(:error)
65
64
 
66
- test "error is printed with backtrace when it occurrs" do
67
- e = Exception.new("message")
68
- e.set_backtrace %w[file1:1 file2:2]
69
- receiver = mock
70
- receiver.expects(:method_call).raises(e)
71
-
72
- controller = DispatchController.new(
73
- Options.new({:ui => "UI::Null"}),
74
- [receiver]
75
- )
76
-
77
- Timewarp.freeze("2009-09-22 12:01:33") do
78
- controller.dispatch(:method_call)
79
- assert_equal <<-end_log, DeepTest.logger.logged_output
80
- [DeepTest@#{Socket.gethostname}] 2009-09-22 12:01:33 Exception while dispatching method_call to #{receiver.inspect}:
81
- [DeepTest@#{Socket.gethostname}] 2009-09-22 12:01:33 Exception: message
82
- [DeepTest@#{Socket.gethostname}] 2009-09-22 12:01:33 file1:1
83
- [DeepTest@#{Socket.gethostname}] 2009-09-22 12:01:33 file2:2
84
- end_log
85
- end
86
- end
65
+ assert_equal [], controller.dispatch(:sleep_100_millis)
66
+ end
87
67
 
88
- test "dispatch calls notifies ui of start and stop of dispatch" do
89
- options = Options.new({:ui => "UI::Null"})
90
- controller = DispatchController.new(
91
- options, [stub_everything]
92
- )
68
+ test "after timeout, no further calls are sent to that receiver" do
69
+ receiver_1, receiver_2 = mock(:__drburi => ""), mock
70
+ receiver_1.expects(:method_call_1).raises(Timeout::Error.new("message"))
71
+ receiver_1.expects(:method_call_2).never
93
72
 
94
- options.ui_instance.expects(:dispatch_starting).with(:method_name)
95
- options.ui_instance.expects(:dispatch_finished).with(:method_name)
96
-
97
- controller.dispatch(:method_name)
98
- end
73
+ receiver_2.expects(:method_call_1)
74
+ receiver_2.expects(:method_call_2)
99
75
 
100
- test "dispatch calls notifies ui dispatch end in case of an error" do
101
- options = Options.new({:ui => "UI::Null"})
102
- controller = DispatchController.new(
103
- options, [receiver = mock]
104
- )
105
- receiver.expects(:method_name).raises("An Error")
106
-
107
- options.ui_instance.expects(:dispatch_starting).with(:method_name)
108
- options.ui_instance.expects(:dispatch_finished).with(:method_name)
109
-
110
- begin
111
- controller.dispatch(:method_name)
112
- rescue RuntimeError => e
113
- raise unless e.message == "An Error"
114
- end
115
- end
76
+ controller = DeepTest::Distributed::DispatchController.new(
77
+ DeepTest::Options.new({:ui => "DeepTest::UI::Null", :timeout_in_seconds => 0.05}),
78
+ [receiver_1, receiver_2]
79
+ )
116
80
 
117
- test "error is raised if dispatch to no receivers in attempted" do
118
- options = Options.new({:ui => "UI::Null"})
119
- controller = DispatchController.new(
120
- options, []
121
- )
81
+ DeepTest.logger.expects(:error)
82
+
83
+ controller.dispatch(:method_call_1)
84
+ controller.dispatch(:method_call_2)
85
+ end
122
86
 
123
- assert_raises(NoDispatchReceiversError) do
124
- controller.dispatch(:any_method)
125
- end
126
- end
87
+ test "receiver is dropped when connection is refused" do
88
+ receiver_1, receiver_2 = mock(:__drburi => ""), mock
89
+ receiver_1.expects(:method_call_1).raises(DRb::DRbConnError)
90
+ receiver_1.expects(:method_call_2).never
127
91
 
128
- class Tracker
129
- def initialize
130
- @mutex = Mutex.new
131
- @condvar = ConditionVariable.new
132
- end
92
+ receiver_2.expects(:method_call_1).returns(:value)
93
+ receiver_2.expects(:method_call_2)
133
94
 
134
- def tracked_method
135
- @mutex.synchronize do
136
- @tracked_method_called = true
137
- @condvar.broadcast
138
- end
139
- end
95
+ controller = DeepTest::Distributed::DispatchController.new(
96
+ DeepTest::Options.new({:ui => "DeepTest::UI::Null", :timeout_in_seconds => 0.05}),
97
+ [receiver_1, receiver_2]
98
+ )
140
99
 
141
- def wait_for_tracked_method
142
- @mutex.synchronize do
143
- loop do
144
- return if @tracked_method_called
145
- @condvar.wait(@mutex)
146
- end
147
- end
148
- end
149
- end
100
+ DeepTest.logger.expects(:error)
101
+
102
+ assert_equal [:value], controller.dispatch(:method_call_1)
150
103
 
151
- class Waiter
152
- def initialize(tracker)
153
- @tracker = tracker
154
- end
104
+ controller.dispatch(:method_call_2)
105
+ end
106
+
107
+ test "receiver is dropped when any exception occurs" do
108
+ receiver = mock(:__drburi => "")
109
+ receiver.expects(:method_call).raises(Exception)
110
+
111
+ controller = DeepTest::Distributed::DispatchController.new(
112
+ DeepTest::Options.new({:ui => "DeepTest::UI::Null", :timeout_in_seconds => 0.05}),
113
+ [receiver]
114
+ )
115
+
116
+ DeepTest.logger.expects(:error)
117
+
118
+ controller.dispatch(:method_call)
119
+ assert_raises(DeepTest::Distributed::NoDispatchReceiversError) {controller.dispatch(:another_call)}
120
+ end
121
+
122
+ test "no error is printed if dispatching without error" do
123
+ receiver_1 = mock
124
+ receiver_1.expects(:method_call_1).raises(DRb::DRbConnError)
125
+
126
+ controller = DeepTest::Distributed::DispatchController.new(
127
+ DeepTest::Options.new({:ui => "DeepTest::UI::Null", :timeout_in_seconds => 0.05}),
128
+ [receiver_1]
129
+ )
130
+
131
+ DeepTest.logger.expects(:error).never
132
+
133
+ controller.dispatch_with_options(:method_call_1, :ignore_connection_error => true)
134
+ end
135
+
136
+ test "dispatch calls notifies ui of start and stop of dispatch" do
137
+ options = DeepTest::Options.new({:ui => "DeepTest::UI::Null"})
138
+ controller = DeepTest::Distributed::DispatchController.new(
139
+ options, [stub_everything]
140
+ )
141
+
142
+ options.ui_instance.expects(:dispatch_starting).with(:method_name)
143
+ options.ui_instance.expects(:dispatch_finished).with(:method_name)
144
+
145
+ controller.dispatch(:method_name)
146
+ end
147
+
148
+ test "dispatch calls notifies ui dispatch end in case of an error" do
149
+ options = DeepTest::Options.new({:ui => "DeepTest::UI::Null"})
150
+ controller = DeepTest::Distributed::DispatchController.new(
151
+ options, [receiver = mock(:__drburi => '')]
152
+ )
153
+ receiver.expects(:method_name).raises("An Error")
154
+ DeepTest.logger.expects(:error)
155
+
156
+ options.ui_instance.expects(:dispatch_starting).with(:method_name)
157
+ options.ui_instance.expects(:dispatch_finished).with(:method_name)
158
+
159
+ begin
160
+ controller.dispatch(:method_name)
161
+ rescue RuntimeError => e
162
+ raise unless e.message == "An Error"
163
+ end
164
+ end
165
+
166
+ test "error is raised if dispatch to no receivers in attempted" do
167
+ options = DeepTest::Options.new({:ui => "DeepTest::UI::Null"})
168
+ controller = DeepTest::Distributed::DispatchController.new(
169
+ options, []
170
+ )
155
171
 
156
- def tracked_method
157
- @tracker.wait_for_tracked_method
172
+ assert_raises(DeepTest::Distributed::NoDispatchReceiversError) do
173
+ controller.dispatch(:any_method)
174
+ end
175
+ end
176
+
177
+ class Tracker
178
+ def initialize
179
+ @mutex = Mutex.new
180
+ @condvar = ConditionVariable.new
181
+ end
182
+
183
+ def tracked_method
184
+ @mutex.synchronize do
185
+ @tracked_method_called = true
186
+ @condvar.broadcast
187
+ end
188
+ end
189
+
190
+ def wait_for_tracked_method
191
+ @mutex.synchronize do
192
+ loop do
193
+ return if @tracked_method_called
194
+ @condvar.wait(@mutex)
158
195
  end
159
196
  end
160
197
  end
161
198
  end
199
+
200
+ class Waiter
201
+ def initialize(tracker)
202
+ @tracker = tracker
203
+ end
204
+
205
+ def tracked_method
206
+ @tracker.wait_for_tracked_method
207
+ end
208
+ end
162
209
  end
@@ -0,0 +1,42 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ unit_tests do
4
+ test "returns ipaddress from peeraddr as address" do
5
+ info = Thread.current['DRb']
6
+ begin
7
+ Thread.current['DRb'] = {
8
+ 'client' => mock(:peeraddr => [nil, nil, nil, "ip"])
9
+ }
10
+
11
+ info = DeepTest::Distributed::DRbClientConnectionInfo.new
12
+ ensure
13
+ Thread.current['DRb'] = info
14
+ end
15
+
16
+ assert_equal "ip", info.address
17
+ end
18
+
19
+ test "raises an error if no drb client is found" do
20
+ info = Thread.current['DRb']
21
+ begin
22
+ Thread.current['DRb'] = {}
23
+ assert_raises(RuntimeError) do
24
+ DeepTest::Distributed::DRbClientConnectionInfo.new
25
+ end
26
+ ensure
27
+ Thread.current['DRb'] = info
28
+ end
29
+ end
30
+
31
+ test "raises an error if no drb info is found" do
32
+ info = Thread.current['DRb']
33
+ begin
34
+ Thread.current['DRb'] = nil
35
+ assert_raises(RuntimeError) do
36
+ DeepTest::Distributed::DRbClientConnectionInfo.new
37
+ end
38
+ ensure
39
+ Thread.current['DRb'] = info
40
+ end
41
+ end
42
+ end