-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use /run
as the default for PID/UNIX-domain sockets
#13
Changes from all commits
d6b7efd
9b87bb6
f74f029
4fc649a
7ebc730
18cec00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
@testset "graceful_terminator" begin | ||
deputy_ipc_dir = mktempdir() | ||
|
||
@testset "Julia entrypoint" begin | ||
code = quote | ||
using K8sDeputy | ||
|
@@ -12,6 +14,7 @@ | |
end | ||
|
||
cmd = `$(Base.julia_cmd()) --color=no -e $code` | ||
cmd = addenv(cmd, "DEPUTY_IPC_DIR" => deputy_ipc_dir) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah maybe not if we are using an external command... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. at the very least it seems that it woudl be annoying lol There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's definitely annoying. I'll look into replacing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah let's not hold this up |
||
buffer = IOBuffer() | ||
p = run(pipeline(cmd; stdout=buffer, stderr=buffer); wait=false) | ||
@test timedwait(() -> process_running(p), Second(5)) === :ok | ||
|
@@ -21,7 +24,9 @@ | |
|
||
# When no PID is passed in the process ID is read from the Julia entrypoint file. | ||
# Blocks untils the process terminates. | ||
@test graceful_terminate() === nothing | ||
withenv("DEPUTY_IPC_DIR" => deputy_ipc_dir) do | ||
@test graceful_terminate() === nothing | ||
end | ||
|
||
@test process_exited(p) | ||
@test p.exitcode == 2 | ||
|
@@ -47,6 +52,7 @@ | |
end | ||
|
||
cmd = `$(Base.julia_cmd()) --color=no -e $code` | ||
cmd = addenv(cmd, "DEPUTY_IPC_DIR" => deputy_ipc_dir) | ||
buffer1 = IOBuffer() | ||
buffer2 = IOBuffer() | ||
p1 = run(pipeline(cmd; stdout=buffer1, stderr=buffer1); wait=false) | ||
|
@@ -57,8 +63,10 @@ | |
sleep(3) | ||
|
||
# Blocks untils the process terminates | ||
@test graceful_terminate(getpid(p1)) === nothing | ||
@test graceful_terminate(getpid(p2)) === nothing | ||
withenv("DEPUTY_IPC_DIR" => deputy_ipc_dir) do | ||
@test graceful_terminate(getpid(p1)) === nothing | ||
@test graceful_terminate(getpid(p2)) === nothing | ||
end | ||
@test process_exited(p1) | ||
@test process_exited(p2) | ||
|
||
|
@@ -73,10 +81,9 @@ | |
end | ||
|
||
# When users set `DEPUTY_IPC_DIR` they may be using a K8s volume. As even `emptyDir` | ||
# volumes persist for the lifetime of the pod we may have a named pipe already present | ||
# from a previous restart. | ||
# volumes persist for the lifetime of the pod we may have a UNIX-domain socket already | ||
# present from a previous restart. | ||
@testset "bind after restart" begin | ||
deputy_ipc_dir = mktempdir() | ||
code = quote | ||
using K8sDeputy | ||
using Sockets: listen | ||
|
@@ -99,31 +106,33 @@ | |
end | ||
|
||
cmd = `$(Base.julia_cmd()) --color=no -e $code` | ||
cmd = addenv(cmd, "DEPUTY_IPC_DIR" => deputy_ipc_dir) | ||
buffer = IOBuffer() | ||
p = run(pipeline(cmd; stdout=buffer, stderr=buffer); wait=false) | ||
@test timedwait(() -> process_running(p), Second(5)) === :ok | ||
|
||
withenv("DEPUTY_IPC_DIR" => deputy_ipc_dir) do | ||
buffer = IOBuffer() | ||
p = run(pipeline(cmd; stdout=buffer, stderr=buffer); wait=false) | ||
@test timedwait(() -> process_running(p), Second(5)) === :ok | ||
|
||
# Allow some time for Julia to startup and the graceful terminator to be registered. | ||
sleep(3) | ||
# Allow some time for Julia to startup and the graceful terminator to be registered. | ||
sleep(3) | ||
|
||
# Socket exists as a named pipe | ||
socket_path = K8sDeputy._graceful_terminator_socket_path(getpid(p)) | ||
@test ispath(socket_path) | ||
@test !isfile(socket_path) | ||
# Socket exists as a UNIX-domain socket | ||
socket_path = withenv("DEPUTY_IPC_DIR" => deputy_ipc_dir) do | ||
return K8sDeputy._graceful_terminator_socket_path(getpid(p)) | ||
end | ||
@test ispath(socket_path) | ||
@test !isfile(socket_path) | ||
|
||
# Blocks untils the process terminates | ||
# Blocks untils the process terminates | ||
withenv("DEPUTY_IPC_DIR" => deputy_ipc_dir) do | ||
@test graceful_terminate(getpid(p)) === nothing | ||
@test process_exited(p) | ||
@test p.exitcode == 2 | ||
|
||
output = String(take!(buffer)) | ||
expected = """ | ||
[ Info: GRACEFUL TERMINATION HANDLER | ||
[ Info: SHUTDOWN COMPLETE | ||
""" | ||
@test output == expected | ||
end | ||
@test process_exited(p) | ||
@test p.exitcode == 2 | ||
|
||
output = String(take!(buffer)) | ||
expected = """ | ||
[ Info: GRACEFUL TERMINATION HANDLER | ||
[ Info: SHUTDOWN COMPLETE | ||
""" | ||
@test output == expected | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could mock this call to the IPC dir for testing purposes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could also possibly use mocking for the external command. Will look into that quickly.