jason-o-matic-deep_test 1.2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/CHANGELOG +47 -0
  2. data/README.rdoc +228 -0
  3. data/Rakefile +211 -0
  4. data/bin/deep_test +15 -0
  5. data/lib/deep_test.rb +90 -0
  6. data/lib/deep_test/database/mysql_setup_listener.rb +113 -0
  7. data/lib/deep_test/database/setup_listener.rb +116 -0
  8. data/lib/deep_test/deadlock_detector.rb +7 -0
  9. data/lib/deep_test/distributed/dispatch_controller.rb +53 -0
  10. data/lib/deep_test/distributed/drb_client_connection_info.rb +15 -0
  11. data/lib/deep_test/distributed/filename_resolver.rb +40 -0
  12. data/lib/deep_test/distributed/master_test_server.rb +52 -0
  13. data/lib/deep_test/distributed/multi_test_server_proxy.rb +44 -0
  14. data/lib/deep_test/distributed/null_work_unit.rb +12 -0
  15. data/lib/deep_test/distributed/remote_worker_client.rb +54 -0
  16. data/lib/deep_test/distributed/remote_worker_server.rb +111 -0
  17. data/lib/deep_test/distributed/rsync.rb +37 -0
  18. data/lib/deep_test/distributed/show_status.rhtml +41 -0
  19. data/lib/deep_test/distributed/test_server.rb +79 -0
  20. data/lib/deep_test/distributed/test_server_status.rb +9 -0
  21. data/lib/deep_test/distributed/test_server_workers.rb +24 -0
  22. data/lib/deep_test/distributed/throughput_runner.rb +42 -0
  23. data/lib/deep_test/distributed/throughput_statistics.rb +26 -0
  24. data/lib/deep_test/distributed/throughput_worker_client.rb +19 -0
  25. data/lib/deep_test/extensions/drb_extension.rb +34 -0
  26. data/lib/deep_test/extensions/object_extension.rb +40 -0
  27. data/lib/deep_test/listener_list.rb +17 -0
  28. data/lib/deep_test/local_workers.rb +55 -0
  29. data/lib/deep_test/logger.rb +17 -0
  30. data/lib/deep_test/marshallable_exception_wrapper.rb +44 -0
  31. data/lib/deep_test/metrics/gatherer.rb +67 -0
  32. data/lib/deep_test/metrics/queue_lock_wait_time_measurement.rb +133 -0
  33. data/lib/deep_test/null_worker_listener.rb +65 -0
  34. data/lib/deep_test/option.rb +70 -0
  35. data/lib/deep_test/options.rb +112 -0
  36. data/lib/deep_test/process_orchestrator.rb +49 -0
  37. data/lib/deep_test/rake_tasks.rb +11 -0
  38. data/lib/deep_test/result_reader.rb +36 -0
  39. data/lib/deep_test/rspec_detector.rb +24 -0
  40. data/lib/deep_test/server.rb +75 -0
  41. data/lib/deep_test/spec.rb +12 -0
  42. data/lib/deep_test/spec/extensions/example_group_methods.rb +64 -0
  43. data/lib/deep_test/spec/extensions/example_methods.rb +46 -0
  44. data/lib/deep_test/spec/extensions/options.rb +43 -0
  45. data/lib/deep_test/spec/extensions/reporter.rb +29 -0
  46. data/lib/deep_test/spec/extensions/spec_task.rb +20 -0
  47. data/lib/deep_test/spec/runner.rb +57 -0
  48. data/lib/deep_test/spec/work_result.rb +33 -0
  49. data/lib/deep_test/spec/work_unit.rb +59 -0
  50. data/lib/deep_test/test.rb +10 -0
  51. data/lib/deep_test/test/extensions/error.rb +14 -0
  52. data/lib/deep_test/test/runner.rb +24 -0
  53. data/lib/deep_test/test/supervised_test_suite.rb +49 -0
  54. data/lib/deep_test/test/work_result.rb +34 -0
  55. data/lib/deep_test/test/work_unit.rb +40 -0
  56. data/lib/deep_test/test_task.rb +51 -0
  57. data/lib/deep_test/ui/console.rb +76 -0
  58. data/lib/deep_test/ui/null.rb +17 -0
  59. data/lib/deep_test/warlock.rb +134 -0
  60. data/lib/deep_test/worker.rb +57 -0
  61. data/script/internal/run_test_suite.rb +7 -0
  62. data/script/public/master_test_server.rb +24 -0
  63. data/script/public/test_server.rb +18 -0
  64. data/script/public/test_throughput.rb +29 -0
  65. data/test/deep_test/database/mysql_setup_listener_test.rb +14 -0
  66. data/test/deep_test/distributed/dispatch_controller_test.rb +209 -0
  67. data/test/deep_test/distributed/drb_client_connection_info_test.rb +42 -0
  68. data/test/deep_test/distributed/filename_resolver_test.rb +52 -0
  69. data/test/deep_test/distributed/master_test_server_test.rb +32 -0
  70. data/test/deep_test/distributed/multi_test_server_proxy_test.rb +96 -0
  71. data/test/deep_test/distributed/remote_worker_client_test.rb +180 -0
  72. data/test/deep_test/distributed/remote_worker_server_test.rb +107 -0
  73. data/test/deep_test/distributed/rsync_test.rb +67 -0
  74. data/test/deep_test/distributed/test_server_test.rb +94 -0
  75. data/test/deep_test/distributed/test_server_workers_test.rb +26 -0
  76. data/test/deep_test/distributed/throughput_runner_test.rb +68 -0
  77. data/test/deep_test/distributed/throughput_worker_client_test.rb +28 -0
  78. data/test/deep_test/extensions/object_extension_test.rb +37 -0
  79. data/test/deep_test/listener_list_test.rb +20 -0
  80. data/test/deep_test/local_workers_test.rb +22 -0
  81. data/test/deep_test/logger_test.rb +11 -0
  82. data/test/deep_test/marshallable_exception_wrapper_test.rb +44 -0
  83. data/test/deep_test/metrics/gatherer_test.rb +66 -0
  84. data/test/deep_test/process_orchestrator_test.rb +11 -0
  85. data/test/deep_test/result_reader_test.rb +128 -0
  86. data/test/deep_test/server_test.rb +58 -0
  87. data/test/deep_test/test/extensions/error_test.rb +40 -0
  88. data/test/deep_test/test/runner_test.rb +7 -0
  89. data/test/deep_test/test/supervised_test_suite_test.rb +79 -0
  90. data/test/deep_test/test/work_result_test.rb +81 -0
  91. data/test/deep_test/test/work_unit_test.rb +61 -0
  92. data/test/deep_test/test_task_test.rb +43 -0
  93. data/test/deep_test/ui/console_test.rb +9 -0
  94. data/test/deep_test/warlock_test.rb +38 -0
  95. data/test/deep_test/worker_test.rb +94 -0
  96. data/test/failing.rake +11 -0
  97. data/test/failing.rb +7 -0
  98. data/test/fake_deadlock_error.rb +12 -0
  99. data/test/simple_test_blackboard.rb +45 -0
  100. data/test/simple_test_blackboard_test.rb +33 -0
  101. data/test/test_factory.rb +74 -0
  102. data/test/test_helper.rb +15 -0
  103. data/test/test_task_test.rb +72 -0
  104. metadata +160 -0
