dtr 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,425 @@
1
+ # Rakefile for DTR -*- ruby -*-
2
+
3
+ # Copyright 2007 by Li Xiao (swing1979@gmail.com)
4
+ # All rights reserved.
5
+
6
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/lib')
7
+ require 'dtr'
8
+
9
+ require 'rake/clean'
10
+ require 'rake/testtask'
11
+ require 'rake/rdoctask'
12
+
13
+ begin
14
+ require 'rubygems'
15
+ require 'rake/gempackagetask'
16
+ rescue Exception
17
+ nil
18
+ end
19
+ CLEAN.include('**/*.o', '*.dot')
20
+ CLOBBER.include('TAGS')
21
+ CLOBBER.include('coverage', 'rcov_aggregate')
22
+
23
+ def announce(msg='')
24
+ STDERR.puts msg
25
+ end
26
+
27
+ if `ruby -Ilib ./bin/dtr --version` =~ /dtr, version ([0-9.]+)$/
28
+ CURRENT_VERSION = $1
29
+ else
30
+ CURRENT_VERSION = "0.0.0"
31
+ end
32
+
33
+ $package_version = CURRENT_VERSION
34
+
35
+ SRC_RB = FileList['lib/**/*.rb', 'lib/**/*.rake']
36
+
37
+ # The default task is run if rake is given no explicit arguments.
38
+
39
+ desc "Default Task"
40
+ task :default => :test_all
41
+
42
+ # Test Tasks ---------------------------------------------------------
43
+ task :dbg do |t|
44
+ puts "Arguments are: #{t.args.join(', ')}"
45
+ end
46
+
47
+ # Common Abbreviations ...
48
+
49
+ task :test_all => [:test_units, :tf]
50
+ task :tu => :test_units
51
+ task :tf => [:start_dtr_server, :start_dtr_runners, :test_functionals, :stop_dtr_runners, :stop_dtr_server]
52
+ task :test => :test_units
53
+
54
+ Rake::TestTask.new(:test_units) do |t|
55
+ t.test_files = FileList['test/*test.rb']
56
+ t.warning = true
57
+ t.verbose = false
58
+ end
59
+
60
+ Rake::TestTask.new(:test_functionals) do |t|
61
+ t.test_files = FileList['test/scenario*.rb']
62
+ t.warning = true
63
+ t.verbose = false
64
+ end
65
+
66
+ task :start_dtr_server do
67
+ ruby "-I#{File.dirname(__FILE__) + "/lib"} #{File.dirname(__FILE__) + "/bin/dtr"} -s -D"
68
+ end
69
+
70
+ task :start_dtr_runners do
71
+ ruby "-I#{File.dirname(__FILE__) + "/lib"} #{File.dirname(__FILE__) + "/bin/dtr"} -r r1,r2,r3 -D"
72
+ end
73
+
74
+ task :stop_dtr_runners do
75
+ ruby "-I#{File.dirname(__FILE__) + "/lib"} #{File.dirname(__FILE__) + "/bin/dtr"} -R"
76
+ end
77
+
78
+ task :stop_dtr_server do
79
+ ruby "-I#{File.dirname(__FILE__) + "/lib"} #{File.dirname(__FILE__) + "/bin/dtr"} -S"
80
+ end
81
+
82
+ begin
83
+ require 'rcov/rcovtask'
84
+
85
+ Rcov::RcovTask.new do |t|
86
+ t.libs << "test"
87
+ t.rcov_opts = [
88
+ '-xRakefile', '-xrakefile', '-xpublish.rf', '--text-report',
89
+ ]
90
+ t.test_files = FileList[
91
+ 'test/*test.rb'
92
+ ]
93
+ t.output_dir = 'coverage'
94
+ t.verbose = true
95
+ end
96
+ rescue LoadError
97
+ # No rcov available
98
+ end
99
+
100
+ directory 'testdata'
101
+ [:test_units].each do |t|
102
+ task t => ['testdata']
103
+ end
104
+
105
+ # CVS Tasks ----------------------------------------------------------
106
+
107
+ # Install DTR using the standard install.rb script.
108
+
109
+ desc "Install the application"
110
+ task :install do
111
+ ruby "install.rb"
112
+ end
113
+
114
+ # Create a task to build the RDOC documentation tree.
115
+
116
+ rd = Rake::RDocTask.new("rdoc") { |rdoc|
117
+ rdoc.rdoc_dir = 'html'
118
+ # rdoc.template = 'kilmer'
119
+ # rdoc.template = 'css2'
120
+ rdoc.template = 'doc/jamis.rb'
121
+ rdoc.title = "DTR -- Distributed Test Runner"
122
+ rdoc.options << '--line-numbers' << '--inline-source' <<
123
+ '--main' << 'README' <<
124
+ '--title' << '"DTR -- Distributed Test Runner'
125
+ rdoc.rdoc_files.include('README', 'LICENSE.txt', 'TODO', 'CHANGES')
126
+ rdoc.rdoc_files.include('lib/**/*.rb', 'doc/**/*.rdoc')
127
+ }
128
+
129
+ # ====================================================================
130
+ # Create a task that will package the DTR software into distributable
131
+ # tar, zip and gem files.
132
+
133
+ PKG_FILES = FileList[
134
+ 'install.rb',
135
+ '[A-Z]*',
136
+ 'bin/**/*',
137
+ 'lib/**/*.rb',
138
+ 'lib/**/*.rake',
139
+ 'test/**/*.rb',
140
+ 'doc/**/*'
141
+ ]
142
+ PKG_FILES.exclude('doc/example/*.o')
143
+ PKG_FILES.exclude(%r{doc/example/main$})
144
+
145
+ if ! defined?(Gem)
146
+ puts "Package Target requires RubyGEMs"
147
+ else
148
+ spec = Gem::Specification.new do |s|
149
+
150
+ #### Basic information.
151
+
152
+ s.name = 'dtr'
153
+ s.version = $package_version
154
+ s.summary = "DTR is a distributed test runner to run tests on distributed computers for decreasing build time."
155
+
156
+ #### Dependencies and requirements.
157
+
158
+ s.add_dependency('daemons', '> 1.0.7')
159
+ #s.requirements << ""
160
+
161
+ #### Which files are to be included in this gem? Everything! (Except SVN directories.)
162
+
163
+ s.files = PKG_FILES.to_a.delete_if {|item| item.include?(".svn")}
164
+
165
+ #### Load-time details: library and application (you will need one or both).
166
+
167
+ s.require_path = 'lib' # Use these for libraries.
168
+
169
+ s.bindir = "bin" # Use these for applications.
170
+ s.executables = ["dtr"]
171
+ s.default_executable = "dtr"
172
+
173
+ #### Documentation and testing.
174
+
175
+ s.has_rdoc = true
176
+ s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
177
+ s.rdoc_options = rd.options
178
+
179
+ #### Author and project details.
180
+
181
+ s.author = "Li Xiao"
182
+ s.email = "swing1979@gmail.com"
183
+ s.homepage = "http://dtr.rubyforge.org"
184
+ s.rubyforge_project = "dtr"
185
+ # if ENV['CERT_DIR']
186
+ # s.signing_key = File.join(ENV['CERT_DIR'], 'gem-private_key.pem')
187
+ # s.cert_chain = [File.join(ENV['CERT_DIR'], 'gem-public_cert.pem')]
188
+ # end
189
+ end
190
+
191
+ package_task = Rake::GemPackageTask.new(spec) do |pkg|
192
+ #pkg.need_zip = true
193
+ #pkg.need_tar = true
194
+ end
195
+ end
196
+
197
+ # Misc tasks =========================================================
198
+
199
+ def count_lines(filename)
200
+ lines = 0
201
+ codelines = 0
202
+ open(filename) { |f|
203
+ f.each do |line|
204
+ lines += 1
205
+ next if line =~ /^\s*$/
206
+ next if line =~ /^\s*#/
207
+ codelines += 1
208
+ end
209
+ }
210
+ [lines, codelines]
211
+ end
212
+
213
+ def show_line(msg, lines, loc)
214
+ printf "%6s %6s %s\n", lines.to_s, loc.to_s, msg
215
+ end
216
+
217
+ desc "Count lines in the main DTR file"
218
+ task :lines do
219
+ total_lines = 0
220
+ total_code = 0
221
+ show_line("File Name", "LINES", "LOC")
222
+ SRC_RB.each do |fn|
223
+ lines, codelines = count_lines(fn)
224
+ show_line(fn, lines, codelines)
225
+ total_lines += lines
226
+ total_code += codelines
227
+ end
228
+ show_line("TOTAL", total_lines, total_code)
229
+ end
230
+
231
+ # Define an optional publish target in an external file. If the
232
+ # publish.rf file is not found, the publish targets won't be defined.
233
+
234
+ load "publish.rf" if File.exist? "publish.rf"
235
+
236
+ # Support Tasks ------------------------------------------------------
237
+
238
+ RUBY_FILES = FileList['**/*.rb'].exclude('pkg')
239
+
240
+ desc "Look for TODO and FIXME tags in the code"
241
+ task :todo do
242
+ RUBY_FILES.egrep(/#.*(FIXME|TODO|TBD)/)
243
+ end
244
+
245
+ desc "Look for Debugging print lines"
246
+ task :dbg do
247
+ RUBY_FILES.egrep(/\bDBG|\bbreakpoint\b/)
248
+ end
249
+
250
+ desc "List all ruby files"
251
+ task :rubyfiles do
252
+ puts RUBY_FILES
253
+ puts FileList['bin/*'].exclude('bin/*.rb')
254
+ end
255
+ task :rf => :rubyfiles
256
+
257
+ desc "Create a TAGS file"
258
+ task :tags => "TAGS"
259
+
260
+ TAGS = 'xctags -e'
261
+
262
+ file "TAGS" => RUBY_FILES do
263
+ puts "Makings TAGS"
264
+ sh "#{TAGS} #{RUBY_FILES}", :verbose => false
265
+ end
266
+
267
+ # --------------------------------------------------------------------
268
+ # Creating a release
269
+
270
+ task :update_site do
271
+ puts %x[scp -r html/* lixiao@rubyforge.org:/var/www/gforge-projects/dtr/]
272
+ end
273
+
274
+ task :noop
275
+
276
+ desc "[rel, reuse, reltest] Make a new release"
277
+ task :release => [
278
+ :prerelease,
279
+ :clobber,
280
+ :test_all,
281
+ :update_version,
282
+ :package,
283
+ :tag] do
284
+
285
+ announce
286
+ announce "**************************************************************"
287
+ announce "* Release #{$package_version} Complete."
288
+ announce "* Packages ready to upload."
289
+ announce "**************************************************************"
290
+ announce
291
+ end
292
+
293
+ # Validate that everything is ready to go for a release.
294
+ desc "[rel, reuse, reltest]"
295
+ task :prerelease do |t, rel, reuse, reltest|
296
+ $package_version = rel
297
+ announce
298
+ announce "**************************************************************"
299
+ announce "* Making RubyGem Release #{$package_version}"
300
+ announce "* (current version #{CURRENT_VERSION})"
301
+ announce "**************************************************************"
302
+ announce
303
+
304
+ # Is a release number supplied?
305
+ unless rel
306
+ fail "Usage: rake release[X.Y.Z] [REUSE=tag_suffix]"
307
+ end
308
+
309
+ # Is the release different than the current release.
310
+ # (or is REUSE set?)
311
+ if $package_version == CURRENT_VERSION && ! reuse
312
+ fail "Current version is #{$package_version}, must specify REUSE=tag_suffix to reuse version"
313
+ end
314
+
315
+ # Are all source files checked in?
316
+ if reltest
317
+ announce "Release Task Testing, skipping checked-in file test"
318
+ else
319
+ announce "Checking for unchecked-in files..."
320
+ data = `svn st`
321
+ unless data =~ /^$/
322
+ abort "svn status is not clean ... do you have unchecked-in files?"
323
+ end
324
+ announce "No outstanding checkins found ... OK"
325
+ end
326
+ end
327
+
328
+ desc "[rel, reuse, reltest]"
329
+ task :update_version => [:prerelease] do |t, rel, reuse, reltest|
330
+ if rel == CURRENT_VERSION
331
+ announce "No version change ... skipping version update"
332
+ else
333
+ announce "Updating DTR version to #{rel}"
334
+ open("lib/dtr.rb") do |dtrin|
335
+ open("lib/dtr.rb.new", "w") do |dtrout|
336
+ dtrin.each do |line|
337
+ if line =~ /^DTRVERSION\s*=\s*/
338
+ dtrout.puts "DTRVERSION = '#{rel}'"
339
+ else
340
+ dtrout.puts line
341
+ end
342
+ end
343
+ end
344
+ end
345
+ mv "lib/dtr.rb.new", "lib/dtr.rb"
346
+ if reltest
347
+ announce "Release Task Testing, skipping commiting of new version"
348
+ else
349
+ sh %{svn commit -m "Updated to version #{rel}" lib/dtr.rb} # "
350
+ end
351
+ end
352
+ end
353
+
354
+ desc "[rel, reuse, reltest] Tag all the CVS files with the latest release number (REL=x.y.z)"
355
+ task :tag => [:prerelease] do |t, rel, reuse, reltest|
356
+ reltag = "REL_#{rel.gsub(/\./, '_')}"
357
+ reltag << reuse.gsub(/\./, '_') if reuse
358
+ announce "Tagging Repository with [#{reltag}]"
359
+ if reltest
360
+ announce "Release Task Testing, skipping CVS tagging"
361
+ else
362
+ sh %{svn copy svn+ssh://rubyforge.org/var/svn/dtr/trunk svn+ssh://rubyforge.org/var/svn/dtr/tags/#{reltag} -m 'Commiting release #{reltag}'}
363
+ end
364
+ end
365
+
366
+ desc "Install the jamis RDoc template"
367
+ task :install_jamis_template do
368
+ require 'rbconfig'
369
+ dest_dir = File.join(Config::CONFIG['rubylibdir'], "rdoc/generators/template/html")
370
+ fail "Unabled to write to #{dest_dir}" unless File.writable?(dest_dir)
371
+ install "doc/jamis.rb", dest_dir, :verbose => true
372
+ end
373
+
374
+ task :c1 do
375
+ Dir.chdir('testdata') do
376
+ DTR.launch_runners(['c1'], nil)
377
+ end
378
+ end
379
+
380
+ task :c3 do
381
+ Dir.chdir('testdata') do
382
+ DTR.launch_runners(['c1', 'c2', 'c3'], nil)
383
+ end
384
+ end
385
+ task :c10 do
386
+ Dir.chdir('testdata') do
387
+ DTR.launch_runners(['c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'c10'], nil)
388
+ end
389
+ end
390
+
391
+ task :runners do
392
+ runners = DTR.runners
393
+ if runners.empty?
394
+ puts "No runner available!"
395
+ else
396
+ puts runners.collect{|r| r.name}.join(", ")
397
+ end
398
+ end
399
+
400
+ task :c2 do
401
+ DTROPTIONS[:names] = ['c1', 'c2']
402
+ DTROPTIONS[:setup] = nil
403
+ Dir.chdir('testdata') do
404
+ DTR.start_runners
405
+ end
406
+ end
407
+
408
+ task :server do
409
+ DTR.start_server
410
+ end
411
+
412
+ Rake::TestTask.new(:dtr) do |t|
413
+ t.libs << DTR.lib_path
414
+ t.test_files = FileList['dtr/inject_with_svn.rb', 'testdata/*.rb']
415
+ t.warning = true
416
+ t.verbose = false
417
+ end
418
+
419
+ require 'dtr/raketasks'
420
+
421
+ DTR::MPTask.new :mt do |t|
422
+ t.test_files = FileList['testdata/*.rb']
423
+ t.processes = 2
424
+ end
425
+
data/TODO ADDED
@@ -0,0 +1,8 @@
1
+ = DTR Project -- To Do List
2
+
3
+ Send suggestions for this list to swing1979@gmail.com
4
+
5
+ === To Do
6
+ 39. class doc(ri)?
7
+
8
+ (moved DONE list to CHANGES file)
data/bin/dtr ADDED
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'logger'
4
+ begin
5
+ require 'dtr'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'dtr'
9
+ end
10
+
11
+ NOTES = <<-NOTES
12
+ ----------------
13
+ Notes:
14
+ * The default value of server address is 'localhost'. If DTR Server start with 'localhost', it would not be found by remote machine. If you run the runner agent on remote machine, you should start the server and runner agent with same server address specified, e.g. dtr -s -a 10.18.1.1, dtr -r r1,r2 -a 10.18.1.1
15
+ * Runners specified by -r option will be started in different processes by the runner agent.
16
+ * You need install gem daemons to use -D option.
17
+ * When specify -D option, dtr_runners.pid/dtr_server.pid will be created in the directory to store the daemon process pid. And the output of the process will be print into *.output file.
18
+
19
+ DTR is a distributed test runner program for decreasing time of running ruby tests based on ruby 'test/unit' package.
20
+ For additional information, see http://dtr.rubyforge.org/
21
+ NOTES
22
+
23
+ opts = OptionParser.new do |opts|
24
+ opts.banner = "DTR usage: #{$0} [options]"
25
+ opts.separator ""
26
+ opts.separator "Synopsis:"
27
+ opts.separator "dtr -s"
28
+ opts.separator "dtr -r runner1_name,runner2_name"
29
+ opts.separator "dtr -a dtr_server_ip -m"
30
+ opts.separator ""
31
+ opts.separator "Options:"
32
+
33
+ opts.on_tail("-m", "--monitor", "Monitor the status of the dtr rinda server, e.g. dtr -a 10.11.1.2 -m") do
34
+ DTROPTIONS[:monitor] = true
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
43
+ end
44
+
45
+ opts.on_tail("-s", "--server", "Start DTR service server. There must be a DTR server running.") do
46
+ DTROPTIONS[:start_server] = true
47
+ end
48
+
49
+ opts.on("-p", "--port PORT", "Port number DTR will listen to. Default is 3344.") do |port|
50
+ DTR.port = port
51
+ end
52
+
53
+ opts.on("-r runner1_name,runner2_name", Array, "Start DTR test runner agent with unique runner names.") do |names|
54
+ DTROPTIONS[:names] = names.collect{|name| name.untaint}
55
+ end
56
+
57
+ opts.on("-a", "--server_address ADDRESS", "Specify dtr server address, domain name or ip address, e.g. 192.168.0.1. Default is 'localhost'.") do |address|
58
+ if (!address.nil?) && (!address.empty?)
59
+ DTR.broadcast_list = [address]
60
+ end
61
+ end
62
+
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
+ DTROPTIONS[:setup] = command.untaint
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
73
+ end
74
+
75
+ opts.on_tail("-R", "--stop_runners", "Stop runners run in daemon mode.") do
76
+ DTR.stop_runners_daemon_mode
77
+ end
78
+
79
+ opts.on_tail("-d", "--debug", "output debug log") do
80
+ DTROPTIONS[:log_level] = Logger::DEBUG
81
+ end
82
+
83
+ opts.on_tail("-v", "--version", "Show version") do
84
+ puts "dtr, version " + DTRVERSION
85
+ end
86
+
87
+ opts.on_tail("-h", "--help", "Show this help doc") do
88
+ puts opts
89
+ puts NOTES
90
+ end
91
+ end
92
+
93
+ no_argv = ARGV.empty?
94
+
95
+ opts.parse!
96
+
97
+ if no_argv
98
+ puts opts
99
+ puts NOTES
100
+ end
101
+
102
+ if DTROPTIONS[:names]
103
+ if DTROPTIONS[:daemon]
104
+ DTR.start_runners_daemon_mode
105
+ else
106
+ DTR.start_runners
107
+ end
108
+ end
109
+
110
+ if DTROPTIONS[:start_server]
111
+ if DTROPTIONS[:daemon]
112
+ DTR.start_server_daemon_mode
113
+ else
114
+ DTR.start_server
115
+ end
116
+ 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