invo-sporknife 0.1.0.1 → 0.1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +12 -40
- data/bin/{spork → sporknife} +0 -0
- data/features/at_exit_during_each_run.feature +2 -3
- data/features/cucumber_rails_integration.feature +18 -7
- data/features/rails_delayed_loading_workarounds.feature +13 -48
- data/features/rspec_rails_integration.feature +9 -8
- data/features/spork_debugger.feature +6 -6
- data/features/steps/rails_steps.rb +4 -18
- data/features/steps/sandbox_steps.rb +5 -5
- data/features/support/env.rb +19 -13
- data/lib/spork.rb +12 -12
- data/lib/spork/app_framework.rb +1 -4
- data/lib/spork/app_framework/rails.rb +117 -41
- data/lib/spork/app_framework/rails_stub_files/application.rb +1 -0
- data/lib/spork/app_framework/rails_stub_files/application_controller.rb +22 -0
- data/lib/spork/app_framework/rails_stub_files/application_helper.rb +3 -0
- data/lib/spork/run_strategy.rb +1 -1
- data/lib/spork/run_strategy/magazine.rb +25 -44
- data/lib/spork/run_strategy/magazine/magazine_slave_provider.rb +19 -16
- data/lib/spork/runner.rb +1 -1
- data/lib/spork/server.rb +0 -2
- data/lib/spork/test_framework.rb +5 -5
- data/lib/spork/test_framework/cucumber.rb +4 -4
- data/spec/spec_helper.rb +2 -7
- data/spec/spork/app_framework/rails_spec.rb +4 -4
- data/spec/spork/forker_spec.rb +1 -1
- data/spec/spork/run_strategy/forking_spec.rb +1 -1
- data/spec/spork/test_framework/cucumber_spec.rb +1 -1
- data/spec/spork/test_framework/rspec_spec.rb +1 -1
- data/spec/spork/test_framework_spec.rb +24 -0
- data/spec/spork_spec.rb +5 -7
- metadata +12 -18
- data/Gemfile +0 -6
- data/features/gemfiles/rails3.0/Gemfile +0 -10
- data/features/gemfiles/rails3.0/Gemfile.lock +0 -116
- data/features/support/bundler_helpers.rb +0 -41
- data/spec/spork/test_framework_shared_examples.rb +0 -23
@@ -17,7 +17,7 @@ When /^the contents of "([^\"]*)" are changed to:$/ do |file_name, file_content|
|
|
17
17
|
end
|
18
18
|
|
19
19
|
# the following code appears in "config/environment.rb" after /Rails::Initializer.run/:
|
20
|
-
Given /^the following code appears in "([^\"]*)" after \/([
|
20
|
+
Given /^the following code appears in "([^\"]*)" after \/([^\\\/]*)\/:$/ do |file_name, regex, content|
|
21
21
|
regex = Regexp.new(regex)
|
22
22
|
in_current_dir do
|
23
23
|
content_lines = File.read(file_name).split("\n")
|
@@ -31,12 +31,12 @@ Given /^the following code appears in "([^\"]*)" after \/([^\/]*)\/:$/ do |file_
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
When /^I run (spork|
|
35
|
-
run(
|
34
|
+
When /^I run (spork|spec|cucumber)(| .*)$/ do |command, args|
|
35
|
+
run(localized_command(command, args))
|
36
36
|
end
|
37
37
|
|
38
|
-
When /^I run this in the background: (spork|
|
39
|
-
@background_script = run_in_background(
|
38
|
+
When /^I run this in the background: (spork|spec|cucumber)(| .*)$/ do |command, args|
|
39
|
+
@background_script = run_in_background(localized_command(command, args))
|
40
40
|
end
|
41
41
|
|
42
42
|
When /^I fire up a spork instance with "spork(.*)"$/ do |spork_opts|
|
data/features/support/env.rb
CHANGED
@@ -1,20 +1,17 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'pathname'
|
3
2
|
require 'fileutils'
|
4
3
|
require 'forwardable'
|
5
4
|
require 'tempfile'
|
6
|
-
require '
|
5
|
+
require 'spec/expectations'
|
7
6
|
require 'timeout'
|
7
|
+
require 'spork'
|
8
8
|
|
9
9
|
require(File.dirname(__FILE__) + '/background_job.rb')
|
10
10
|
|
11
|
-
SPORK_ROOT = Pathname.new(File.expand_path('../../', File.dirname(__FILE__)))
|
12
11
|
class SporkWorld
|
12
|
+
BINARY = File.expand_path(File.dirname(__FILE__) + '/../../bin/spork')
|
13
13
|
RUBY_BINARY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
|
14
|
-
|
15
|
-
SANDBOX_DIR = SPORK_ROOT + "tmp/sandbox"
|
16
|
-
GEMFILES_ROOT = SPORK_ROOT + "features/gemfiles"
|
17
|
-
SPORK_LIBDIR = SPORK_ROOT + "lib"
|
14
|
+
SANDBOX_DIR = File.expand_path(File.join(File.dirname(__FILE__), '../../tmp/sandbox'))
|
18
15
|
|
19
16
|
extend Forwardable
|
20
17
|
def_delegators SporkWorld, :sandbox_dir, :spork_lib_dir
|
@@ -57,11 +54,23 @@ class SporkWorld
|
|
57
54
|
Dir.chdir(@current_dir, &block)
|
58
55
|
end
|
59
56
|
|
57
|
+
def localized_command(command, args)
|
58
|
+
case command
|
59
|
+
when 'spork'
|
60
|
+
command = SporkWorld::BINARY
|
61
|
+
when 'cucumber'
|
62
|
+
command = Cucumber::BINARY
|
63
|
+
else
|
64
|
+
command = %x{which #{command}}.chomp
|
65
|
+
end
|
66
|
+
"#{SporkWorld::RUBY_BINARY} -I #{Cucumber::LIBDIR} #{command} #{args}"
|
67
|
+
end
|
68
|
+
|
60
69
|
def run(command)
|
61
70
|
stderr_file = Tempfile.new('spork')
|
62
71
|
stderr_file.close
|
63
72
|
in_current_dir do
|
64
|
-
@last_stdout =
|
73
|
+
@last_stdout = `#{command} 2> #{stderr_file.path}`
|
65
74
|
@last_exit_status = $?.exitstatus
|
66
75
|
end
|
67
76
|
@last_stderr = IO.read(stderr_file.path)
|
@@ -69,7 +78,7 @@ class SporkWorld
|
|
69
78
|
|
70
79
|
def run_in_background(command)
|
71
80
|
in_current_dir do
|
72
|
-
@background_job = BackgroundJob.run(
|
81
|
+
@background_job = BackgroundJob.run(command)
|
73
82
|
end
|
74
83
|
@background_jobs << @background_job
|
75
84
|
@background_job
|
@@ -84,11 +93,8 @@ class SporkWorld
|
|
84
93
|
@background_jobs.clear
|
85
94
|
@background_job = nil
|
86
95
|
end
|
87
|
-
end
|
88
|
-
|
89
|
-
require(SPORK_ROOT + "features/support/bundler_helpers.rb")
|
90
|
-
BundlerHelpers.set_gemfile(ENV["GEMFILE"])
|
91
96
|
|
97
|
+
end
|
92
98
|
|
93
99
|
World do
|
94
100
|
SporkWorld.new
|
data/lib/spork.rb
CHANGED
@@ -30,7 +30,7 @@ module Spork
|
|
30
30
|
# * +prevent_double_run+ - Pass false to disable double run prevention
|
31
31
|
def each_run(prevent_double_run = true, &block)
|
32
32
|
return if prevent_double_run && already_ran?(caller.first)
|
33
|
-
if state == :
|
33
|
+
if @state == :using_spork
|
34
34
|
each_run_procs << block
|
35
35
|
else
|
36
36
|
yield
|
@@ -47,23 +47,28 @@ module Spork
|
|
47
47
|
after_each_run_procs << block
|
48
48
|
end
|
49
49
|
|
50
|
+
# Used by the server. Sets the state to activate spork. Otherwise, prefork and each_run are run in passive mode, allowing specs without a Spork server.
|
51
|
+
def using_spork!
|
52
|
+
@state = :using_spork
|
53
|
+
end
|
54
|
+
|
50
55
|
def using_spork?
|
51
|
-
state
|
56
|
+
@state == :using_spork
|
52
57
|
end
|
53
58
|
|
59
|
+
# Used by the server. Returns the current state of Spork.
|
54
60
|
def state
|
55
61
|
@state ||= :not_using_spork
|
56
62
|
end
|
57
63
|
|
58
64
|
# Used by the server. Called when loading the prefork blocks of the code.
|
59
65
|
def exec_prefork(&block)
|
60
|
-
|
66
|
+
using_spork!
|
61
67
|
yield
|
62
68
|
end
|
63
69
|
|
64
70
|
# Used by the server. Called to run all of the prefork blocks.
|
65
71
|
def exec_each_run(&block)
|
66
|
-
@state = :run
|
67
72
|
activate_after_each_run_at_exit_hook
|
68
73
|
each_run_procs.each { |p| p.call }
|
69
74
|
each_run_procs.clear
|
@@ -83,9 +88,9 @@ module Spork
|
|
83
88
|
|
84
89
|
klass.class_eval <<-EOF, __FILE__, __LINE__ + 1
|
85
90
|
alias :#{method_name_without_spork} :#{method_name} unless method_defined?(:#{method_name_without_spork})
|
86
|
-
def #{method_name}(*args
|
91
|
+
def #{method_name}(*args)
|
87
92
|
Spork.each_run(false) do
|
88
|
-
#{method_name_without_spork}(*args
|
93
|
+
#{method_name_without_spork}(*args)
|
89
94
|
end
|
90
95
|
end
|
91
96
|
EOF
|
@@ -131,11 +136,7 @@ module Spork
|
|
131
136
|
def expanded_caller(caller_line)
|
132
137
|
file, line = caller_line.split(/:(\d+)/)
|
133
138
|
line.gsub(/:.+/, '')
|
134
|
-
|
135
|
-
if ENV['OS'] == 'Windows_NT' # windows
|
136
|
-
expanded = expanded[2..-1]
|
137
|
-
end
|
138
|
-
expanded
|
139
|
+
File.expand_path(file, Dir.pwd) + ":" + line
|
139
140
|
end
|
140
141
|
|
141
142
|
def already_ran?(caller_script_and_line)
|
@@ -149,7 +150,6 @@ module Spork
|
|
149
150
|
end
|
150
151
|
|
151
152
|
def after_each_run_procs
|
152
|
-
spookie
|
153
153
|
@after_each_run_procs ||= []
|
154
154
|
end
|
155
155
|
end
|
data/lib/spork/app_framework.rb
CHANGED
@@ -9,10 +9,7 @@ class Spork::AppFramework
|
|
9
9
|
File.exist?("config/boot.rb") && File.read("config/boot.rb").include?('PADRINO')
|
10
10
|
},
|
11
11
|
:Rails => lambda {
|
12
|
-
File.exist?("config/environment.rb") && (
|
13
|
-
File.read("config/environment.rb").include?('RAILS_GEM_VERSION') ||
|
14
|
-
(File.exist?("config/application.rb") && File.read("config/application.rb").include?("Rails::Application"))
|
15
|
-
)
|
12
|
+
File.exist?("config/environment.rb") && File.read("config/environment.rb").include?('RAILS_GEM_VERSION')
|
16
13
|
}
|
17
14
|
} unless defined? SUPPORTED_FRAMEWORKS
|
18
15
|
|
@@ -1,5 +1,118 @@
|
|
1
1
|
class Spork::AppFramework::Rails < Spork::AppFramework
|
2
2
|
|
3
|
+
# TODO - subclass this out to handle different versions of rails
|
4
|
+
# Also... this is the nastiest duck punch ever. Clean this up.
|
5
|
+
module NinjaPatcher
|
6
|
+
def self.included(klass)
|
7
|
+
klass.class_eval do
|
8
|
+
unless method_defined?(:load_environment_without_spork)
|
9
|
+
alias :load_environment_without_spork :load_environment
|
10
|
+
alias :load_environment :load_environment_with_spork
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.run_with_spork(*args, &block) # it's all fun and games until someone gets an eye poked out
|
14
|
+
if ENV['RAILS_ENV']
|
15
|
+
Object.send(:remove_const, :RAILS_ENV)
|
16
|
+
Object.const_set(:RAILS_ENV, ENV['RAILS_ENV'].dup)
|
17
|
+
end
|
18
|
+
run_without_spork(*args, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
class << self
|
22
|
+
unless method_defined?(:run_without_spork)
|
23
|
+
alias :run_without_spork :run
|
24
|
+
alias :run :run_with_spork
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def load_environment_with_spork
|
31
|
+
result = load_environment_without_spork
|
32
|
+
install_hooks
|
33
|
+
result
|
34
|
+
end
|
35
|
+
|
36
|
+
def install_hooks
|
37
|
+
auto_reestablish_db_connection
|
38
|
+
delay_observer_loading
|
39
|
+
delay_app_preload
|
40
|
+
delay_application_controller_loading
|
41
|
+
delay_route_loading
|
42
|
+
delay_eager_view_loading
|
43
|
+
end
|
44
|
+
|
45
|
+
def reset_rails_env
|
46
|
+
return unless ENV['RAILS_ENV']
|
47
|
+
Object.send(:remove_const, :RAILS_ENV)
|
48
|
+
Object.const_set(:RAILS_ENV, ENV['RAILS_ENV'].dup)
|
49
|
+
end
|
50
|
+
|
51
|
+
def delay_observer_loading
|
52
|
+
if ::Rails::Initializer.instance_methods.map(&:to_sym).include?(:load_observers)
|
53
|
+
Spork.trap_method(::Rails::Initializer, :load_observers)
|
54
|
+
end
|
55
|
+
if Object.const_defined?(:ActionController)
|
56
|
+
require "action_controller/dispatcher.rb"
|
57
|
+
Spork.trap_class_method(::ActionController::Dispatcher, :define_dispatcher_callbacks) if ActionController::Dispatcher.respond_to?(:define_dispatcher_callbacks)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def delay_app_preload
|
62
|
+
if ::Rails::Initializer.instance_methods.map(&:to_sym).include?(:load_application_classes)
|
63
|
+
Spork.trap_method(::Rails::Initializer, :load_application_classes)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def delay_application_controller_loading
|
68
|
+
if application_controller_source = ["#{Dir.pwd}/app/controllers/application.rb", "#{Dir.pwd}/app/controllers/application_controller.rb"].find { |f| File.exist?(f) }
|
69
|
+
application_helper_source = "#{Dir.pwd}/app/helpers/application_helper.rb"
|
70
|
+
load_paths = (::ActiveSupport.const_defined?(:Dependencies) ? ::ActiveSupport::Dependencies : ::Dependencies).load_paths
|
71
|
+
load_paths.unshift(File.expand_path('rails_stub_files', File.dirname(__FILE__)))
|
72
|
+
Spork.each_run do
|
73
|
+
require application_controller_source
|
74
|
+
require application_helper_source if File.exist?(application_helper_source)
|
75
|
+
# update the rails magic to refresh the module
|
76
|
+
ApplicationController.send(:helper, ApplicationHelper)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def auto_reestablish_db_connection
|
82
|
+
if Object.const_defined?(:ActiveRecord)
|
83
|
+
Spork.each_run do
|
84
|
+
# rails lib/test_help.rb is very aggressive about overriding RAILS_ENV and will switch it back to test after the cucumber env was loaded
|
85
|
+
reset_rails_env
|
86
|
+
ActiveRecord::Base.establish_connection
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def delay_route_loading
|
92
|
+
if ::Rails::Initializer.instance_methods.map(&:to_sym).include?(:initialize_routing)
|
93
|
+
Spork.trap_method(::Rails::Initializer, :initialize_routing)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def delay_eager_view_loading
|
98
|
+
# So, in testing mode it seems it would be optimal to not eager load
|
99
|
+
# views (as your may only run a test that uses one or two views).
|
100
|
+
# However, I decided to delay eager loading rather than force it to
|
101
|
+
# disable because you may wish to eager load your views (I.E. you're
|
102
|
+
# testing concurrency)
|
103
|
+
|
104
|
+
# Rails 2.3.x +
|
105
|
+
if defined?(::ActionView::Template::EagerPath)
|
106
|
+
Spork.trap_method(::ActionView::Template::EagerPath, :load!)
|
107
|
+
end
|
108
|
+
# Rails 2.2.x
|
109
|
+
if defined?(::ActionView::PathSet::Path)
|
110
|
+
Spork.trap_method(::ActionView::PathSet::Path, :load)
|
111
|
+
end
|
112
|
+
# Rails 2.0.5 - 2.1.x don't appear to eager cache views.
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
3
116
|
def preload(&block)
|
4
117
|
STDERR.puts "Preloading Rails environment"
|
5
118
|
STDERR.flush
|
@@ -18,10 +131,6 @@ class Spork::AppFramework::Rails < Spork::AppFramework
|
|
18
131
|
@boot_file ||= File.join(File.dirname(environment_file), 'boot')
|
19
132
|
end
|
20
133
|
|
21
|
-
def application_file
|
22
|
-
@application_file ||= File.join(File.dirname(environment_file), 'application')
|
23
|
-
end
|
24
|
-
|
25
134
|
def environment_contents
|
26
135
|
@environment_contents ||= File.read(environment_file)
|
27
136
|
end
|
@@ -30,7 +139,7 @@ class Spork::AppFramework::Rails < Spork::AppFramework
|
|
30
139
|
@vendor ||= File.expand_path("vendor/rails", Dir.pwd)
|
31
140
|
end
|
32
141
|
|
33
|
-
def
|
142
|
+
def version
|
34
143
|
@version ||= (
|
35
144
|
if /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/.match(environment_contents)
|
36
145
|
$1
|
@@ -41,42 +150,9 @@ class Spork::AppFramework::Rails < Spork::AppFramework
|
|
41
150
|
end
|
42
151
|
|
43
152
|
def preload_rails
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
require application_file
|
49
|
-
::Rails.application
|
50
|
-
::Rails::Engine.class_eval do
|
51
|
-
def eager_load!
|
52
|
-
# turn off eager_loading, all together
|
53
|
-
end
|
54
|
-
end
|
55
|
-
# Spork.trap_method(::AbstractController::Helpers::ClassMethods, :helper)
|
56
|
-
Spork.trap_method(::ActiveModel::Observing::ClassMethods, :instantiate_observers)
|
57
|
-
Spork.each_run { ActiveRecord::Base.establish_connection rescue nil } if Object.const_defined?(:ActiveRecord)
|
58
|
-
|
59
|
-
|
60
|
-
AbstractController::Helpers::ClassMethods.module_eval do
|
61
|
-
def helper(*args, &block)
|
62
|
-
([args].flatten - [:all]).each do |arg|
|
63
|
-
next unless arg.is_a?(String)
|
64
|
-
filename = arg + "_helper"
|
65
|
-
unless ::ActiveSupport::Dependencies.search_for_file(filename)
|
66
|
-
# this error message must raise in the format such that LoadError#path returns the filename
|
67
|
-
raise LoadError.new("Missing helper file helpers/%s.rb" % filename)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
Spork.each_run(false) do
|
72
|
-
modules_for_helpers(args).each do |mod|
|
73
|
-
add_template_helper(mod)
|
74
|
-
end
|
75
|
-
|
76
|
-
_helpers.module_eval(&block) if block_given?
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
153
|
+
Object.const_set(:RAILS_GEM_VERSION, version) if version
|
154
|
+
require boot_file
|
155
|
+
::Rails::Initializer.send(:include, Spork::AppFramework::Rails::NinjaPatcher)
|
80
156
|
end
|
81
157
|
|
82
158
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
load(File.dirname(__FILE__) + "/application_controller.rb")
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# This is a stub used to help Spork delay the loading of the real ApplicationController
|
2
|
+
class ::ApplicationController < ActionController::Base
|
3
|
+
@@preloading = true
|
4
|
+
class << self
|
5
|
+
def inherited(klass)
|
6
|
+
(@_descendants ||= []) << klass if @@preloading
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def reapply_inheritance!
|
11
|
+
@@preloading = false
|
12
|
+
Array(@_descendants).each do |descendant|
|
13
|
+
descendant.master_helper_module.send(:include, master_helper_module)
|
14
|
+
descendant.send(:default_helper_module!)
|
15
|
+
|
16
|
+
descendant.respond_to?(:reapply_inheritance!) && descendant.reapply_inheritance!
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Spork.each_run { ApplicationController.reapply_inheritance! }
|
data/lib/spork/run_strategy.rb
CHANGED
@@ -28,7 +28,7 @@ class Spork::RunStrategy
|
|
28
28
|
|
29
29
|
protected
|
30
30
|
def self.factory(test_framework)
|
31
|
-
if RUBY_PLATFORM =~ /mswin|mingw
|
31
|
+
if RUBY_PLATFORM =~ /mswin|mingw/
|
32
32
|
Spork::RunStrategy::Magazine.new(test_framework)
|
33
33
|
else
|
34
34
|
Spork::RunStrategy::Forking.new(test_framework)
|
@@ -4,14 +4,14 @@
|
|
4
4
|
require 'drb'
|
5
5
|
require 'rinda/ring'
|
6
6
|
require 'win32/process' if RUBY_PLATFORM =~ /mswin|mingw/ and RUBY_VERSION < '1.9.1'
|
7
|
-
require 'rubygems' # used for Gem.ruby
|
8
7
|
|
9
8
|
$:.unshift(File.dirname(__FILE__))
|
10
9
|
require 'magazine/magazine_slave'
|
11
10
|
|
11
|
+
|
12
12
|
class Spork::RunStrategy::Magazine < Spork::RunStrategy
|
13
13
|
|
14
|
-
Slave_Id_Range = 1..
|
14
|
+
Slave_Id_Range = 1..3 # Ringserver uses id: 0. Slave use: 1..MAX_SLAVES
|
15
15
|
|
16
16
|
def slave_max
|
17
17
|
Slave_Id_Range.to_a.size
|
@@ -33,13 +33,14 @@ class Spork::RunStrategy::Magazine < Spork::RunStrategy
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def start_Rinda_ringserver
|
36
|
-
app_name =
|
37
|
-
spawn_process(app_name)
|
36
|
+
app_name = 'ruby ring_server.rb'
|
37
|
+
spawn_process(app_name)
|
38
38
|
end
|
39
39
|
|
40
40
|
def fill_slave_pool
|
41
41
|
Slave_Id_Range.each do |id|
|
42
42
|
start_slave(id)
|
43
|
+
sleep 10
|
43
44
|
end
|
44
45
|
puts " -- Starting to fill pool..."
|
45
46
|
puts " Wait until at least one slave is provided before running tests..."
|
@@ -49,21 +50,11 @@ class Spork::RunStrategy::Magazine < Spork::RunStrategy
|
|
49
50
|
|
50
51
|
def start_slave(id)
|
51
52
|
app_pwd = Dir.pwd # path running app in
|
52
|
-
app = "
|
53
|
+
app = "ruby magazine_slave_provider.rb #{id} '#{app_pwd}' #{@test_framework.short_name}"
|
53
54
|
@pids[id] = spawn_process(app)
|
54
55
|
end
|
55
56
|
|
56
57
|
def spawn_process(app)
|
57
|
-
|
58
|
-
if RUBY_PLATFORM =~ /java/
|
59
|
-
# jruby 1.8 has no easy way to just spawn, so use a thread
|
60
|
-
Dir.chdir(@path) do
|
61
|
-
io = IO.popen app
|
62
|
-
Thread.new { puts io.read }
|
63
|
-
return io.pid
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
58
|
if RUBY_VERSION < '1.9.1'
|
68
59
|
Process.create( :app_name => app, :cwd => @path ).process_id
|
69
60
|
else
|
@@ -76,24 +67,24 @@ class Spork::RunStrategy::Magazine < Spork::RunStrategy
|
|
76
67
|
end
|
77
68
|
|
78
69
|
def run(argv, stderr, stdout)
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
70
|
+
DRb.start_service
|
71
|
+
ts = Rinda::RingFinger.primary
|
72
|
+
if ts.read_all([:name, :MagazineSlave, nil, nil]).size > 0
|
73
|
+
print ' <-- take tuple'; stdout.flush
|
74
|
+
tuple = ts.take([:name, :MagazineSlave, nil, nil])
|
75
|
+
slave = tuple[2]
|
76
|
+
id = tuple[3]
|
77
|
+
|
78
|
+
puts "(#{slave.id_num}); slave.run..."; $stdout.flush
|
79
|
+
begin
|
80
|
+
slave.run(argv,stderr,stdout)
|
81
|
+
puts " -- (#{slave.id_num});run done"; $stdout.flush
|
82
|
+
ensure
|
83
|
+
restart_slave(id)
|
84
|
+
end
|
85
|
+
else
|
86
|
+
puts '- NO tuple'; $stdout.flush
|
87
|
+
end
|
97
88
|
end
|
98
89
|
|
99
90
|
def restart_slave(id)
|
@@ -102,19 +93,9 @@ class Spork::RunStrategy::Magazine < Spork::RunStrategy
|
|
102
93
|
start_slave(id)
|
103
94
|
end
|
104
95
|
|
105
|
-
def windows?
|
106
|
-
ENV['OS'] == 'Windows_NT'
|
107
|
-
end
|
108
|
-
|
109
96
|
def kill_all_processes
|
110
97
|
|
111
|
-
@pids.each {|pid|
|
112
|
-
if windows?
|
113
|
-
system("taskkill /f /pid #{pid}")
|
114
|
-
else
|
115
|
-
Process.kill(9, pid)
|
116
|
-
end
|
117
|
-
}
|
98
|
+
@pids.each {|pid| Process.kill(9, pid)}
|
118
99
|
puts "\nKilling processes."; $stdout.flush
|
119
100
|
end
|
120
101
|
|