Skip to content

Commit

Permalink
fix process specs
Browse files Browse the repository at this point in the history
  • Loading branch information
kostya committed Jul 7, 2013
1 parent f9afba0 commit 696eb6f
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 50 deletions.
6 changes: 3 additions & 3 deletions spec/process/controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
end

describe "unmonitor" do
[1, 2].each do |c|
it "should just forget about any process #{C[c][:name]}" do
start_ok_process(C[c])
[C.p1, C.p2].each do |cfg|
it "should just forget about any process #{cfg[:name]}" do
start_ok_process(cfg)
old_pid = @process.pid

@process.unmonitor
Expand Down
34 changes: 16 additions & 18 deletions spec/process/monitoring_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

describe "Process Monitoring" do

[1, 2].each do |c|
name = C[c][:name]

it "process crashed, should restart #{name}" do
start_ok_process(C[c])
[C.p1, C.p2].each do |cfg|
it "process crashed, should restart #{cfg[:name]}" do
start_ok_process(cfg)
old_pid = @pid

die_process!(@pid)
Expand All @@ -27,32 +25,32 @@
end

it "someone remove pid_file. should rewrite" do
start_ok_process(C[c])
start_ok_process(cfg)
old_pid = @pid
File.exists?(C[c][:pid_file]).should == true
File.exists?(cfg[:pid_file]).should == true

FileUtils.rm(C[c][:pid_file]) # someone removes it (bad man)
File.exists?(C[c][:pid_file]).should == false
FileUtils.rm(cfg[:pid_file]) # someone removes it (bad man)
File.exists?(cfg[:pid_file]).should == false

sleep 10 # wait until monitor understand it

File.exists?(C[c][:pid_file]).should == true
File.exists?(cfg[:pid_file]).should == true
@process.pid.should == old_pid
@process.load_pid_from_file.should == @process.pid
@process.state_name.should == :up
end

it "someone rewrite pid_file. should rewrite for daemonize only" do
start_ok_process(C[c])
start_ok_process(cfg)
old_pid = @pid
@process.load_pid_from_file.should == @pid

File.open(C[c][:pid_file], 'w'){|f| f.write(99999) }
File.open(cfg[:pid_file], 'w'){|f| f.write(99999) }
@process.load_pid_from_file.should == 99999

sleep 10 # wait until monitor understand it

if C[c][:daemonize]
if cfg[:daemonize]
@process.load_pid_from_file.should == @pid
else
@process.load_pid_from_file.should == 99999
Expand All @@ -63,13 +61,13 @@
end

it "someone rewrite pid_file. and ctime > limit, should rewrite for both" do
start_ok_process(C[c])
start_ok_process(cfg)
old_pid = @pid
@process.load_pid_from_file.should == @pid

silence_warnings{ Eye::Process::Monitor::REWRITE_FACKUP_PIDFILE_PERIOD = 4.seconds }

File.open(C[c][:pid_file], 'w'){|f| f.write(99999) }
File.open(cfg[:pid_file], 'w'){|f| f.write(99999) }
@process.load_pid_from_file.should == 99999

sleep 15 # wait until monitor understand it
Expand All @@ -83,14 +81,14 @@
end

it "EMULATE UNICORN someone rewrite pid_file and process die (should read actual pid from file)" do
start_ok_process(C[c])
start_ok_process(cfg)
old_pid = @pid

# rewrite by another :)
@pid = Eye::System.daemonize("ruby sample.rb", {:environment => {"ENV1" => "SECRET1"},
:working_dir => C[c][:working_dir], :stdout => @log})[:pid]
:working_dir => cfg[:working_dir], :stdout => @log})[:pid]

File.open(C[c][:pid_file], 'w'){|f| f.write(@pid) }
File.open(cfg[:pid_file], 'w'){|f| f.write(@pid) }

die_process!(old_pid)

Expand Down
24 changes: 11 additions & 13 deletions spec/process/restart_spec.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe "Process Restart" do
[1, 2].each do |c|
name = C[c][:name]

it "restart by default command #{name}" do
start_ok_process(C[c])
[C.p1, C.p2].each do |cfg|
it "restart by default command #{cfg[:name]}" do
start_ok_process(cfg)
old_pid = @pid

dont_allow(@process).check_crash
Expand All @@ -24,8 +22,8 @@
@process.load_pid_from_file.should == @process.pid
end

it "stop_command is #{name}" do
start_ok_process(C[c].merge(:stop_command => "kill -9 {{PID}}"))
it "stop_command is #{cfg[:name]}" do
start_ok_process(cfg.merge(:stop_command => "kill -9 {{PID}}"))
old_pid = @pid

dont_allow(@process).check_crash
Expand All @@ -45,7 +43,7 @@

it "emulate restart_command that cant kill (USR1)" do
# not trully test, but its ok as should send signal (unicorn case)
start_ok_process(C[c].merge(:restart_command => "kill -USR1 {{PID}}"))
start_ok_process(cfg.merge(:restart_command => "kill -USR1 {{PID}}"))
old_pid = @pid

