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,20 +1,22 @@
1
1
  require File.dirname(__FILE__) + "/../test_helper"
2
2
 
3
- unit_tests do
4
- test "forwards methods defined in NullWorkerListener to all listeners" do
5
- listener_1, listener_2 = mock, mock
6
- list = DeepTest::ListenerList.new([listener_1, listener_2])
7
- listener_1.expects(:starting).with(:worker)
8
- listener_2.expects(:starting).with(:worker)
9
- listener_1.expects(:starting_work).with(:worker, :work)
10
- listener_2.expects(:starting_work).with(:worker, :work)
11
- list.starting(:worker)
12
- list.starting_work(:worker, :work)
13
- end
3
+ module DeepTest
4
+ unit_tests do
5
+ test "forwards methods defined in NullListener to all listeners" do
6
+ listener_1, listener_2 = mock, mock
7
+ list = ListenerList.new([listener_1, listener_2])
8
+ listener_1.expects(:starting).with(:agent)
9
+ listener_2.expects(:starting).with(:agent)
10
+ listener_1.expects(:starting_work).with(:agent, :work)
11
+ listener_2.expects(:starting_work).with(:agent, :work)
12
+ list.starting(:agent)
13
+ list.starting_work(:agent, :work)
14
+ end
14
15
 
15
- test "doesn't forward methods not defined in NullWorkerListener" do
16
- listener = mock
17
- listener.expects(:to_s).never
18
- DeepTest::ListenerList.new([listener]).to_s
16
+ test "doesn't forward methods not defined in NullListener" do
17
+ listener = mock
18
+ listener.expects(:to_s).never
19
+ ListenerList.new([listener]).to_s
20
+ end
19
21
  end
20
22
  end
@@ -0,0 +1,19 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ module DeepTest
4
+ unit_tests do
5
+ test "number_of_agents is determined by options" do
6
+ deployment = LocalDeployment.new Options.new(:number_of_agents => 4)
7
+ assert_equal 4, deployment.number_of_agents
8
+ end
9
+
10
+ test "load_files simply loads each file provided" do
11
+ deployment = LocalDeployment.new Options.new({})
12
+
13
+ deployment.expects(:load).with(:file_1)
14
+ deployment.expects(:load).with(:file_2)
15
+
16
+ deployment.load_files([:file_1, :file_2])
17
+ end
18
+ end
19
+ end
@@ -1,11 +1,38 @@
1
1
  require File.dirname(__FILE__) + "/../test_helper"
2
2
 
