-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into cv/k8s-tests
- Loading branch information
Showing
5 changed files
with
75 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,74 @@ | ||
@testset "graceful_terminator / graceful_terminate" begin | ||
code = quote | ||
using K8sDeputy | ||
atexit(() -> @info "SHUTDOWN COMPLETE") | ||
graceful_terminator() do | ||
@info "GRACEFUL TERMINATION HANDLER" | ||
exit(2) | ||
return nothing | ||
@testset "graceful_terminator" begin | ||
@testset "Julia entrypoint" begin | ||
code = quote | ||
using K8sDeputy | ||
atexit(() -> @info "SHUTDOWN COMPLETE") | ||
graceful_terminator() do | ||
@info "GRACEFUL TERMINATION HANDLER" | ||
exit(2) | ||
return nothing | ||
end | ||
sleep(60) | ||
end | ||
sleep(60) | ||
|
||
cmd = `$(Base.julia_cmd()) --color=no -e $code` | ||
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) | ||
|
||
# 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 | ||
|
||
@test process_exited(p) | ||
@test p.exitcode == 2 | ||
|
||
output = String(take!(buffer)) | ||
expected = """ | ||
[ Info: GRACEFUL TERMINATION HANDLER | ||
[ Info: SHUTDOWN COMPLETE | ||
""" | ||
@test output == expected | ||
end | ||
|
||
cmd = `$(Base.julia_cmd()) --color=no -e $code` | ||
buffer = IOBuffer() | ||
p = run(pipeline(cmd; stdout=buffer, stderr=buffer); wait=false) | ||
@test timedwait(() -> process_running(p), Second(5)) === :ok | ||
@testset "multiple Julia processes" begin | ||
code = quote | ||
using K8sDeputy | ||
atexit(() -> @info "SHUTDOWN COMPLETE") | ||
graceful_terminator(; set_entrypoint=false) do | ||
@info "GRACEFUL TERMINATION HANDLER" | ||
exit(2) | ||
return nothing | ||
end | ||
sleep(60) | ||
end | ||
|
||
cmd = `$(Base.julia_cmd()) --color=no -e $code` | ||
buffer1 = IOBuffer() | ||
buffer2 = IOBuffer() | ||
p1 = run(pipeline(cmd; stdout=buffer1, stderr=buffer1); wait=false) | ||
p2 = run(pipeline(cmd; stdout=buffer2, stderr=buffer2); wait=false) | ||
@test timedwait(() -> process_running(p1) && process_running(p2), 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) | ||
|
||
@test graceful_terminate(getpid(p)) === nothing # Blocks untils the HTTP server goes down | ||
@test process_exited(p) | ||
@test p.exitcode == 2 | ||
# Blocks untils the process terminates | ||
@test graceful_terminate(getpid(p1)) === nothing | ||
@test graceful_terminate(getpid(p2)) === nothing | ||
@test process_exited(p1) | ||
@test process_exited(p2) | ||
|
||
output = String(take!(buffer)) | ||
expected = """ | ||
[ Info: GRACEFUL TERMINATION HANDLER | ||
[ Info: SHUTDOWN COMPLETE | ||
""" | ||
@test output == expected | ||
output1 = String(take!(buffer1)) | ||
output2 = String(take!(buffer2)) | ||
expected = """ | ||
[ Info: GRACEFUL TERMINATION HANDLER | ||
[ Info: SHUTDOWN COMPLETE | ||
""" | ||
@test output1 == expected | ||
@test output2 == expected | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters