Skip to content

Commit a3e84ec

Browse files
Use local variable instead of @pid to prevent race conditions
1 parent 3c777ec commit a3e84ec

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

test/scheduler_task_test.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
test 'sending TERM to scheduler breaks out of poll_sleep' do
2525
Resque::Scheduler.expects(:release_master_lock)
2626

27-
@pid = Process.pid
27+
pid = Process.pid
2828
Thread.new do
2929
sleep(0.05)
30-
Process.kill(:TERM, @pid)
30+
Process.kill(:TERM, pid)
3131
end
3232

3333
assert_raises SystemExit do
@@ -41,10 +41,10 @@
4141
test 'can start successfully' do
4242
Resque::Scheduler.poll_sleep_amount = nil
4343

44-
@pid = Process.pid
44+
pid = Process.pid
4545
Thread.new do
4646
sleep(0.15)
47-
Process.kill(:TERM, @pid)
47+
Process.kill(:TERM, pid)
4848
end
4949

5050
assert_raises SystemExit do
@@ -56,10 +56,10 @@
5656
Resque::Scheduler.poll_sleep_amount = 0
5757
Resque::Scheduler.expects(:release_master_lock)
5858

59-
@pid = Process.pid
59+
pid = Process.pid
6060
Thread.new do
6161
sleep(0.05)
62-
Process.kill(:TERM, @pid)
62+
Process.kill(:TERM, pid)
6363
end
6464

6565
assert_raises SystemExit do
@@ -86,10 +86,10 @@
8686
test 'logs scheduler master' do
8787
Resque::Scheduler.expects(:master?).returns(true)
8888

89-
@pid = Process.pid
89+
pid = Process.pid
9090
Thread.new do
9191
sleep(0.1)
92-
Process.kill(:TERM, @pid)
92+
Process.kill(:TERM, pid)
9393
end
9494

9595
assert_raises SystemExit do
@@ -102,10 +102,10 @@
102102
test 'logs scheduler child' do
103103
Resque::Scheduler.expects(:master?).returns(false)
104104

105-
@pid = Process.pid
105+
pid = Process.pid
106106
Thread.new do
107107
sleep(0.1)
108-
Process.kill(:TERM, @pid)
108+
Process.kill(:TERM, pid)
109109
end
110110

111111
assert_raises SystemExit do

0 commit comments

Comments
 (0)