Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b325d4a6
Commit
b325d4a6
authored
Apr 20, 2017
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test that asserts unicorns terminate
parent
a9da3743
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
106 additions
and
1 deletion
+106
-1
app/controllers/unicorn_test_controller.rb
app/controllers/unicorn_test_controller.rb
+12
-0
config/routes.rb
config/routes.rb
+2
-0
config/routes/test.rb
config/routes/test.rb
+2
-0
lib/tasks/brakeman.rake
lib/tasks/brakeman.rake
+1
-1
spec/unicorn/unicorn_spec.rb
spec/unicorn/unicorn_spec.rb
+89
-0
No files found.
app/controllers/unicorn_test_controller.rb
0 → 100644
View file @
b325d4a6
if
Rails
.
env
.
test?
class
UnicornTestController
<
ActionController
::
Base
def
pid
render
plain:
Process
.
pid
.
to_s
end
def
kill
Process
.
kill
(
params
[
:signal
],
Process
.
pid
)
render
plain:
'Bye!'
end
end
end
config/routes.rb
View file @
b325d4a6
...
...
@@ -99,5 +99,7 @@ Rails.application.routes.draw do
end
end
draw
:test
if
Rails
.
env
.
test?
get
'*unmatched_route'
,
to:
'application#route_not_found'
end
config/routes/test.rb
0 → 100644
View file @
b325d4a6
get
'/unicorn_test/pid'
=>
'unicorn_test#pid'
post
'/unicorn_test/kill'
=>
'unicorn_test#kill'
lib/tasks/brakeman.rake
View file @
b325d4a6
...
...
@@ -2,7 +2,7 @@ desc 'Security check via brakeman'
task
:brakeman
do
# We get 0 warnings at level 'w3' but we would like to reach 'w2'. Merge
# requests are welcome!
if
system
(
*
%w(brakeman --no-progress --skip-files lib/backup/repository.rb -w3 -z)
)
if
system
(
*
%w(brakeman --no-progress --skip-files lib/backup/repository.rb
,app/controllers/unicorn_test_controller.rb
-w3 -z)
)
puts
'Security check succeed'
else
puts
'Security check failed'
...
...
spec/unicorn/unicorn_spec.rb
0 → 100644
View file @
b325d4a6
require
'fileutils'
require
'excon'
require
'spec_helper'
describe
'Unicorn'
do
before
(
:all
)
do
config_lines
=
File
.
read
(
'config/unicorn.rb.example'
).
split
(
"
\n
"
)
# Remove these because they make setup harder.
config_lines
=
config_lines
.
reject
do
|
line
|
%w[
pid
stderr_path
stdout_path
]
.
any?
{
|
prefix
|
line
.
start_with?
(
prefix
)
}
end
config_lines
=
config_lines
.
reject
{
|
l
|
l
.
start_with?
(
'working_directory'
)
}
config_lines
<<
"working_directory '
#{
Rails
.
root
}
'"
# We want to have exactly 1 worker process because that makes it
# predictable which process will handle our requests.
config_lines
=
config_lines
.
reject
{
|
l
|
l
.
start_with?
(
'worker_processes'
)
}
config_lines
<<
'worker_processes 1'
@socket_path
=
File
.
join
(
Dir
.
pwd
,
'tmp/tests/unicorn.socket'
)
config_lines
=
config_lines
.
reject
{
|
l
|
l
.
start_with?
(
'listen'
)
}
config_lines
<<
"listen '
#{
@socket_path
}
'"
ready_file
=
'tmp/tests/unicorn-worker-ready'
FileUtils
.
rm_f
(
ready_file
)
after_fork_index
=
config_lines
.
index
{
|
l
|
l
.
start_with?
(
'after_fork'
)
}
config_lines
.
insert
(
after_fork_index
+
1
,
"File.write('
#{
ready_file
}
', Process.pid)"
)
config_path
=
'tmp/tests/unicorn.rb'
File
.
write
(
config_path
,
config_lines
.
join
(
"
\n
"
)
+
"
\n
"
)
cmd
=
%W[unicorn -E test -c
#{
config_path
}
#{
Rails
.
root
.
join
(
'config.ru'
)
}
]
@unicorn_master_pid
=
spawn
(
*
cmd
)
120
.
times
do
break
if
File
.
exist?
(
ready_file
)
pid
=
Process
.
waitpid
(
@unicorn_master_pid
,
Process
::
WNOHANG
)
raise
"unicorn failed to boot:
#{
$?
}
"
unless
pid
.
nil?
sleep
1
end
WebMock
.
allow_net_connect!
end
%w[SIGQUIT SIGTERM SIGKILL]
.
each
do
|
signal
|
it
"has a worker that self-terminates on signal
#{
signal
}
"
do
response
=
Excon
.
get
(
'unix:///unicorn_test/pid'
,
socket:
@socket_path
)
expect
(
response
.
status
).
to
eq
(
200
)
worker_pid
=
response
.
body
.
to_i
expect
(
worker_pid
>
0
).
to
eq
(
true
)
begin
Excon
.
post
(
'unix:///unicorn_test/kill'
,
socket:
@socket_path
,
body:
"signal=
#{
signal
}
"
)
rescue
Excon
::
Error
::
Socket
# The connection may be closed abruptly
end
expect
(
pid_gone?
(
worker_pid
)).
to
eq
(
true
)
end
end
after
(
:all
)
do
WebMock
.
disable_net_connect!
(
allow_localhost:
true
)
Process
.
kill
(
'TERM'
,
@unicorn_master_pid
)
end
def
pid_gone?
(
pid
)
10
.
times
do
begin
Process
.
kill
(
0
,
pid
)
rescue
Errno
::
ESRCH
return
true
end
sleep
1
end
false
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment