relex-specjour 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/.dev ADDED
@@ -0,0 +1,3 @@
1
+ export RUBYLIB=`pwd`/lib
2
+ export RUBYOPT=rubygems
3
+ export PATH=`pwd`/bin:$PATH
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ .specjour
23
+ spec/spec.opts
data/History.markdown ADDED
@@ -0,0 +1,48 @@
1
+ History
2
+ =======
3
+ 0.2.5
4
+ -----
5
+ *2010-05-13*
6
+
7
+ * [changed] The rails plugin now runs in a Rails.configuration.after_intialize
8
+ block
9
+
10
+ 0.2.4
11
+ -----
12
+ *2010-05-10*
13
+
14
+ * [added] Correct exit status
15
+ * [fixed] Will reconnect when connection is lost while requesting tests
16
+
17
+ 0.2.3
18
+ -----
19
+ *2010-04-25*
20
+
21
+ * [fixed] Absolute paths in rsyncd.conf restrict portability. The rsync daemon
22
+ completely fails when it can't find the path to serve which typically happens
23
+ running specjour on another computer. Remove your rsyncd.conf to regenerate a
24
+ new one. Back it up first if you've made changes to it.
25
+ **Backwards Incompatible**
26
+
27
+ * [fixed] CPU core detection works on OSX Core i7 (thanks Hashrocket!)
28
+
29
+ 0.2.2
30
+ -----
31
+ *2010-04-22*
32
+
33
+ * [added] Backtrace for cucumber failures
34
+
35
+ 0.2.1
36
+ -----
37
+ *2010-04-21*
38
+
39
+ * [added] The rsync daemon configuration file now lives in
40
+ project_path/.specjour/rsyncd.conf. Edit your rsync exclusions there.
41
+ * [fixed] Don't report connection errors when CTRL-C is sent.
42
+
43
+ 0.2.0
44
+ -----
45
+ *2010-04-20*
46
+
47
+ * [added] Cucumber support. `rake specjour:cucumber`
48
+ * [added] CPU Core detection, use -w to override with less or more workers
data/MIT_LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Sandro Turriate
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,104 @@
1
+ # Specjour
2
+
3
+ ## FUCK SETI. Run specs with your spare CPU cycles.
4
+
5
+ _Distribute your spec suite amongst your LAN via Bonjour._
6
+
7
+ 1. Spin up a manager on each machine that can run your specs.
8
+ 2. Start a dispatcher in your project directory.
9
+ 3. Say farewell to your long coffee breaks.
10
+
11
+ ## Requirements
12
+ * Bonjour or DNSSD (the capability and the gem)
13
+ * Rsync (system command used)
14
+ * Rspec (officially v1.3.0)
15
+
16
+ ## Installation
17
+ gem install specjour
18
+
19
+ ## Start a manager
20
+ Running `specjour` on the command-line will start a manager which advertises that it's ready to run specs. By default, the manager will use your system cores to determine the number of workers to use. Two cores equals two workers. If you only want to dedicate 1 core to running specs, use `$ specjour --workers 1`.
21
+
22
+ $ specjour
23
+
24
+ ## Setup the dispatcher
25
+ Require specjour's rake tasks in your project's `Rakefile`.
26
+
27
+ require 'specjour/tasks/specjour'
28
+
29
+ ## Distribute the specs
30
+ Run the rake task to distribute the specs among the managers you started.
31
+
32
+ $ rake specjour
33
+
34
+ ## Distribute the features
35
+ Run the rake task to distribute the features among the managers you started.
36
+
37
+ $ rake specjour:cucumber
38
+
39
+ ## Rails
40
+ Each worker should run their specs in an isolated database. Modify the test database name in your `config/database.yml` to include the following environment variable (Influenced by [parallel\_tests](http://github.com/grosser/parallel_tests)):
41
+
42
+ test:
43
+ database: blog_test<%=ENV['TEST_ENV_NUMBER']%>
44
+
45
+ Add the specjour gem to your project:
46
+
47
+ config.gem 'specjour'
48
+
49
+ Doing this enables a rails plugin wherein each worker will attempt to clear its database tables before running any specs via `DELETE FROM <table_name>;`. Additionally, test databases will be created if they don't exist (i.e. `CREATE DATABASE blog_test8` for the 8th worker) and your schema will be loaded when the database is out of date.
50
+
51
+ ### Customizing database setup
52
+ If the plugin doesn't set up the database properly for your test suite, bypass it entirely. Remove specjour as a project gem and create your own initializer to setup the database. Specjour sets the environment variable PREPARE\_DB when it runs your specs so you can look for that when setting up the database.
53
+
54
+ # config/initializers/specjour.rb
55
+
56
+ if ENV['PREPARE_DB']
57
+ load 'Rakefile'
58
+
59
+ # clear the db and load db/seeds.rb
60
+ Rake::Task['db:reset'].invoke
61
+ end
62
+
63
+ ## Only listen to supported projects
64
+ By default, a manager will listen to all projects trying to distribute specs over the network. Sometimes you'll only want a manager to respond to one specific spec suite. You can accomplish this with the `--projects` flag.
65
+
66
+ $ specjour --projects bizconf # only run specs for the bizconf project
67
+
68
+ You could also listen to multiple projects:
69
+
70
+ $ specjour --projects bizconf,workbeast # only run specs for the bizconf and workbeast projects
71
+
72
+ ## Customize what gets rsync'd
73
+ The standard rsync configuration file may be too broad for your
74
+ project. If you find you're rsyncing gigs of extraneous data from your public
75
+ directory, add an exclusion to your projects rsyncd.conf file.
76
+
77
+ $ vi workbeast/.specjour/rsyncd.conf
78
+
79
+ ## Use one machine
80
+ Distributed testing doesn't have to happen over multiple machines, just multiple processes. Specjour is an excellent candidiate for running 4 tests at once on one machine with 4 cores. Just run `$ specjour` in one window and `$ rake specjour` in another.
81
+
82
+ ## Thanks
83
+
84
+ * shayarnett - Cucumber support, pairing and other various patches
85
+ * voxdolo - Endless support, alpha testing, various patches
86
+ * leshill - Made rsync daemon configurable
87
+ * testjour - Ripped off your name
88
+ * parallel\_tests - Made my test suite twice as fast
89
+
90
+ ## Note on Patches/Pull Requests
91
+
92
+ * Fork the project.
93
+ * `$ source .dev` to ensure you're using the local specjour binary, not the
94
+ rubygems version
95
+ * Make your feature addition or bug fix.
96
+ * Add tests for it. This is important so I don't break it in a
97
+ future version unintentionally.
98
+ * Commit, do not mess with rakefile, version, or history.
99
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
100
+ * Send me a pull request. Bonus points for topic branches.
101
+
102
+ ## Copyright
103
+
104
+ Copyright (c) 2010 Sandro Turriate. See MIT\_LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "relex-specjour"
8
+ gem.summary = %Q{Distribute your spec suite amongst your LAN via Bonjour.}
9
+ gem.description = %Q{Distribute your spec suite amongst your LAN via Bonjour.}
10
+ gem.email = "colintimmermans@gmail.com"
11
+ gem.homepage = "http://github.com/sandro/specjour"
12
+ gem.authors = ["Sandro Turriate", "Colin Timmermans"]
13
+ gem.add_dependency "dnssd", "1.3.1"
14
+ gem.add_dependency "rspec"
15
+ gem.add_development_dependency "rspec", "1.3.0"
16
+ gem.add_development_dependency "rr", "0.10.11"
17
+ gem.add_development_dependency "yard", "0.5.3"
18
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
+ end
24
+
25
+ require 'spec/rake/spectask'
26
+ Spec::Rake::SpecTask.new(:spec) do |spec|
27
+ spec.libs << 'lib' << 'spec'
28
+ spec.spec_files = FileList['spec/**/*_spec.rb']
29
+ end
30
+
31
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
32
+ spec.libs << 'lib' << 'spec'
33
+ spec.pattern = 'spec/**/*_spec.rb'
34
+ spec.rcov = true
35
+ end
36
+
37
+ task :spec => :check_dependencies
38
+
39
+ task :default => :spec
40
+
41
+ begin
42
+ require 'yard'
43
+ YARD::Rake::YardocTask.new
44
+ rescue LoadError
45
+ task :yardoc do
46
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
47
+ end
48
+ end
49
+
50
+ $:.unshift(File.dirname(__FILE__) + "/lib")
51
+ require 'specjour/tasks/specjour'
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.6
data/bin/specjour ADDED
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ require 'specjour'
4
+
5
+ options = {:batch_size => 1}
6
+
7
+ optparse = OptionParser.new do |opts|
8
+ opts.banner = "Usage: specjour [options]"
9
+
10
+ opts.on('-w', '--workers WORKERS', Numeric, "Number of WORKERS to spin up, defaults to available cores") do |n|
11
+ options[:worker_size] = n
12
+ end
13
+
14
+ opts.on('-b', '--batch-size [SIZE]', Integer, "Number of specs to run before reporting back to the dispatcher, defaults to #{options[:batch_size]}") do |n|
15
+ options[:batch_size] = n
16
+ end
17
+
18
+ opts.on('-p', '--projects PROJECTS', Array, "Only run specs for these comma delimited project names, i.e. workbeast,taigan") do |project_names|
19
+ options[:registered_projects] = project_names
20
+ end
21
+
22
+ opts.on('--do-work OPTIONS', Array, 'INTERNAL USE ONLY') do |args|
23
+ options[:worker_args] = args[0], args[1], args[2]
24
+ end
25
+
26
+ opts.on('--log', TrueClass, 'print debug messages to stdout') do |val|
27
+ Specjour.new_logger Logger::DEBUG
28
+ end
29
+
30
+ opts.on_tail('-v', '--version', 'Show the version of specjour') do
31
+ abort Specjour::VERSION
32
+ end
33
+
34
+ opts.on_tail("-h", "--help", "Show this message") do
35
+ summary = opts.to_a
36
+ summary.first << "\n"
37
+ abort summary.reject {|s| s =~ /INTERNAL/}.join
38
+ end
39
+ end
40
+
41
+ optparse.parse!
42
+
43
+ abort(%(ERROR: I don't understand the following flags: "#{ARGV.join(', ')}")) if ARGV.any?
44
+
45
+ if options[:worker_args]
46
+ options[:worker_args] << options[:batch_size]
47
+ Specjour::Worker.new(*options[:worker_args]).run
48
+ else
49
+ options[:worker_size] ||= Specjour::CPU.cores
50
+ Specjour::Manager.new(options).start
51
+ end
data/lib/specjour.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'drb'
2
+
3
+ autoload :URI, 'uri'
4
+ autoload :Forwardable, 'forwardable'
5
+ autoload :GServer, 'gserver'
6
+ autoload :Timeout, 'timeout'
7
+ autoload :Benchmark, 'benchmark'
8
+ autoload :Logger, 'logger'
9
+ autoload :Socket, 'socket'
10
+
11
+ module Specjour
12
+ autoload :CPU, 'specjour/cpu'
13
+ autoload :Connection, 'specjour/connection'
14
+ autoload :Dispatcher, 'specjour/dispatcher'
15
+ autoload :Manager, 'specjour/manager'
16
+ autoload :OpenStruct, 'ostruct'
17
+ autoload :Printer, 'specjour/printer'
18
+ autoload :Protocol, 'specjour/protocol'
19
+ autoload :RsyncDaemon, 'specjour/rsync_daemon'
20
+ autoload :SocketHelpers, 'specjour/socket_helpers'
21
+ autoload :Worker, 'specjour/worker'
22
+
23
+ autoload :Cucumber, 'specjour/cucumber'
24
+ autoload :Rspec, 'specjour/rspec'
25
+
26
+ VERSION = "0.2.5".freeze
27
+
28
+ class Error < StandardError; end
29
+
30
+ def self.logger
31
+ @logger ||= new_logger
32
+ end
33
+
34
+ def self.new_logger(level = Logger::UNKNOWN)
35
+ @logger = Logger.new $stdout
36
+ @logger.level = level
37
+ @logger
38
+ end
39
+
40
+ def self.log?
41
+ logger.level != Logger::UNKNOWN
42
+ end
43
+ end
@@ -0,0 +1,85 @@
1
+ module Specjour
2
+ class Connection
3
+ include Protocol
4
+ extend Forwardable
5
+
6
+ attr_reader :uri
7
+ attr_writer :socket
8
+
9
+ def_delegators :socket, :flush, :closed?, :gets, :each
10
+
11
+ def self.wrap(established_connection)
12
+ host, port = established_connection.peeraddr.values_at(3,1)
13
+ connection = new URI::Generic.build(:host => host, :port => port)
14
+ connection.socket = established_connection
15
+ connection
16
+ end
17
+
18
+ def initialize(uri)
19
+ @uri = uri
20
+ end
21
+
22
+ alias to_str to_s
23
+
24
+ def connect
25
+ timeout { connect_socket }
26
+ end
27
+
28
+ def disconnect
29
+ socket.close
30
+ end
31
+
32
+ def socket
33
+ @socket ||= connect
34
+ end
35
+
36
+ def timeout(&block)
37
+ Timeout.timeout(2, &block)
38
+ rescue Timeout::Error
39
+ raise Error, "Connection to dispatcher timed out"
40
+ end
41
+
42
+ def next_test
43
+ will_reconnect do
44
+ send_message(:ready)
45
+ load_object socket.gets(TERMINATOR)
46
+ end
47
+ end
48
+
49
+ def print(arg)
50
+ will_reconnect do
51
+ socket.print dump_object(arg)
52
+ end
53
+ end
54
+
55
+ def puts(arg)
56
+ print(arg << "\n")
57
+ end
58
+
59
+ def send_message(method_name, *args)
60
+ print([method_name, *args])
61
+ flush
62
+ end
63
+
64
+ protected
65
+
66
+ def connect_socket
67
+ @socket = TCPSocket.open(uri.host, uri.port)
68
+ rescue Errno::ECONNREFUSED => error
69
+ Specjour.logger.debug "Could not connect to #{uri.to_s}\n#{error.inspect}"
70
+ retry
71
+ end
72
+
73
+ def reconnect
74
+ socket.close unless socket.closed?
75
+ connect
76
+ end
77
+
78
+ def will_reconnect(&block)
79
+ block.call
80
+ rescue SystemCallError => error
81
+ reconnect
82
+ retry
83
+ end
84
+ end
85
+ end