@@ -0,0 +1,52 @@
1
+ module DeepTest
2
+ module Distributed
3
+ class MasterTestServer
4
+ include ERB::Util
5
+
6
+ STATUS_PORT = 4020 unless defined?(STATUS_PORT)
7
+
8
+ attr_reader :servers
9
+
10
+ def initialize(servers)
11
+ @servers = servers
12
+ end
13
+
14
+ def show_status(req, res)
15
+ template = File.read(File.dirname(__FILE__) + "/show_status.rhtml")
16
+ res.body = ERB.new(template).result(binding)
17
+ end
18
+
19
+ def test_server_statuses
20
+ @servers.map do |s|
21
+ status = begin
22
+ s.status
23
+ rescue Exception => e
24
+ e
25
+ end
26
+
27
+ [s.__drburi, status]
28
+ end
29
+ end
30
+
31
+ def self.start(uri, server_uris)
32
+ master = start_drb(uri, server_uris)
33
+ start_http(master)
34
+ DeepTest.logger.info "MasterTestServer listening at #{DRb.uri}"
35
+ DRb.thread.join
36
+ end
37
+
38
+ def self.start_drb(uri, server_uris)
39
+ servers = server_uris.map {|server_uri| DRbObject.new_with_uri server_uri}
40
+ master = DeepTest::Distributed::MasterTestServer.new(servers)
41
+ DRb.start_service(uri, master)
42
+ master
43
+ end
44
+
45
+ def self.start_http(master)
46
+ s = WEBrick::HTTPServer.new :Port => STATUS_PORT
47
+ s.mount_proc("/", &master.method(:show_status))
48
+ Thread.new {s.start}
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,44 @@
1
+ module DeepTest
2
+ module Distributed
3
+ class MultiTestServerProxy
4
+ def initialize(options, slaves)
5
+ DeepTest.logger.debug "MultiTestServerProxy#initialize #{slaves.length} slaves"
6
+ @slave_controller = DispatchController.new(options, slaves)
7
+ end
8
+
9
+ def spawn_worker_server(options)
10
+ DeepTest.logger.debug "dispatch spawn_worker_server for #{options.origin_hostname}"
11
+ WorkerServerProxy.new options,
12
+ @slave_controller.dispatch(:spawn_worker_server,
13
+ options)
14
+ end
15
+
16
+ def sync(options)
17
+ DeepTest.logger.debug "dispatch sync for #{options.origin_hostname}"
18
+ @slave_controller.dispatch(:sync, options)
19
+ end
20
+
21
+ class WorkerServerProxy
22
+ def initialize(options, slaves)
23
+ DeepTest.logger.debug "WorkerServerProxy#initialize #{slaves.inspect}"
24
+ @slave_controller = DispatchController.new(options, slaves)
25
+ end
26
+
27
+ def load_files(files)
28
+ DeepTest.logger.debug "dispatch load_files"
29
+ @slave_controller.dispatch(:load_files, files)
30
+ end
31
+
32
+ def start_all
33
+ DeepTest.logger.debug "dispatch start_all"
34
+ @slave_controller.dispatch(:start_all)
35
+ end
36
+
37
+ def stop_all
38
+ DeepTest.logger.debug "dispatch stop_all"
39
+ @slave_controller.dispatch_with_options(:stop_all, :ignore_connection_error => true)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,12 @@
1
+ module DeepTest
2
+ module Distributed
3
+ #
4
+ # Work Unit used to measure throughput of workers.
5
+ #
6
+ class NullWorkUnit
7
+ def run
8
+ :null_work_unit_result
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,54 @@
1
+ module DeepTest
2
+ module Distributed
3
+ class RemoteWorkerClient
4
+ def initialize(options, test_server, failover_workers)
5
+ @failover_workers = failover_workers
6
+ @options = options
7
+ @test_server = test_server
8
+ end
9
+
10
+ def load_files(filelist)
11
+ @options.new_listener_list.before_sync
12
+
13
+ t = Thread.new do
14
+ @test_server.sync(@options)
15
+ @worker_server = @test_server.spawn_worker_server(@options)
16
+ @worker_server.load_files filelist
17
+ end
18
+
19
+ filelist.each {|f| load f}
20
+
21
+ begin
22
+ t.join
23
+ rescue => e
24
+ # The failover here doesn't invoke load_files on the failover_workers
25
+ # because they will be LocalWorkers, which fork from the current
26
+ # process. The fact that we depend in this here is damp...
27
+ #
28
+ fail_over("load_files", e)
29
+ end
30
+ end
31
+
32
+ def start_all
33
+ @worker_server.start_all
34
+ rescue => e
35
+ raise if failed_over?
36
+ fail_over("start_all", e)
37
+ retry
38
+ end
39
+
40
+ def stop_all
41
+ @worker_server.stop_all
42
+ end
43
+
44
+ def fail_over(method, exception)
45
+ @options.ui_instance.distributed_failover_to_local(method, exception)
46
+ @worker_server = @failover_workers
47
+ end
48
+
49
+ def failed_over?
50
+ @worker_server == @failover_workers
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,111 @@
1
+ require 'pp'
2
+ module DeepTest
3
+ module Distributed
4
+ class RemoteWorkerServer
5
+ include DRb::DRbUndumped
6
+
7
+ MERCY_KILLING_GRACE_PERIOD = 10 * 60 unless defined?(MERCY_KILLING_GRACE_PERIOD)
8
+
9
+ def initialize(base_path, workers, options)
10
+ @base_path = base_path
11
+ @workers = workers
12
+ @options = options
13
+
14
+ @resolver = FilenameResolver.new(@base_path)
15
+ @options.libs.each { |l| $: << @resolver.resolve(l) }
16
+ @options.requires.each { |r| require r }
17
+ end
18
+
19
+ def launch_mercy_killer(grace_period)
20
+ Thread.new do
21
+ sleep grace_period
22
+ exit(0) unless workers_started?
23
+ end
24
+ end
25
+
26
+ def load_files(files)
27
+ # # puts "LOAD FILES: #{files.inspect}"
28
+ @options.new_listener_list.before_remote_load_files
29
+ # # $: << "#{@base_path}/lib"
30
+ # # puts "RWS LOAD FILES workers: #{@workers.instance_variable_get("@options").new_listener_list.before_remote_load_files.inspect}"
31
+ Dir.chdir @base_path
32
+ resolver = FilenameResolver.new(@base_path)
33
+ # # # # require File.expand_path("#{@base_path}/config/environment")
34
+ # $: << "#{@base_path}/vendor/rails/activerecord/lib"
35
+ # # # # require File.expand_path("#{@base_path}/vendor/rails/activerecord/lib/active_record")
36
+ # require "active_record"
37
+ # # # # require 'vendor/rails/railties/lib/initializer'
38
+ # require File.expand_path("#{@base_path}/lib/my_mysql_setup_listener")
39
+ # # # # DeepTest::Database::MysqlSetupListener.new.starting(Struct.new(:number).new(123))
40
+ # w = MyMysqlSetupListener.new
41
+ # w.starting(Struct.new(:number).new(123))
42
+ # ENV["DEEP_TEST_DB"] = w.worker_database
43
+
44
+
45
+ # Dir.chdir @base_path
46
+ # resolver = FilenameResolver.new(@base_path)
47
+ files.each do |file|
48
+ # puts file
49
+ load resolver.resolve(file)
50
+ end
51
+ rescue Exception => e
52
+ puts e.message
53
+ pp e.backtrace
54
+ raise
55
+ end
56
+
57
+ def start_all
58
+ @workers_started = true
59
+ @workers.start_all
60
+ end
61
+
62
+ def stop_all
63
+ Thread.new do
64
+ @workers.stop_all
65
+ end
66
+ end
67
+
68
+ def workers_started?
69
+ @workers_started
70
+ end
71
+
72
+ def self.warlock
73
+ @warlock ||= DeepTest::Warlock.new
74
+ end
75
+
76
+ def self.running_server_count
77
+ @warlock.demon_count if @warlock
78
+ end
79
+
80
+ def self.stop_all
81
+ @warlock.stop_all if @warlock
82
+ end
83
+
84
+ def self.start(address, base_path, workers, options, grace_period = MERCY_KILLING_GRACE_PERIOD)
85
+ innie, outie = IO.pipe
86
+
87
+ warlock.start("RemoteWorkerServer") do
88
+ innie.close
89
+
90
+ server = new(base_path, workers, options)
91
+
92
+ DRb.start_service("drubyall://#{address}:0", server)
93
+ DeepTest.logger.info "RemoteWorkerServer started at #{DRb.uri}"
94
+
95
+ outie.write DRb.uri
96
+ outie.close
97
+
98
+ server.launch_mercy_killer(grace_period)
99
+
100
+ DRb.thread.join
101
+ end
102
+
103
+ outie.close
104
+ uri = innie.gets
105
+ innie.close
106
+ DRbObject.new_with_uri(uri)
107
+ end
108
+
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,37 @@
1
+ module DeepTest
2
+ module Distributed
3
+ class RSync
4
+ def self.sync(connection_info, options, destination)
5
+ command = Args.new(connection_info, options).command(destination)
6
+ DeepTest.logger.debug("rsycing: #{command}")
7
+ successful = system command
8
+ raise "RSync Failed!!" unless successful
9
+ end
10
+
11
+ class Args
12
+ def initialize(connection_info, options)
13
+ @connection_info = connection_info
14
+ @options = options
15
+ @sync_options = options.sync_options
16
+ end
17
+
18
+ def command(destination)
19
+ # The '/' after source tells rsync to copy the contents
20
+ # of source to destination, rather than the source directory
21
+ # itself
22
+ "rsync -az --delete #{@sync_options[:rsync_options]} #{source_location}/ #{destination}".strip.squeeze(" ")
23
+ end
24
+
25
+ def source_location
26
+ source = ""
27
+ unless @sync_options[:local]
28
+ source << @sync_options[:username] << '@' if @sync_options[:username]
29
+ source << @connection_info.address
30
+ source << (@sync_options[:daemon] ? '::' : ':')
31
+ end
32
+ source << @sync_options[:source]
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,41 @@
1
+ <html>
2
+ <head>
3
+ <title>DeepTest Test Server Status</title>
4
+ <style>
5
+ .ok {
6
+ background-color: #AAFFAA;
7
+ }
8
+
9
+ .error {
10
+ background-color: #FFAAAA;
11
+ }
12
+
13
+ </style>
14
+ </head>
15
+ <body>
16
+ <h1>DeepTest Test Server Status</h1>
17
+ <table>
18
+ <tr>
19
+ <th>Mirror Server</th>
20
+ <th>Bound To</th>
21
+ <th>Workers / Client</th>
22
+ <th>Clients</th>
23
+ </tr>
24
+ <% test_server_statuses.each do |uri, status|
25
+ if Exception === status %>
26
+ <tr class="error">
27
+ <td><%=h uri %></td>
28
+ <td colspan="3"><%=h status.message %></td>
29
+ </tr>
30
+ <% else %>
31
+ <tr class="ok">
32
+ <td><%=h uri %></td>
33
+ <td><%=h status.binding_uri %></td>
34
+ <td><%=h status.number_of_workers %></td>
35
+ <td><%=h status.remote_worker_server_count %></td>
36
+ </tr>
37
+ <% end
38
+ end %>
39
+ </table>
40
+ </body>
41
+ </html>
@@ -0,0 +1,79 @@
1
+ module DeepTest
2
+ module Distributed
3
+ class TestServer
4
+ DEFAULT_CONFIG = {
5
+ :work_dir => "/tmp",
6
+ :uri => "drubyall://:4022",
7
+ :number_of_workers => 2
8
+ } unless defined?(DEFAULT_CONFIG)
9
+
10
+ def initialize(config)
11
+ @config = config
12
+ end
13
+
14
+ def spawn_worker_server(options)
15
+ DeepTest.logger.debug("mirror spawn_worker_server for #{options.origin_hostname}")
16
+ RemoteWorkerServer.start(URI.parse(@config[:uri]).host,
17
+ options.mirror_path(@config[:work_dir]),
18
+ TestServerWorkers.new(options, @config, DRbClientConnectionInfo.new),
19
+ options)
20
+ end
21
+
22
+ def status
23
+ TestServerStatus.new(
24
+ DRb.uri,
25
+ @config[:number_of_workers],
26
+ RemoteWorkerServer.running_server_count
27
+ )
28
+ end
29
+
30
+ def sync(options)
31
+ DeepTest.logger.debug "mirror sync for #{options.origin_hostname}"
32
+ path = options.mirror_path(@config[:work_dir])
33
+ DeepTest.logger.debug "Syncing #{options.sync_options[:source]} to #{path}"
34
+ RSync.sync(DRbClientConnectionInfo.new, options, path)
35
+ end
36
+
37
+ def servers
38
+ [DRbObject.new_with_uri(DRb.uri)]
39
+ end
40
+
41
+ def self.start(config)
42
+ server = DeepTest::Distributed::TestServer.new(config)
43
+ DRb.start_service(config[:uri], server)
44
+ DeepTest.logger.info "TestServer listening at #{DRb.uri}"
45
+ DRb.thread.join
46
+ end
47
+
48
+ def self.parse_args(args)
49
+ options = DeepTest::Distributed::TestServer::DEFAULT_CONFIG.dup
50
+ OptionParser.new do |opts|
51
+ opts.banner = "Usage: deep_test test_server [options]"
52
+
53
+ opts.on("--work_dir PATH", "Absolute path to keep mirror working copies at") do |v|
54
+ options[:work_dir] = v
55
+ end
56
+
57
+ opts.on("--uri URI", "DRb URI to bind server to") do |v|
58
+ options[:uri] = v
59
+ end
60
+
61
+ opts.on("--number_of_workers NUM", "Number of workers to start when running tests") do |v|
62
+ options[:number_of_workers] = v.to_i
63
+ end
64
+
65
+ opts.on_tail("-h", "--help", "Show this message") do
66
+ puts opts
67
+ exit
68
+ end
69
+ end.parse(args)
70
+ options
71
+ end
72
+
73
+ def self.connect(options)
74
+ servers = DRbObject.new_with_uri(options.distributed_server).servers
75
+ MultiTestServerProxy.new(options, servers)
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,9 @@
1
+ module DeepTest
2
+ module Distributed
3
+ TestServerStatus = Struct.new(
4
+ :binding_uri,
5
+ :number_of_workers,
6
+ :remote_worker_server_count
7
+ ) unless defined?(TestServerStatus)
8
+ end
9
+ end