dtr 0.0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +7 -0
- data/LICENSE.txt +203 -0
- data/README.rdoc +208 -0
- data/Rakefile +64 -205
- data/TODO +8 -2
- data/bin/dtr +27 -60
- data/dtr.gemspec +8 -11
- data/lib/dtr.rb +5 -94
- data/lib/dtr/agent.rb +38 -0
- data/lib/dtr/agent/brain.rb +57 -0
- data/lib/dtr/agent/herald.rb +60 -0
- data/lib/dtr/agent/runner.rb +87 -0
- data/lib/dtr/agent/sync_codebase.rb +44 -0
- data/lib/dtr/agent/sync_logger.rb +70 -0
- data/lib/dtr/agent/test_case.rb +53 -0
- data/lib/dtr/agent/test_unit.rb +40 -0
- data/lib/dtr/agent/worker.rb +89 -0
- data/lib/dtr/agent/working_env_ext.rb +47 -0
- data/lib/dtr/facade.rb +65 -0
- data/lib/dtr/master.rb +40 -0
- data/lib/dtr/monitor.rb +95 -0
- data/lib/dtr/raketasks.rb +155 -22
- data/lib/dtr/shared.rb +24 -0
- data/lib/dtr/shared/adapter.rb +115 -0
- data/lib/dtr/shared/configuration.rb +104 -0
- data/lib/dtr/shared/message_decorator.rb +28 -0
- data/lib/dtr/shared/ruby_ext.rb +129 -0
- data/lib/dtr/shared/service.rb +19 -0
- data/lib/dtr/shared/service/agent.rb +37 -0
- data/lib/dtr/shared/service/file.rb +28 -0
- data/lib/dtr/shared/service/rinda.rb +48 -0
- data/lib/dtr/shared/service/runner.rb +34 -0
- data/lib/dtr/shared/service/working_env.rb +28 -0
- data/lib/dtr/shared/sync_codebase.rb +18 -0
- data/lib/dtr/shared/sync_codebase/copiable_package.rb +40 -0
- data/lib/dtr/shared/sync_codebase/master_ext.rb +40 -0
- data/lib/dtr/shared/sync_codebase/package.rb +53 -0
- data/lib/dtr/shared/sync_codebase/sync_service.rb +36 -0
- data/lib/dtr/shared/sync_logger.rb +64 -0
- data/lib/dtr/shared/utils.rb +17 -0
- data/lib/dtr/shared/utils/cmd.rb +30 -0
- data/lib/dtr/shared/utils/env_store.rb +60 -0
- data/lib/dtr/shared/utils/logger.rb +87 -0
- data/lib/dtr/shared/working_env.rb +38 -0
- data/lib/dtr/test_unit.rb +9 -275
- data/lib/dtr/test_unit/drb_test_runner.rb +48 -0
- data/lib/dtr/test_unit/injection.rb +29 -0
- data/lib/dtr/test_unit/test_case_injection.rb +37 -0
- data/lib/dtr/test_unit/test_suite_injection.rb +24 -0
- data/lib/dtr/test_unit/testrunnermediator_injection.rb +72 -0
- data/lib/dtr/test_unit/thread_safe_test_result.rb +38 -0
- data/lib/dtr/test_unit/worker_club.rb +72 -0
- data/lib/dtr/test_unit_injection.rb +1 -2
- data/test/acceptance/agent_working_env_test.rb +86 -0
- data/test/acceptance/dtr_package_task_test.rb +36 -0
- data/test/acceptance/general_test.rb +331 -0
- data/test/acceptance/raketasks_test.rb +23 -0
- data/test/acceptance/sync_codebase_test.rb +66 -0
- data/test/acceptance/sync_logger_test.rb +32 -0
- data/test/agent_helper.rb +37 -0
- data/test/logger_stub.rb +34 -0
- data/test/test_helper.rb +71 -0
- data/test/unit/adapter_test.rb +149 -0
- data/test/unit/configuration_test.rb +44 -0
- data/test/unit/facade_test.rb +41 -0
- data/test/unit/logger_test.rb +72 -0
- data/test/unit/test_unit_test.rb +26 -0
- data/test/unit/working_env_test.rb +71 -0
- data/testdata/Rakefile +11 -0
- data/testdata/a_failed_test_case.rb +8 -0
- data/testdata/a_file_system_test_case.rb +8 -0
- data/testdata/a_test_case.rb +13 -0
- data/testdata/a_test_case2.rb +6 -0
- data/testdata/an_error_test_case.rb +9 -0
- data/testdata/another_project/Rakefile +6 -0
- data/testdata/another_project/passed_test_case.rb +7 -0
- data/testdata/hacked_run_method_test_case.rb +15 -0
- data/testdata/is_required_by_a_test.rb +9 -0
- data/testdata/lib/lib_test_case.rb +7 -0
- data/testdata/package_task_test_rakefile +8 -0
- data/testdata/raketasks/Rakefile +7 -0
- data/testdata/raketasks/success_test_case.rb +6 -0
- data/testdata/scenario_test_case.rb +34 -0
- data/testdata/setup_agent_env_test_case.rb +9 -0
- data/testdata/sleep_3_secs_test_case.rb +9 -0
- data/testdata/verify_dir_pwd/Rakefile +6 -0
- data/testdata/verify_dir_pwd/verify_dir_pwd_test_case.rb +10 -0
- metadata +101 -34
- data/README +0 -291
- data/install.rb +0 -88
- data/lib/dtr/base.rb +0 -172
- data/lib/dtr/runner.rb +0 -270
- data/lib/dtr/service_provider.rb +0 -160
data/TODO
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
= DTR Project -- To Do List
|
2
2
|
|
3
|
-
Send suggestions for this list to
|
3
|
+
Send suggestions for this list to iam@li-xiao.com
|
4
4
|
|
5
5
|
=== To Do
|
6
|
-
|
6
|
+
|
7
|
+
=== TBD for next release
|
8
|
+
should trigger started notification on test runner in agent Herald, for some tools are using this hook(e.g. inbrowser_test) to setup test environment.
|
9
|
+
agent should wakeup when worker is dead, so that it could be picked up by another master process
|
10
|
+
auto prepare database for each runner, so that run tests in multi-processes could be easy setup.
|
11
|
+
provide a way to monitor agent runner efficiency
|
12
|
+
use system instead of fork to launch sub process in agent, which makes dtr support windows and jruby
|
7
13
|
|
8
14
|
(moved DONE list to CHANGES file)
|
data/bin/dtr
CHANGED
@@ -11,10 +11,13 @@ end
|
|
11
11
|
NOTES = <<-NOTES
|
12
12
|
----------------
|
13
13
|
Notes:
|
14
|
-
*
|
15
|
-
*
|
16
|
-
*
|
17
|
-
|
14
|
+
* DTR would always add 'localhost' into broadcast list.
|
15
|
+
* Agent start by specifying runners by -r option, every runner would be started in different process for running test. e.g. dtr -r runner1,runner2
|
16
|
+
* DTR master environment options:
|
17
|
+
* DTR_MASTER_ENV: this variable would be copied into agent process for sharing info between master and agents. Normally used in agent setup environment command.
|
18
|
+
* DTR_AGENT_ENV_SETUP_CMD: this variable would be applied as agent setup environment command when agent have no setup environment command specified by --setup option.
|
19
|
+
* DTR_LOG_LEVEL: master process logger level, e.g. ENV['DTR_LOG_LEVEL'] = Logger::DEBUG. Agent process logs would be output in master process log file, so setting this option also changes agent logger level.
|
20
|
+
* DTR_RUNNER_NAME: this environment variable would be provided in runner process for test environment to get the runner name to setup, e.g. setting up database configuration.
|
18
21
|
|
19
22
|
DTR is a distributed test runner program for decreasing time of running ruby tests based on ruby 'test/unit' package.
|
20
23
|
For additional information, see http://dtr.rubyforge.org/
|
@@ -24,60 +27,39 @@ opts = OptionParser.new do |opts|
|
|
24
27
|
opts.banner = "DTR usage: #{$0} [options]"
|
25
28
|
opts.separator ""
|
26
29
|
opts.separator "Synopsis:"
|
27
|
-
opts.separator "dtr -
|
28
|
-
opts.separator "dtr -
|
29
|
-
opts.separator "dtr -a dtr_server_ip -m"
|
30
|
+
opts.separator "dtr -g group_name -r runner1_name,runner2_name"
|
31
|
+
opts.separator "dtr -a broadcast_ip -m"
|
30
32
|
opts.separator ""
|
31
33
|
opts.separator "Options:"
|
32
34
|
|
33
|
-
opts.on_tail("-m", "--monitor", "Monitor the status of the dtr
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
opts.on_tail("-c", "--clean_server", "Clean server environment, shutdown all runners registered.") do
|
38
|
-
DTR.clean_server
|
39
|
-
end
|
40
|
-
|
41
|
-
opts.on_tail("-b", "--be_silent", "Only show error messages") do
|
42
|
-
DTROPTIONS[:log_level] = Logger::ERROR
|
35
|
+
opts.on_tail("-m", "--monitor", "Monitor the status of the dtr agents and master processes. Used for testing your dtr grid environment. CAUTION! monitoring agents causes all idle agents hang on by the monitor process.") do
|
36
|
+
$monitor = true
|
43
37
|
end
|
44
38
|
|
45
|
-
opts.
|
46
|
-
|
39
|
+
opts.on("-p", "--port PORT", "Port number of DTR agent listening. Default is 7788.") do |port|
|
40
|
+
DTR.agent_listen_port = port
|
47
41
|
end
|
48
42
|
|
49
|
-
opts.on("-
|
50
|
-
|
43
|
+
opts.on("-g", "--group GROUP_NAME", "If you have several DTR grids working for different project or environment, you should group your agents in different names for different usages. Default is none.") do |group_name|
|
44
|
+
DTR.group = group_name
|
51
45
|
end
|
52
46
|
|
53
47
|
opts.on("-r runner1_name,runner2_name", Array, "Start DTR test runner agent with unique runner names.") do |names|
|
54
|
-
|
48
|
+
DTR_AGENT_OPTIONS[:runners] = names.collect{|name| name.untaint}
|
55
49
|
end
|
56
50
|
|
57
|
-
opts.on("-a", "--
|
51
|
+
opts.on("-a", "--broadcast_address ADDRESS", "Specify broadcast address for looking up dtr agent service, e.g. 192.168.255.255. Default is 'localhost'. DTR master and monitor would need this.") do |address|
|
58
52
|
if (!address.nil?) && (!address.empty?)
|
59
53
|
DTR.broadcast_list = [address]
|
60
54
|
end
|
61
55
|
end
|
62
56
|
|
63
|
-
opts.on("-i", "--setup COMMAND", "Set command for initializing test runner test environment, e.g. 'rake db:test:prepare'. Default is do nothing.") do |command|
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
opts.on_tail("-D", "--daemon", "Start server/runners in daemon mode. Gem 'daemons' must be installed") do
|
68
|
-
DTROPTIONS[:daemon] = true
|
69
|
-
end
|
70
|
-
|
71
|
-
opts.on_tail("-S", "--stop_server", "Stop server run in daemon mode.") do
|
72
|
-
DTR.stop_server_daemon_mode
|
57
|
+
opts.on("-i", "--setup COMMAND", "Set command for initializing test runner test environment, e.g. 'rake db:test:prepare'. Default is do nothing. You also can specify DTR_AGENT_ENV_SETUP_CMD in your master process environment to let all agents setup same environment.") do |command|
|
58
|
+
DTR_AGENT_OPTIONS[:agent_env_setup_cmd] = command.untaint
|
73
59
|
end
|
74
|
-
|
75
|
-
opts.
|
76
|
-
|
77
|
-
end
|
78
|
-
|
79
|
-
opts.on_tail("-d", "--debug", "output debug log") do
|
80
|
-
DTROPTIONS[:log_level] = Logger::DEBUG
|
60
|
+
|
61
|
+
opts.on("-d", "--working_directory DIRECTORY", "Specify a directory as agent launching & working directory.") do |dir|
|
62
|
+
DTR_AGENT_OPTIONS[:launching_dir] = dir
|
81
63
|
end
|
82
64
|
|
83
65
|
opts.on_tail("-v", "--version", "Show version") do
|
@@ -99,26 +81,11 @@ if no_argv
|
|
99
81
|
puts NOTES
|
100
82
|
end
|
101
83
|
|
102
|
-
if
|
103
|
-
|
104
|
-
DTR.start_runners_daemon_mode
|
105
|
-
else
|
106
|
-
DTR.start_runners
|
107
|
-
end
|
84
|
+
if $monitor
|
85
|
+
DTR.monitor
|
108
86
|
end
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
DTR.start_server_daemon_mode
|
113
|
-
else
|
114
|
-
DTR.start_server
|
87
|
+
if DTR_AGENT_OPTIONS[:runners] && !DTR_AGENT_OPTIONS[:runners].empty?
|
88
|
+
Dir.chdir(DTR_AGENT_OPTIONS[:launching_dir] || '.') do
|
89
|
+
DTR.start_agent
|
115
90
|
end
|
116
91
|
end
|
117
|
-
|
118
|
-
if DTROPTIONS[:monitor]
|
119
|
-
if DTROPTIONS[:daemon]
|
120
|
-
puts "Can't start monitor with daemon mode."
|
121
|
-
else
|
122
|
-
DTR.monitor
|
123
|
-
end
|
124
|
-
end
|
data/dtr.gemspec
CHANGED
@@ -1,17 +1,12 @@
|
|
1
1
|
Gem::Specification.new do |spec|
|
2
2
|
spec.name = 'dtr'
|
3
|
-
spec.version = "0.0
|
3
|
+
spec.version = "1.0.0"
|
4
4
|
spec.summary = "DTR is a distributed test runner to run tests on distributed computers for decreasing build time."
|
5
5
|
|
6
6
|
#### Dependencies and requirements.
|
7
|
+
spec.files = ["lib/dtr/agent/brain.rb", "lib/dtr/agent/herald.rb", "lib/dtr/agent/runner.rb", "lib/dtr/agent/sync_codebase.rb", "lib/dtr/agent/sync_logger.rb", "lib/dtr/agent/test_case.rb", "lib/dtr/agent/test_unit.rb", "lib/dtr/agent/worker.rb", "lib/dtr/agent/working_env_ext.rb", "lib/dtr/agent.rb", "lib/dtr/facade.rb", "lib/dtr/master.rb", "lib/dtr/monitor.rb", "lib/dtr/raketasks.rb", "lib/dtr/shared/adapter.rb", "lib/dtr/shared/configuration.rb", "lib/dtr/shared/message_decorator.rb", "lib/dtr/shared/ruby_ext.rb", "lib/dtr/shared/service/agent.rb", "lib/dtr/shared/service/file.rb", "lib/dtr/shared/service/rinda.rb", "lib/dtr/shared/service/runner.rb", "lib/dtr/shared/service/working_env.rb", "lib/dtr/shared/service.rb", "lib/dtr/shared/sync_codebase/copiable_package.rb", "lib/dtr/shared/sync_codebase/master_ext.rb", "lib/dtr/shared/sync_codebase/package.rb", "lib/dtr/shared/sync_codebase/sync_service.rb", "lib/dtr/shared/sync_codebase.rb", "lib/dtr/shared/sync_logger.rb", "lib/dtr/shared/utils/cmd.rb", "lib/dtr/shared/utils/env_store.rb", "lib/dtr/shared/utils/logger.rb", "lib/dtr/shared/utils.rb", "lib/dtr/shared/working_env.rb", "lib/dtr/shared.rb", "lib/dtr/test_unit/drb_test_runner.rb", "lib/dtr/test_unit/injection.rb", "lib/dtr/test_unit/test_case_injection.rb", "lib/dtr/test_unit/test_suite_injection.rb", "lib/dtr/test_unit/testrunnermediator_injection.rb", "lib/dtr/test_unit/thread_safe_test_result.rb", "lib/dtr/test_unit/worker_club.rb", "lib/dtr/test_unit.rb", "lib/dtr/test_unit_injection.rb", "lib/dtr.rb", "bin/dtr", "CHANGES", "dtr.gemspec", "lib", "LICENSE.TXT", "Rakefile", "README.rdoc", "TODO"]
|
7
8
|
|
8
|
-
spec.
|
9
|
-
#s.requirements << ""
|
10
|
-
|
11
|
-
#### Which files are to be included in this gem? Everything! (Except SVN directories.)
|
12
|
-
|
13
|
-
spec.files = FileList['lib/**/*.rb', 'lib/**/*.rake', 'bin/*', '[a-zA-Z]*'].to_a
|
14
|
-
p FileList['lib/**/*.rb', 'lib/**/*.rake', 'bin/*', '[a-zA-Z]*'].to_a
|
9
|
+
spec.test_files = ["test/acceptance/agent_working_env_test.rb", "test/acceptance/dtr_package_task_test.rb", "test/acceptance/general_test.rb", "test/acceptance/raketasks_test.rb", "test/acceptance/sync_codebase_test.rb", "test/acceptance/sync_logger_test.rb", "test/agent_helper.rb", "test/logger_stub.rb", "test/test_helper.rb", "test/unit/adapter_test.rb", "test/unit/configuration_test.rb", "test/unit/facade_test.rb", "test/unit/logger_test.rb", "test/unit/test_unit_test.rb", "test/unit/working_env_test.rb", "testdata/a_failed_test_case.rb", "testdata/a_file_system_test_case.rb", "testdata/a_test_case.rb", "testdata/a_test_case2.rb", "testdata/an_error_test_case.rb", "testdata/another_project", "testdata/another_project/passed_test_case.rb", "testdata/another_project/Rakefile", "testdata/hacked_run_method_test_case.rb", "testdata/is_required_by_a_test.rb", "testdata/lib", "testdata/lib/lib_test_case.rb", "testdata/package_task_test_rakefile", "testdata/Rakefile", "testdata/raketasks", "testdata/raketasks/Rakefile", "testdata/raketasks/success_test_case.rb", "testdata/scenario_test_case.rb", "testdata/setup_agent_env_test_case.rb", "testdata/sleep_3_secs_test_case.rb", "testdata/verify_dir_pwd", "testdata/verify_dir_pwd/Rakefile", "testdata/verify_dir_pwd/verify_dir_pwd_test_case.rb"]
|
15
10
|
|
16
11
|
#### Load-time details: library and application (you will need one or both).
|
17
12
|
|
@@ -23,12 +18,14 @@ Gem::Specification.new do |spec|
|
|
23
18
|
|
24
19
|
#### Documentation and testing.
|
25
20
|
|
26
|
-
spec.has_rdoc =
|
21
|
+
spec.has_rdoc = true
|
22
|
+
spec.extra_rdoc_files = ["README.rdoc", "LICENSE.txt", "TODO", "CHANGES"]
|
23
|
+
spec.rdoc_options = ["--line-numbers", "--inline-source", "--main", "README.rdoc", "--title", "\"DTR -- Distributed Test Runner"]
|
27
24
|
|
28
25
|
#### Author and project details.
|
29
26
|
|
30
27
|
spec.author = "Li Xiao"
|
31
|
-
spec.email = "
|
28
|
+
spec.email = "iam@li-xiao.com"
|
32
29
|
spec.homepage = "http://github.com/xli/dtr/tree/master"
|
33
30
|
spec.rubyforge_project = "dtr"
|
34
|
-
end
|
31
|
+
end
|
data/lib/dtr.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (c) 2007-2008 Li Xiao
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -12,100 +12,11 @@
|
|
12
12
|
# See the License for the specific language governing permissions and
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
|
-
|
16
|
-
DTROPTIONS = {} unless defined?(DTROPTIONS)
|
15
|
+
require 'dtr/facade'
|
17
16
|
|
18
|
-
|
17
|
+
DTRVERSION="1.0.0"
|
18
|
+
DTR_AGENT_OPTIONS = {:runners => [], :agent_env_setup_cmd => nil}
|
19
19
|
|
20
20
|
module DTR
|
21
|
-
|
22
|
-
def start_server
|
23
|
-
require 'dtr/service_provider'
|
24
|
-
ServiceProvider.new.start
|
25
|
-
end
|
26
|
-
|
27
|
-
def start_runners
|
28
|
-
launch_runners(DTROPTIONS[:names], DTROPTIONS[:setup])
|
29
|
-
end
|
30
|
-
|
31
|
-
def launch_runners(names, setup=nil)
|
32
|
-
require 'dtr/runner'
|
33
|
-
names = names || "DTR(#{Time.now})"
|
34
|
-
DTR::RunnerAgent.start(names, setup)
|
35
|
-
end
|
36
|
-
|
37
|
-
def lib_path
|
38
|
-
File.expand_path(File.dirname(__FILE__))
|
39
|
-
end
|
40
|
-
|
41
|
-
def broadcast_list=(list)
|
42
|
-
require 'dtr/service_provider'
|
43
|
-
ServiceProvider.broadcast_list = list
|
44
|
-
end
|
45
|
-
|
46
|
-
def port=(port)
|
47
|
-
require 'dtr/service_provider'
|
48
|
-
ServiceProvider.port = port
|
49
|
-
end
|
50
|
-
|
51
|
-
def runners
|
52
|
-
require 'dtr/service_provider'
|
53
|
-
ServiceProvider.new.runners
|
54
|
-
end
|
55
|
-
|
56
|
-
def monitor
|
57
|
-
require 'dtr/service_provider'
|
58
|
-
DTROPTIONS[:log_file] = 'dtr_monitor.log'
|
59
|
-
ServiceProvider.new.monitor
|
60
|
-
end
|
61
|
-
|
62
|
-
def stop_runners_daemon_mode
|
63
|
-
with_daemon_gem do
|
64
|
-
Daemons.run_proc "dtr_runners", :ARGV => ['stop']
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def start_runners_daemon_mode
|
69
|
-
with_daemon_gem do
|
70
|
-
FileUtils.rm_rf('dtr_runners.output')
|
71
|
-
pwd = Dir.pwd
|
72
|
-
Daemons.run_proc "dtr_runners", :ARGV => ['start'], :backtrace => true do
|
73
|
-
Dir.chdir(pwd) do
|
74
|
-
start_runners
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def start_server_daemon_mode
|
81
|
-
with_daemon_gem do
|
82
|
-
Daemons.run_proc "dtr_server", :ARGV => ['start'] do
|
83
|
-
start_server
|
84
|
-
end
|
85
|
-
end
|
86
|
-
sleep(2)
|
87
|
-
end
|
88
|
-
|
89
|
-
def stop_server_daemon_mode
|
90
|
-
with_daemon_gem do
|
91
|
-
Daemons.run_proc "dtr_server", :ARGV => ['stop']
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
def with_daemon_gem
|
96
|
-
require "rubygems"
|
97
|
-
begin
|
98
|
-
require "daemons"
|
99
|
-
rescue LoadError
|
100
|
-
raise "The daemons gem must be installed"
|
101
|
-
end
|
102
|
-
yield
|
103
|
-
end
|
104
|
-
|
105
|
-
def clean_server
|
106
|
-
require 'dtr/service_provider'
|
107
|
-
ServiceProvider.new.clear_workspace
|
108
|
-
end
|
109
|
-
|
110
|
-
module_function :start_server, :start_runners, :launch_runners, :lib_path, :broadcast_list=, :runners, :with_daemon_gem, :start_runners_daemon_mode, :stop_runners_daemon_mode, :start_server_daemon_mode, :stop_server_daemon_mode, :monitor, :port=, :clean_server
|
21
|
+
extend Facade
|
111
22
|
end
|
data/lib/dtr/agent.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'dtr/shared'
|
16
|
+
require 'dtr/agent/working_env_ext'
|
17
|
+
require 'dtr/agent/sync_codebase'
|
18
|
+
|
19
|
+
require 'dtr/agent/sync_logger'
|
20
|
+
require 'dtr/agent/brain'
|
21
|
+
require 'dtr/agent/worker'
|
22
|
+
require 'dtr/agent/test_unit'
|
23
|
+
require 'dtr/agent/herald'
|
24
|
+
require 'dtr/agent/test_case'
|
25
|
+
require 'dtr/agent/runner'
|
26
|
+
|
27
|
+
module DTR
|
28
|
+
module Agent
|
29
|
+
def start(runner_names=["Distributed Test Runner"], agent_env_setup_cmd=nil)
|
30
|
+
DTR.logger('dtr_agent.log')
|
31
|
+
Brain.new(runner_names, agent_env_setup_cmd).hypnotize
|
32
|
+
end
|
33
|
+
|
34
|
+
module_function :start
|
35
|
+
end
|
36
|
+
WorkingEnv.send(:include, Agent::WorkingEnvExt)
|
37
|
+
WorkingEnv.send(:include, SyncCodebase::WorkingEnvExt)
|
38
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module DTR
|
16
|
+
module Agent
|
17
|
+
|
18
|
+
class Brain
|
19
|
+
include Adapter::Follower
|
20
|
+
|
21
|
+
def initialize(runner_names, agent_env_setup_cmd)
|
22
|
+
raise 'No runner? What can I do for you?' if runner_names.blank?
|
23
|
+
@runner_names = runner_names
|
24
|
+
@agent_env_setup_cmd = agent_env_setup_cmd
|
25
|
+
DTR.info {""}
|
26
|
+
DTR.info {"--------------------beautiful line--------------------------"}
|
27
|
+
DTR.info {"=> Agent environment setup command: #{@agent_env_setup_cmd}"}
|
28
|
+
DTR.info {"=> Runner names: #{@runner_names.join(', ')}"}
|
29
|
+
DTR.info {"=> Broadcast list: #{DTR.configuration.broadcast_list.inspect}"}
|
30
|
+
DTR.info {"=> Listening port: #{DTR.configuration.agent_listen_port}"}
|
31
|
+
DTR.info {"=> Group: #{DTR.configuration.group}"}
|
32
|
+
end
|
33
|
+
|
34
|
+
def hypnotize
|
35
|
+
loop do
|
36
|
+
if wakeup?
|
37
|
+
DTR.info {"Agent brain wakes up"}
|
38
|
+
work(DTR.fork_process { Worker.new(@runner_names, @agent_env_setup_cmd).launch })
|
39
|
+
DTR.info {"Agent brain is going to sleep"}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
rescue Interrupt, SystemExit, SignalException
|
43
|
+
ensure
|
44
|
+
relax
|
45
|
+
end
|
46
|
+
|
47
|
+
def work(worker)
|
48
|
+
until sleep?
|
49
|
+
#keep worker working :D
|
50
|
+
end
|
51
|
+
ensure
|
52
|
+
DTR.info {"Killing worker"}
|
53
|
+
DTR.kill_process worker
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Copyright (c) 2007-2008 Li Xiao <iam@li-xiao.com>
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module DTR
|
16
|
+
|
17
|
+
module Agent
|
18
|
+
class Herald
|
19
|
+
class WorkingEnvError < StandardError
|
20
|
+
end
|
21
|
+
|
22
|
+
include Service::WorkingEnv
|
23
|
+
include Service::Agent
|
24
|
+
|
25
|
+
def initialize(working_env_key, agent_env_setup_cmd, runners)
|
26
|
+
@working_env_key = working_env_key
|
27
|
+
@agent_env_setup_cmd = agent_env_setup_cmd
|
28
|
+
@runners = runners
|
29
|
+
@env_store = EnvStore.new
|
30
|
+
start_service
|
31
|
+
start_off
|
32
|
+
ensure
|
33
|
+
stop_service
|
34
|
+
end
|
35
|
+
|
36
|
+
def start_off
|
37
|
+
DTR.info {"=> Herald starts off..."}
|
38
|
+
provide_agent_info(@agent_env_setup_cmd, @runners)
|
39
|
+
|
40
|
+
@env_store[@working_env_key] = fetch_working_env
|
41
|
+
rescue WorkingEnvError
|
42
|
+
DTR.error $!.message
|
43
|
+
exit(-1)
|
44
|
+
rescue
|
45
|
+
DTR.error $!.message
|
46
|
+
DTR.error $!.backtrace.join("\n")
|
47
|
+
exit(-1)
|
48
|
+
end
|
49
|
+
|
50
|
+
def fetch_working_env
|
51
|
+
working_env = lookup_working_env
|
52
|
+
DTR.info {"=> Got working environment created at #{working_env[:created_at]} by #{working_env[:host]}"}
|
53
|
+
|
54
|
+
raise WorkingEnvError.new("No test files need to load?(working env: #{working_env})") if working_env[:files].blank?
|
55
|
+
raise WorkingEnvError.new('Setup working environment failed, no runner started.') unless working_env.setup_env(@agent_env_setup_cmd)
|
56
|
+
working_env
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|