3
- unit_tests do
4
- test "info log level by default" do
5
- assert_equal Logger::INFO, DeepTest.logger.level
6
- end
7
-
8
- test "formatter uses msg only" do
9
- assert_equal "[DeepTest] my_msg\n", DeepTest.logger.formatter.call(nil, nil, nil, "my_msg")
3
+ module DeepTest
4
+ unit_tests do
5
+ test "info log level by default" do
6
+ assert_equal Logger::INFO, DeepTest.logger.level
7
+ end
8
+
9
+ test "formatter uses msg only" do
10
+ time = Time.parse("2009-09-22 12:01:33")
11
+ assert_equal "[DeepTest@#{Socket.gethostname}] 2009-09-22 12:01:33 my_msg\n", DeepTest.logger.formatter.call(nil, time, nil, "my_msg")
12
+ end
13
+
14
+ Logger::Severity.constants.each do |severity|
15
+ test "#{severity.downcase} can not be called with any arguments" do
16
+ logger = Logger.new stub_everything
17
+ assert_raises(ArgumentError) { logger.send severity.downcase, "a" }
18
+ end
19
+
20
+ THE_DATE = '\d{4}-\d\d-\d\d \d\d:\d\d:\d\d' unless defined?(THE_DATE)
21
+
22
+ test "#{severity.downcase} can be called with a block" do
23
+ logger = Logger.new(out = StringIO.new)
24
+ logger.level = Logger.const_get(severity)
25
+ logger.send(severity.downcase) { "a" }
26
+ assert_match /\[DeepTest@#{Socket.gethostname}\] #{THE_DATE} a\n/, out.string
27
+ end
28
+
29
+ test "#{severity.downcase} rescues errors from block and logs them" do
30
+ logger = Logger.new(out = StringIO.new)
31
+ logger.level = Logger.const_get(severity)
32
+ logger.send(severity.downcase) { raise Exception, "e" }
33
+ assert_match /\[DeepTest@#{Socket.gethostname}\] #{THE_DATE} Exception: e occurred logging on #{__FILE__}:#{__LINE__ - 1}:in `send'\n/,
34
+ out.string
35
+ end
36
+ end
10
37
  end
11
38
  end
@@ -0,0 +1,12 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ module DeepTest
4
+ unit_tests do
5
+ test "shutdown calls done_with_work" do
6
+ main = Main.new(nil, stub_everything, nil, central_command = mock)
7
+ central_command.expects(:done_with_work)
8
+
9
+ main.shutdown
10
+ end
11
+ end
12
+ end
@@ -1,44 +1,46 @@
1
1
  require File.dirname(__FILE__) + "/../test_helper"
2
2
 
3
- unit_tests do
4
- test "loading a marshallable exception evals the classname and returns an instance of the original exception" do
5
- original = RuntimeError.new "message"
6
- original.set_backtrace ['1', '2']
3
+ module DeepTest
4
+ unit_tests do
5
+ test "loading a marshallable exception evals the classname and returns an instance of the original exception" do
6
+ original = RuntimeError.new "message"
7
+ original.set_backtrace ['1', '2']
7
8
 
8
- marshalled = DeepTest::MarshallableExceptionWrapper.new(original)
9
- DeepTest::MarshallableExceptionWrapper.any_instance.expects(:eval).
10
- with("::RuntimeError").returns(RuntimeError)
9
+ marshalled = MarshallableExceptionWrapper.new(original)
10
+ MarshallableExceptionWrapper.any_instance.expects(:eval).
11
+ with("::RuntimeError").returns(RuntimeError)
11
12
 
12
- loaded = Marshal.load(Marshal.dump(marshalled)).resolve
13
+ loaded = Marshal.load(Marshal.dump(marshalled)).resolve
13
14
 
14
- assert_equal original.class, loaded.class
15
- assert_equal original.message, loaded.message
16
- assert_equal original.backtrace, loaded.backtrace
17
- end
15
+ assert_equal original.class, loaded.class
16
+ assert_equal original.message, loaded.message
17
+ assert_equal original.backtrace, loaded.backtrace
18
+ end
18
19
 
19
- test "loading a marshallable exception when class is not available returns an instance of unloadable exception" do
20
- original = RuntimeError.new "message"
21
- original.set_backtrace ['1', '2']
20
+ test "loading a marshallable exception when class is not available returns an instance of unloadable exception" do
21
+ original = RuntimeError.new "message"
22
+ original.set_backtrace ['1', '2']
22
23
 
23
- marshalled = DeepTest::MarshallableExceptionWrapper.new(original)
24
- DeepTest::MarshallableExceptionWrapper.any_instance.expects(:eval).
25
- raises("Eval Error")
24
+ marshalled = MarshallableExceptionWrapper.new(original)
25
+ MarshallableExceptionWrapper.any_instance.expects(:eval).
26
+ raises("Eval Error")
26
27
 
27
- loaded = Marshal.load(Marshal.dump(marshalled)).resolve
28
+ loaded = Marshal.load(Marshal.dump(marshalled)).resolve
28
29
 
29
- assert_equal DeepTest::UnloadableException, loaded.class
30
- assert_equal "RuntimeError: " + original.message, loaded.message
31
- assert_equal original.backtrace, loaded.backtrace
32
- end
30
+ assert_equal UnloadableException, loaded.class
31
+ assert_equal "RuntimeError: " + original.message, loaded.message
32
+ assert_equal original.backtrace, loaded.backtrace
33
+ end
33
34
 
34
- test "loading a marshallable exception when class init throws an error returns an unloadable exception" do
35
- original = RuntimeError.new "message"
35
+ test "loading a marshallable exception when class init throws an error returns an unloadable exception" do
36
+ original = RuntimeError.new "message"
36
37
 
37
- marshalled = DeepTest::MarshallableExceptionWrapper.new(original)
38
- RuntimeError.expects(:new).raises(StandardError.new)
38
+ marshalled = MarshallableExceptionWrapper.new(original)
39
+ RuntimeError.expects(:new).raises(StandardError.new)
39
40
 
40
- loaded = Marshal.load(Marshal.dump(marshalled)).resolve
41
+ loaded = Marshal.load(Marshal.dump(marshalled)).resolve
41
42
 
42
- assert_equal DeepTest::UnloadableException, loaded.class
43
+ assert_equal UnloadableException, loaded.class
44
+ end
43
45
  end
44
46
  end
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ module DeepTest
4
+ module Metrics
5
+ class DataTest < ::Test::Unit::TestCase
6
+ test "measurements are summarized in report" do
7
+ data = Data.new
8
+ data.add Measurement.new("category a", 1, "bytes")
9
+ data.add Measurement.new("category b", 2, "seconds")
10
+ data.add Measurement.new("category a", 2, "bytes")
11
+ data.add Measurement.new("category b", 3, "seconds")
12
+
13
+ assert_equal <<-end_text, data.summary
14
+ Metrics Data
15
+ ------------
16
+ category a: 1.5 avg / 3 total bytes
17
+ category b: 2.5 avg / 5 total seconds
18
+ end_text
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ require File.dirname(__FILE__) + "/../../test_helper"
2
+
3
+ module DeepTest
4
+ module Metrics
5
+ class MeasurementTest < ::Test::Unit::TestCase
6
+ test "of_time_taken should measure time an operation takes" do
7
+ measurement = Measurement.of_time_taken("category") do
8
+ sleep 0.5
9
+ end
10
+
11
+ assert_equal "category", measurement.category
12
+ assert_in_delta 0.5, measurement.value, 0.1
13
+ assert_equal "seconds", measurement.units
14
+ end
15
+ end
16
+ end
17
+ end
18
+
@@ -0,0 +1,104 @@
1
+ require File.dirname(__FILE__) + "/../test_helper"
2
+
3
+ module DeepTest
4
+ unit_tests do
5
+ test "should write strings to proxy wire" do
6
+ io = ProxyIO.new(ProxyIO::Stdout, wire = mock)
7
+ wire.expects(:send_message).with ProxyIO::Stdout::Output.new("my_string")
8
+ io.write "my_string"
9
+ end
10
+
11
+ test "should call to_s on any received objects" do
12
+ io = ProxyIO.new(ProxyIO::Stdout, wire = mock)
13
+ wire.expects(:send_message).with ProxyIO::Stdout::Output.new("some value")
14
+ io.write mock(:to_s => "some value")
15
+ end
16
+
17
+ test "should clear string buffer after forwarding to wire" do
18
+ io = ProxyIO.new(ProxyIO::Stdout, wire = mock)
19
+ wire.expects(:send_message).with ProxyIO::Stdout::Output.new("string 1")
20
+ wire.expects(:send_message).with ProxyIO::Stdout::Output.new("string 2")
21
+ io.write "string 1"
22
+ io.write "string 2"
23
+ end
24
+
25
+ test "should forward flush to the wire" do
26
+ io = ProxyIO.new(ProxyIO::Stdout, wire = mock)
27
+ wire.expects(:send_message).with kind_of(ProxyIO::Stdout::Flush)
28
+ io.flush
29
+ end
30
+
31
+ test "Stdout::Output prints to stdout" do
32
+ output = ProxyIO::Stdout::Output.new("output")
33
+ assert_equal "output", capture_stdout { output.execute }
34
+ end
35
+
36
+ test "Stderr::Output prints to stdout" do
37
+ output = ProxyIO::Stderr::Output.new("output")
38
+ assert_equal "output", capture_stderr { output.execute }
39
+ end
40
+
41
+ test "Stdout::Flush prints to stdout" do
42
+ output = ProxyIO::Stdout::Flush.new
43
+ $stdout.expects :flush
44
+ output.execute
45
+ end
46
+
47
+ test "Stderr::Flush prints to stdout" do
48
+ output = ProxyIO::Stderr::Flush.new
49
+ $stderr.expects :flush
50
+ output.execute
51
+ end
52
+
53
+ test "replace_stdout_stderr! yields" do
54
+ yielded = false
55
+ ProxyIO.replace_stdout_stderr!(mock) { yielded = true }
56
+ assert yielded, "didn't yield"
57
+ end
58
+
59
+ test "will replace stdout with proxy to wire" do
60
+ ProxyIO.replace_stdout_stderr!(wire = mock) do
61
+ wire.expects(:send_message).with ProxyIO::Stdout::Output.new("global string")
62
+ wire.expects(:send_message).with ProxyIO::Stdout::Output.new("const string")
63
+ $stdout.write "global string"
64
+ STDOUT.write "const string"
65
+ end
66
+ end
67
+
68
+ test "will restore stdout after yielding" do
69
+ old_stdout_global, old_stdout_const = $stdout, STDOUT
70
+ ProxyIO.replace_stdout_stderr!(mock) { raise "error" } rescue nil
71
+ assert_equal old_stdout_global, $stdout
72
+ assert_equal old_stdout_const, STDOUT
73
+ end
74
+
75
+ test "will replace stderr with proxy to wire" do
76
+ ProxyIO.replace_stdout_stderr!(wire = mock) do
77
+ wire.expects(:send_message).with ProxyIO::Stderr::Output.new("global string")
78
+ wire.expects(:send_message).with ProxyIO::Stderr::Output.new("const string")
79
+ $stderr.write "global string"
80
+ STDERR.write "const string"
81
+ end
82
+ end
83
+
84
+ test "will restore stderr after yielding" do
85
+ old_stderr_global, old_stderr_const = $stderr, STDERR
86
+ ProxyIO.replace_stdout_stderr!(mock) { raise "error" } rescue nil
87
+ assert_equal old_stderr_global, $stderr
88
+ assert_equal old_stderr_const, STDERR
89
+ end
90
+
91
+ test "reconnect the logger to the new stdout" do
92
+ old_stderr_global, old_stderr_const = $stderr, STDERR
93
+ ProxyIO.replace_stdout_stderr!(mock) do
94
+ assert_equal $stdout, DeepTest.logger.io_stream
95
+ end
96
+ end
97
+
98
+ test "supress warnings restores verbose" do
99
+ old_verbose = $VERBOSE
100
+ ProxyIO.supress_warnings { raise "error" } rescue nil
101
+ assert_equal old_verbose, $VERBOSE
102
+ end
103
+ end
104
+ end
@@ -1,128 +1,128 @@
1
1
  require File.dirname(__FILE__) + "/../test_helper"
2
2
 
3
- unit_tests do
3
+ module DeepTest
4
+ unit_tests do
5
+ class FakeResult
6
+ attr_reader :identifier
7
+ def initialize(i) @identifier = i; end
8
+ def ==(other) identifier == other.identifier; end
9
+ end
4
10
 
5
- class FakeResult
6
- attr_reader :identifier
7
- def initialize(i) @identifier = i; end
8
- def ==(other) identifier == other.identifier; end
9
- end
11
+ test "reads all as many results as requested" do
12
+ central_command = TestCentralCommand.start Options.new({})
13
+ 1.upto(4) {|i| central_command.write_result FakeResult.new(i)}
14
+ work_units = {1 => "One", 2 => "Two", 3 => "Three"}
15
+ ResultReader.new(central_command).read(work_units) {}
16
+ assert_equal FakeResult.new(4), central_command.take_result
17
+ end
10
18
 
11
- test "reads all as many results as requested" do
12
- blackboard = DeepTest::SimpleTestBlackboard.new
13
- 1.upto(4) {|i| blackboard.write_result FakeResult.new(i)}
14
- work_units = {1 => "One", 2 => "Two", 3 => "Three"}
15
- DeepTest::ResultReader.new(blackboard).read(work_units) {}
16
- assert_equal FakeResult.new(4), blackboard.take_result
17
- end
19
+ test "returns unread tests on NoAgentsRunningError" do
20
+ central_command = TestCentralCommand.start Options.new({})
21
+ work_units = {1 => "One"}
22
+ FailureMessage.expects(:show)
23
+ ResultReader.new(central_command).read(work_units) {}
24
+ assert_equal({1 => "One"}, work_units)
25
+ end
18
26
 
19
- test "returns unread tests on ResultOverdueError" do
20
- blackboard = DeepTest::SimpleTestBlackboard.new
21
- blackboard.simulate_result_overdue_error = true
22
- work_units = {1 => "One"}
23
- DeepTest.logger.expects(:error)
24
- DeepTest::ResultReader.new(blackboard).read(work_units) {}
25
- assert_equal({1 => "One"}, work_units)
26
- end
27
+ test "yields each result" do
28
+ central_command = TestCentralCommand.start Options.new({})
29
+ 1.upto(3) {|i| central_command.write_result FakeResult.new(i)}
30
+ results = []
31
+ work_units = {1 => "One", 2 => "Two", 3 => "Three"}
32
+ ResultReader.new(central_command).read(work_units) {|r| results << r}
33
+ assert_equal [["One", FakeResult.new(1)],
34
+ ["Two", FakeResult.new(2)],
35
+ ["Three", FakeResult.new(3)]],
36
+ results
37
+ end
27
38
 
28
- test "yields each result" do
29
- blackboard = DeepTest::SimpleTestBlackboard.new
30
- 1.upto(3) {|i| blackboard.write_result FakeResult.new(i)}
31
- results = []
32
- work_units = {1 => "One", 2 => "Two", 3 => "Three"}
33
- DeepTest::ResultReader.new(blackboard).read(work_units) {|r| results << r}
34
- assert_equal [["One", FakeResult.new(1)],
35
- ["Two", FakeResult.new(2)],
36
- ["Three", FakeResult.new(3)]],
37
- results
38
- end
39
+ test "keeps attempting to read results when none are available" do
40
+ central_command = TestCentralCommand.start Options.new({})
41
+ work_units = {1 => "One", 2 => "Two", 3 => "Three"}
42
+ t = Thread.new {ResultReader.new(central_command).read(work_units) {}}
43
+ 1.upto(4) {|i| central_command.write_result FakeResult.new(i)}
44
+ t.join
45
+ assert_equal FakeResult.new(4), central_command.take_result
46
+ end
39
47
 
40
- test "keeps attempting to read results when none are available" do
41
- blackboard = DeepTest::SimpleTestBlackboard.new
42
- work_units = {1 => "One", 2 => "Two", 3 => "Three"}
43
- t = Thread.new {DeepTest::ResultReader.new(blackboard).read(work_units) {}}
44
- 1.upto(4) {|i| blackboard.write_result FakeResult.new(i)}
45
- t.join
46
- assert_equal FakeResult.new(4), blackboard.take_result
47
- end
48
+ test "doesn't yield empty results" do
49
+ central_command = TestCentralCommand.start Options.new({})
50
+ results = []
51
+ t = Thread.new {ResultReader.new(central_command).read(1 => "One") {|r| results << r}}
52
+ central_command.write_result FakeResult.new(1)
53
+ t.join
54
+ assert_equal [["One", FakeResult.new(1)]], results
55
+ end
48
56
 
49
- test "doesn't yield empty results" do
50
- blackboard = DeepTest::SimpleTestBlackboard.new
51
- results = []
52
- t = Thread.new {DeepTest::ResultReader.new(blackboard).read(1 => "One") {|r| results << r}}
53
- blackboard.write_result FakeResult.new(1)
54
- t.join
55
- assert_equal [["One", FakeResult.new(1)]], results
56
- end
57
+ test "prints output if result has output" do
58
+ central_command = TestCentralCommand.start Options.new({})
59
+ central_command.write_result mock(:output => "output", :identifier => 1)
57
60
 
58
- test "prints output if result has output" do
59
- blackboard = DeepTest::SimpleTestBlackboard.new
60
- blackboard.write_result mock(:output => "output", :identifier => 1)
61
+ out = capture_stdout do
62
+ ResultReader.new(central_command).read(1 => "One") {}
63
+ end
61
64
 
62
- out = capture_stdout do
63
- DeepTest::ResultReader.new(blackboard).read(1 => "One") {}
65
+ assert_equal "output", out
64
66
  end
65
67
 
66
- assert_equal "output", out
67
- end
68
+ test "doesn't print any output if output is nil" do
69
+ central_command = TestCentralCommand.start Options.new({})
70
+ central_command.write_result mock(:output => nil, :identifier => 1)
68
71
 
69
- test "doesn't print any output if output is nil" do
70
- blackboard = DeepTest::SimpleTestBlackboard.new
71
- blackboard.write_result mock(:output => nil, :identifier => 1)
72
+ out = capture_stdout do
73
+ ResultReader.new(central_command).read(1 => "One") {}
74
+ end
72
75
 
73
- out = capture_stdout do
74
- DeepTest::ResultReader.new(blackboard).read(1 => "One") {}
76
+ assert_equal "", out
75
77
  end
76
78
 
77
- assert_equal "", out
78
- end
79
+ test "prints useful error information in case of Agent::Error" do
80
+ error = RuntimeError.new "message"
81
+ error.set_backtrace ['a', 'b']
79
82
 
80
- test "prints useful error information in case of Worker::Error" do
81
- error = RuntimeError.new "message"
82
- error.set_backtrace ['a', 'b']
83
+ central_command = TestCentralCommand.start Options.new({})
84
+ central_command.write_result Agent::Error.new("work_unit", error)
83
85
 
84
- blackboard = DeepTest::SimpleTestBlackboard.new
85
- blackboard.write_result DeepTest::Worker::Error.new("work_unit", error)
86
86
 
87
+ out = capture_stdout do
88
+ ResultReader.new(central_command).read(1 => "One") {}
89
+ end
87
90
 
88
- out = capture_stdout do
89
- DeepTest::ResultReader.new(blackboard).read(1 => "One") {}
91
+ assert_equal "work_unit: message\na\nb\n", out
90
92
  end
91
93
 
92
- assert_equal "work_unit: message\na\nb\n", out
93
- end
94
+ test "doesn't yield Agent::Error results" do
95
+ central_command = TestCentralCommand.start Options.new({})
96
+ central_command.write_result Agent::Error.new("work_unit", RuntimeError.new)
94
97
 
95
- test "doesn't yield Worker::Error results" do
96
- blackboard = DeepTest::SimpleTestBlackboard.new
97
- blackboard.write_result DeepTest::Worker::Error.new("work_unit", RuntimeError.new)
98
98
 
99
+ results = []
100
+ capture_stdout do
101
+ ResultReader.new(central_command).read(1 => "One") {|r| results << r}
102
+ end
99
103
 
100
- results = []
101
- capture_stdout do
102
- DeepTest::ResultReader.new(blackboard).read(1 => "One") {|r| results << r}
104
+ assert_equal [], results
103
105
  end
104
106
 
105
- assert_equal [], results
106
- end
107
-
108
- test "doesn't modify original work unit hash" do
109
- blackboard = DeepTest::SimpleTestBlackboard.new
110
- blackboard.write_result FakeResult.new(1)
111
- work_units = {1 => "One"}
112
- DeepTest::ResultReader.new(blackboard).read(work_units) {}
113
- assert_equal({1 => "One"}, work_units)
114
- end
107
+ test "doesn't modify original work unit hash" do
108
+ central_command = TestCentralCommand.start Options.new({})
109
+ central_command.write_result FakeResult.new(1)
110
+ work_units = {1 => "One"}
111
+ ResultReader.new(central_command).read(work_units) {}
112
+ assert_equal({1 => "One"}, work_units)
113
+ end
115
114
 
116
- test "returns remaining tests that didn't have errors" do
117
- blackboard = DeepTest::SimpleTestBlackboard.new
118
- blackboard.write_result FakeResult.new(1)
119
- blackboard.write_result DeepTest::Worker::Error.new("work_unit", RuntimeError.new)
115
+ test "returns remaining tests that didn't have errors" do
116
+ central_command = TestCentralCommand.start Options.new({})
117
+ central_command.write_result FakeResult.new(1)
118
+ central_command.write_result Agent::Error.new("work_unit", RuntimeError.new)
120
119
 
121
- work_units = {1 => "One", 2 => "Two"}
120
+ work_units = {1 => "One", 2 => "Two"}
122
121
 
123
- capture_stdout do
124
- missing_work_units = DeepTest::ResultReader.new(blackboard).read(work_units) {}
125
- assert_equal({2 => "Two"}, missing_work_units)
122
+ capture_stdout do
123
+ missing_work_units = ResultReader.new(central_command).read(work_units) {}
124
+ assert_equal({2 => "Two"}, missing_work_units)
125
+ end
126
126
  end
127
127
  end
128
128
  end