Skip to content

Commit

Permalink
kill up to two of inc's parent processes
Browse files Browse the repository at this point in the history
This may make the test suite run better on Travis CI.
  • Loading branch information
alexch committed Oct 5, 2015
1 parent 812a6ac commit 246fc08
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 44 deletions.
1 change: 1 addition & 0 deletions inc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def run
f.puts(launched)
f.puts(i)
f.puts($$)
f.puts(Process.ppid)
end
sleep 0.5
i+=1
Expand Down
52 changes: 23 additions & 29 deletions spec/functional_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@
require "#{here}/spec_helper.rb"
require "#{here}/inc_process.rb"


describe "the rerun command" do
before do
STDOUT.sync = true

@inc = IncProcess.new
@dir = @inc.dir
@dir1 = @inc.dir1
@dir2 = @inc.dir2

# one file that exists in dir1
@watched_file1 = File.join(@dir1, "foo.rb")
touch @watched_file1
@existing_file = File.join(@inc.dir1, "foo.rb")
touch @existing_file

# one file that doesn't yet exist in dir1
@watched_file2 = File.join(@dir1, "bar.rb")
@soon_to_exist_file = File.join(@inc.dir1, "bar.rb")

# one file that exists in dir2
@watched_file3 = File.join(@dir2, "baz.rb")
@other_existing_file = File.join(@inc.dir2, "baz.rb")

@inc.launch
end
Expand All @@ -28,17 +26,11 @@
@inc.kill
end


def read
@inc.read
end

def current_count
launched_at, count = read
count
end

def touch(file = @watched_file1)
def touch(file = @existing_file)
puts "#{Time.now.strftime("%T")} touching #{file}"
File.open(file, "w") do |f|
f.puts Time.now
Expand All @@ -49,37 +41,39 @@ def type char
# todo: send a character to stdin of the rerun process
end

it "increments a test file at least once per second" do
sleep 1
x = current_count
sleep 1
y = current_count
y.should be > x
describe IncProcess do
it "increments a test file at least once per second" do
sleep 1
x = @inc.current_count
sleep 1
y = @inc.current_count
y.should be > x
end
end

it "restarts its target when an app file is modified" do
first_launched_at, count = read
touch @watched_file1
first_launched_at = read[:launched_at]
touch @existing_file
sleep 4
second_launched_at, count = read
second_launched_at = read[:launched_at]

second_launched_at.should be > first_launched_at
end

it "restarts its target when an app file is created" do
first_launched_at, count = read
touch @watched_file2
first_launched_at = read[:launched_at]
touch @soon_to_exist_file
sleep 4
second_launched_at, count = read
second_launched_at = read[:launched_at]

second_launched_at.should be > first_launched_at
end

it "restarts its target when an app file is created in the second dir" do
first_launched_at, count = read
touch @watched_file3
first_launched_at = read[:launched_at]
touch @other_existing_file
sleep 4
second_launched_at, count = read
second_launched_at = read[:launched_at]

second_launched_at.should be > first_launched_at
end
Expand Down
39 changes: 24 additions & 15 deletions spec/inc_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,50 @@ def initialize

end

# don't call this until you're sure it's running
def kill
timeout(4) {
Process.kill("INT", @inc_pid) && Process.wait(@inc_pid) rescue Errno::ESRCH
Process.kill("INT", @rerun_pid) && Process.wait(@rerun_pid) rescue Errno::ESRCH
}
timeout(4) do
pids = ([@inc_pid, @inc_parent_pid, @rerun_pid] - [Process.pid]).uniq
pids.each do |pid|
Process.kill("INT", pid) rescue Errno::ESRCH
end
pids.each do |pid|
Process.wait(pid) rescue Errno::ESRCH
end
end
end

def cmd
def rerun_cmd
root = File.dirname(__FILE__) + "/.."
"#{root}/bin/rerun -d '#{@dir1},#{@dir2}' ruby #{root}/inc.rb #{@inc_output_file}"
end

def launch
@rerun_pid = spawn(cmd)
@rerun_pid = spawn(rerun_cmd)
timeout(10) { sleep 0.5 until File.exist?(@inc_output_file) }
sleep 4 # let rerun's watcher get going
sleep 3 # let rerun's watcher get going
end

def read
File.open(@inc_output_file, "r") do |f|
launched_at = f.gets.to_i
count = f.gets.to_i
@inc_pid = f.gets.to_i
result = [launched_at, count, @inc_pid]
puts "reading #{@inc_output_file}: #{result.join("\t")}"
result = {
launched_at: f.gets.to_i,
count: f.gets.to_i,
inc_pid: f.gets.to_i,
inc_parent_pid: f.gets.to_i,
}
@inc_pid = result[:inc_pid]
@inc_parent_pid = result[:inc_parent_pid]
puts "reading #{@inc_output_file}: #{result.inspect}"
result
end
end

def current_count
launched_at, count = read
count
read[:count]
end

def touch(file = @watched_file1)
def touch(file = @existing_file)
puts "#{Time.now.strftime("%T")} touching #{file}"
File.open(file, "w") do |f|
f.puts Time.now
Expand Down

0 comments on commit 246fc08

Please sign in to comment.