Skip to content

Commit

Permalink
Add convention to preload app before first child is forked in a slave…
Browse files Browse the repository at this point in the history
…. The convention is that a file called testjour_preload.rb will get loaded if it exists.
  • Loading branch information
Luke Melia and Lee Bankewitz committed Dec 7, 2009
1 parent 091a8ee commit eca3ecc
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
7 changes: 6 additions & 1 deletion features/run.feature
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ Feature: Run Features
Then it should fail with "1 steps passed"
And the output should contain "FAIL"
And the output should contain "1 steps failed"
And it should run on 2 slaves
And it should run on 2 slaves

Scenario: Preload application
Given a file testjour_preload.rb at the root of the project that logs "Hello, world"
When I run `testjour passing.feature`
And testjour.log should include "Hello, world"
6 changes: 6 additions & 0 deletions features/step_definitions/testjour_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
FileUtils.mkdir_p full_path
end

Given /^a file testjour_preload.rb at the root of the project that logs "Hello, world"$/ do
File.open(File.join(@full_dir, 'testjour_preload.rb'), 'w') do |file|
file.puts "Testjour.logger.info 'Hello, world'"
end
end

When /^I run `testjour (.+)`$/ do |args|
@args ||= []
@args += args.split
Expand Down
1 change: 1 addition & 0 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ def be_like(expected)

Dir.chdir(@full_dir) do
File.unlink("testjour.log") if File.exists?("testjour.log")
File.unlink("testjour_preload.rb") if File.exists?("testjour_preload.rb")
end
end
10 changes: 9 additions & 1 deletion lib/testjour/commands/run_slave.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def execute
configuration.setup
configuration.setup_mysql
require_cucumber_files
preload_app
work
rescue Object => ex
Testjour.logger.error "run:slave error: #{ex.message}"
Expand All @@ -45,7 +46,7 @@ def work
features = load_plain_text_features(feature_file)
parent_pid = $PID
if @child = fork
Testjour.logger.info "Forked #{@child} at #{Time.now.to_i}"
Testjour.logger.info "Forked #{@child} to run #{feature_file}"
Process.wait
Testjour.logger.info "Finished running: #{feature_file}"
else
Expand Down Expand Up @@ -74,6 +75,13 @@ def require_cucumber_files
step_mother.load_code_files(configuration.cucumber_configuration.step_defs_to_load)
end

def preload_app
if File.exist?('./testjour_preload.rb')
Testjour.logger.info 'Requiring ./testjour_preload.rb'
require './testjour_preload.rb'
end
end

# Not every platform supports fork. Here we do our magic to
# determine if yours does.
def fork
Expand Down
1 change: 1 addition & 0 deletions spec/fixtures/testjour_preload.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Testjour.logger.info 'Hello, world'

0 comments on commit eca3ecc

Please sign in to comment.