Skip to content

Commit

Permalink
trying parallel tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kostya committed Jul 7, 2013
1 parent 8f68731 commit e32d5c3
Show file tree
Hide file tree
Showing 17 changed files with 125 additions and 79 deletions.
6 changes: 3 additions & 3 deletions spec/checker/socket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

def chsock(cfg = {})
Eye::Checker.create(nil, {:type => :socket, :every => 5.seconds,
:times => 1, :addr => 'tcp://127.0.0.1:33231', :send_data => "ping",
:times => 1, :addr => "tcp://127.0.0.1:#{C.p4_ports[0]}", :send_data => "ping",
:expect_data => /pong/, :timeout => 2}.merge(cfg))
end

def chsockb(cfg = {})
Eye::Checker.create(nil, {:type => :socket, :every => 5.seconds,
:times => 1, :addr => 'tcp://127.0.0.1:33232', :protocol => :em_object, :send_data => {},
:times => 1, :addr => "tcp://127.0.0.1:#{C.p4_ports[1]}", :protocol => :em_object, :send_data => {},
:expect_data => /pong/, :timeout => 2}.merge(cfg))
end

describe "Socket Checker" do
%w[ tcp://127.0.0.1:33231 unix:/tmp/em_test_sock_spec].each do |addr|
["tcp://127.0.0.1:#{C.p4_ports[0]}", "unix:#{C.p4_sock}"].each do |addr|
describe "socket: '#{addr}'" do
before :each do
start_ok_process(C.p4)
Expand Down
11 changes: 7 additions & 4 deletions spec/example/em.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,15 @@ def unbind

trap "TERM" do
EM.stop
`rm /tmp/em_test_sock_spec` rescue nil
`rm #{$sock}` rescue nil
end

EM.run do
EM.start_server '127.0.0.1', 33231, Echo
EM.start_server '127.0.0.1', 33232, EchoObj
EM.start_server "/tmp/em_test_sock_spec", nil, Echo
$port1 = (ARGV[0] || 33231).to_i
$port2 = (ARGV[1] || 33232).to_i
$sock = (ARGV[2] || "/tmp/em_test_sock_spec")
EM.start_server '127.0.0.1', $port1, Echo
EM.start_server '127.0.0.1', $port2, EchoObj
EM.start_server $sock, nil, Echo
puts 'started'
end
4 changes: 3 additions & 1 deletion spec/example/forking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

root = File.expand_path(File.dirname(__FILE__))

PID_NAME = ENV["PID_NAME"] || "forking.pid"

f = Forking.new(:name => 'forking', :working_dir => root,
:log_file => "#{root}/forking.log",
:pid_file => "#{root}/forking.pid", :sync_log => true)
:pid_file => "#{root}/#{PID_NAME}", :sync_log => true)

3.times do |i|
f.spawn(:log_file => "#{root}/child#{i}.log", :sync_log => true) do
Expand Down
4 changes: 2 additions & 2 deletions spec/notify/jabber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