dont_allow(@process).check_crash
Expand All @@ -70,7 +68,7 @@
# and than even if old process doesnot die, start another one, (looks like bug, but this is not, it just bad using, commands)

# same situation, when stop command kills so long time, that process cant stop
start_ok_process(C[c].merge(:stop_command => "kill -USR1 {{PID}}"))
start_ok_process(cfg.merge(:stop_command => "kill -USR1 {{PID}}"))
old_pid = @pid

dont_allow(@process).check_crash
Expand All @@ -90,10 +88,10 @@
File.read(@log).should include("USR1")
end

it "bad restart_command is #{name} and its kills" do
it "bad restart_command is #{cfg[:name]} and its kills" do
# not really restartin, just killing
# so monitor should see that process died, and up it
start_ok_process(C[c].merge(:restart_command => "kill -9 {{PID}}"))
start_ok_process(cfg.merge(:restart_command => "kill -9 {{PID}}"))

mock(@process).check_crash

Expand All @@ -103,7 +101,7 @@
end

it "Bad restart command, invalid" do
start_ok_process(C[c].merge(:restart_command => "asdfasdf sdf asd fasdf asdf"))
start_ok_process(cfg.merge(:restart_command => "asdfasdf sdf asd fasdf asdf"))

dont_allow(@process).check_crash

Expand All @@ -113,7 +111,7 @@
end

it "restart command timeouted" do
start_ok_process(C[c].merge(:restart_command => "sleep 5", :restart_timeout => 3))
start_ok_process(cfg.merge(:restart_command => "sleep 5", :restart_timeout => 3))
@process.restart

sleep 1
Expand Down
22 changes: 10 additions & 12 deletions spec/process/start_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@
@process.watchers.keys.should == [:check_alive]
end

[1, 2].each do |c|
name = C[c][:name]

it "start new process, with config #{name}" do
@process = process C[c]
[C.p1, C.p2].each do |cfg|
it "start new process, with config #{cfg[:name]}" do
@process = process cfg
@process.start.should == {:pid=>@process.pid}

sleep 0.5
Expand All @@ -56,10 +54,10 @@
@process.watchers.keys.should == [:check_alive]
end

it "pid_file already exists, but process not, with config #{name}" do
it "pid_file already exists, but process not, with config #{cfg[:name]}" do
File.open(C.p1[:pid_file], 'w'){|f| f.write(1234567) }

@process = process C[c]
@process = process cfg
@process.start.should == {:pid=>@process.pid}

sleep 0.5
Expand All @@ -71,8 +69,8 @@
@process.state_name.should == :up
end

it "process crashed, with config #{name}" do
@process = process(C[c].merge(:start_command => C[c][:start_command] + " -r" ))
it "process crashed, with config #{cfg[:name]}" do
@process = process(cfg.merge(:start_command => cfg[:start_command] + " -r" ))
@process.start.should == {:error=>:not_realy_running}

sleep 1
Expand All @@ -90,7 +88,7 @@
end

it "start with invalid command" do
@process = process(C[c].merge(:start_command => "asdf asdf1 r f324 f324f 32f44f"))
@process = process(cfg.merge(:start_command => "asdf asdf1 r f324 f324f 32f44f"))
mock(@process).check_crash
res = @process.start
res.should == {:error=>"#<Errno::ENOENT: No such file or directory - asdf>"}
Expand All @@ -104,7 +102,7 @@
end

it "start PROBLEM with stdout permissions" do
@process = process(C[c].merge(:stdout => "/var/run/1.log"))
@process = process(cfg.merge(:stdout => "/var/run/1.log"))
mock(@process).check_crash
res = @process.start
res.should == {:error=>"#<Errno::EACCES: Permission denied - open>"}
Expand All @@ -118,7 +116,7 @@
end

it "start PROBLEM binary permissions" do
@process = process(C[c].merge(:start_command => "./sample.rb"))
@process = process(cfg.merge(:start_command => "./sample.rb"))
mock(@process).check_crash
res = @process.start
res.should == {:error=>"#<Errno::EACCES: Permission denied - ./sample.rb>"}
Expand Down
8 changes: 4 additions & 4 deletions spec/process/system_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@
(Time.now - @process.pid_file_ctime).should < 0.1.second
end

[1, 2].each do |c|
it "blocking execute should not block process actor mailbox #{C[c][:name]}" do
@process = Eye::Process.new(C[c].merge(:start_command => "sleep 5", :start_timeout => 10.seconds))
[C.p1, C.p2].each do |cfg|
it "blocking execute should not block process actor mailbox #{cfg[:name]}" do
@process = Eye::Process.new(cfg.merge(:start_command => "sleep 5", :start_timeout => 10.seconds))
should_spend(1) do
@process.async.start
sleep 1

# here mailbox should anwser without blocks
@process.name.should == C[c][:name]
@process.name.should == cfg[:name]
end
end
end
Expand Down

0 comments on commit 696eb6f

Please sign in to comment.