describe "Eye::Notify::Jabber" do
before :each do
@message = {:message=>"something", :name=>"blocking process",
:full_name=>"main:default:blocking process", :pid=>123,
@message = {:message=>"something", :name=>"Blocking Process",
:full_name=>"main:default:Blocking Process", :pid=>123,
:host=>'host1', :level=>:crit, :at => Time.now}
@h = {:host=>"mx.some.host.ru", :type=>:mail, :port=>25, :contact=>"vasya@mail.ru", :password => "123"}
end
Expand Down
8 changes: 4 additions & 4 deletions spec/notify/mail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

describe "Eye::Notify::Mail" do
before :each do
@message = {:message=>"something", :name=>"blocking process",
:full_name=>"main:default:blocking process", :pid=>123,
@message = {:message=>"something", :name=>"Blocking Process",
:full_name=>"main:default:Blocking Process", :pid=>123,
:host=>'host1', :level=>:crit, :at => Time.now}
@h = {:host=>"mx.some.host.ru", :type=>:mail, :port=>25, :domain=>"some.host", :contact=>"vasya@mail.ru"}
end
Expand All @@ -16,11 +16,11 @@

@m.execute

@m.message_subject.should == "[host1] [main:default:blocking process] something"
@m.message_subject.should == "[host1] [main:default:Blocking Process] something"
@m.contact.should == "vasya@mail.ru"

m = @m.message.split("\n")
m.should include("To: <vasya@mail.ru>")
m.should include("Subject: [host1] [main:default:blocking process] something")
m.should include("Subject: [host1] [main:default:Blocking Process] something")
end
end
8 changes: 4 additions & 4 deletions spec/notify_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def execute

describe "Eye::Notify" do
before :each do
@message = {:message=>"something", :name=>"blocking process",
:full_name=>"main:default:blocking process", :pid=>123,
@message = {:message=>"something", :name=>"Blocking Process",
:full_name=>"main:default:Blocking Process", :pid=>123,
:host=>'host1', :level=>:crit, :at => Time.now}

end
Expand Down Expand Up @@ -82,8 +82,8 @@ def execute
$wo.contact.should == 'vasya@mail.ru'
$wo.port.should == 25

$wo.message_subject.should == '[host1] [main:default:blocking process] something'
$wo.message_body.should start_with('[host1] [main:default:blocking process] something at')
$wo.message_subject.should == '[host1] [main:default:Blocking Process] something'
$wo.message_body.should start_with('[host1] [main:default:Blocking Process] something at')
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/process/checks/intergration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
it "timeouted http, should not lock actor-mailbox" do
cfg = C.p5.merge(
:checks => join(C.check_http(
:url => "http://127.0.0.1:33233/timeout", :timeout => 6.seconds, :every => 5.seconds,
:url => "http://127.0.0.1:#{C.p5_port}/timeout", :timeout => 6.seconds, :every => 5.seconds,
:times => 3),
C.check_cpu(:every => 1.second)
)
Expand Down
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
[C.p1, C.p2].each do |cfg|
it "should just forget about any process #{cfg[:name]}" do
start_ok_process
[1, 2].each do |c|
it "should just forget about any process #{C[c][:name]}" do
start_ok_process(C[c])
old_pid = @process.pid

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

describe "Process Monitoring" do

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

it "process crashed, should restart #{name}" do
start_ok_process(C[c])
old_pid = @pid

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

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

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

sleep 10 # wait until monitor understand it

File.exists?(cfg[:pid_file]).should == true
File.exists?(C[c][: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(cfg)
start_ok_process(C[c])
old_pid = @pid
@process.load_pid_from_file.should == @pid

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

sleep 10 # wait until monitor understand it

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

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

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

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

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

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

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

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

die_process!(old_pid)

Expand Down
6 changes: 3 additions & 3 deletions spec/process/notify_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
end

it "should send to notifies warn message" do
m = {:message=>"something", :name=>"blocking process", :full_name=>"main:default:blocking process", :pid=>nil, :host=>"host1", :level=>:info}
m = {:message=>"something", :name=>"Blocking Process", :full_name=>"main:default:Blocking Process", :pid=>nil, :host=>"host1", :level=>:info}
mock(Eye::Notify).notify('vasya', hash_including(m))
@process.notify(:info, 'something')
end

it "should send to notifies crit message" do
m = {:message=>"something", :name=>"blocking process",
:full_name=>"main:default:blocking process", :pid=>nil,
m = {:message=>"something", :name=>"Blocking Process",
:full_name=>"main:default:Blocking Process", :pid=>nil,
:host=>'host1', :level=>:warn}

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

describe "Process Restart" do
[C.p1, C.p2].each do |cfg|
it "restart by default command #{cfg[:name]}" do
start_ok_process(cfg)
[1, 2].each do |c|
name = C[c][:name]

it "restart by default command #{name}" do
start_ok_process(C[c])
old_pid = @pid

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

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

dont_allow(@process).check_crash
Expand All @@ -43,7 +45,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(cfg.merge(:restart_command => "kill -USR1 {{PID}}"))
start_ok_process(C[c].merge(:restart_command => "kill -USR1 {{PID}}"))
old_pid = @pid

dont_allow(@process).check_crash
Expand All @@ -68,7 +70,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(cfg.merge(:stop_command => "kill -USR1 {{PID}}"))
start_ok_process(C[c].merge(:stop_command => "kill -USR1 {{PID}}"))
old_pid = @pid

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

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

mock(@process).check_crash

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

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

dont_allow(@process).check_crash

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

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

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

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

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

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

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

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

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

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

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

it "start with invalid command" do
@process = process(c.merge(:start_command => "asdf asdf1 r f324 f324f 32f44f"))
@process = process(C[c].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 @@ -102,7 +104,7 @@
end

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

it "start PROBLEM binary permissions" do
@process = process(c.merge(:start_command => "./sample.rb"))
@process = process(C[c].merge(:start_command => "./sample.rb"))
mock(@process).check_crash
res = @process.start
res.should == {:error=>"#<Errno::EACCES: Permission denied - ./sample.rb>"}
Expand Down
2 changes: 1 addition & 1 deletion spec/process/stop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@

# not blocking actor
should_spend(0) do
@process.name.should == 'blocking process'
@process.name.should == 'Blocking Process'
end

Eye::System.pid_alive?(@pid).should == true
Expand Down

0 comments on commit e32d5c3

Please sign in to comment.