-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement #5 * Bumped version to 0.5.0
- Loading branch information
Showing
7 changed files
with
173 additions
and
6 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
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using Visor | ||
using Test | ||
|
||
# | ||
# | ||
# root | ||
# / | ||
# / | ||
# s1 | ||
# / \ | ||
# s11 w3 | ||
# / \ | ||
# w1 w2 | ||
# | ||
# startup order: w1, w2, w3 | ||
# if strategy is :one_for_all and the failed process does not restart terminate | ||
# all sibling processes. | ||
# | ||
|
||
#ENV["JULIA_DEBUG"] = Visor | ||
|
||
starts = 0 | ||
|
||
stopped = [] | ||
|
||
function myworker(self) | ||
global starts | ||
|
||
@info "[$self]: starting" | ||
starts += 1 | ||
if self.id === "w3" | ||
sleep(2) | ||
#if starts < 4 | ||
@info "[$self]: THROW EXCEPTION" | ||
error("bang") | ||
#end | ||
else | ||
sleep(20) | ||
end | ||
@info "[$self]: terminate" | ||
# for msg in self.inbox | ||
# @debug "[$(self.id)] recv: $msg" | ||
# if isshutdown(msg) | ||
# push!(stopped, self.id) | ||
# break | ||
# end | ||
# end | ||
end | ||
|
||
s11_specs = [ | ||
process("w1", myworker; thread=true), process("w2", myworker; force_interrupt_after=1) | ||
] | ||
|
||
s1_specs = [ | ||
supervisor("s11", s11_specs; intensity=1, terminateif=:shutdown), | ||
process("w3", myworker; force_interrupt_after=1), | ||
] | ||
|
||
specs = [supervisor("s1", s1_specs; strategy=:one_for_all)] | ||
|
||
handle = Visor.supervise(specs; wait=false) | ||
|
||
timer_not_triggered = true | ||
timer = Timer((tim) -> begin | ||
global timer_not_triggered = false | ||
shutdown(handle) | ||
end, 10) | ||
|
||
@test wait(handle) === nothing | ||
|
||
# if all processes terminate the timer that shutdown thw system | ||
# is not triggered | ||
@test timer_not_triggered | ||
@test starts === 6 | ||
close(timer) |
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
include("utils.jl") | ||
|
||
NAME = "Alfred" | ||
|
||
EXPECTED_RESTARTS = 7 | ||
restart_count = 0 | ||
|
||
function p2(self) | ||
global restart_count += 1 | ||
sleep(1) | ||
return error("simulate a fault") | ||
end | ||
|
||
function myworker(self) | ||
global restart_count | ||
|
||
@info "(re)starting [$(self.id)]" | ||
restart_count += 1 | ||
|
||
try | ||
for msg in self.inbox | ||
@info "[$(self.id)] recv: $msg" | ||
if isshutdown(msg) | ||
break | ||
elseif msg.request === :get_name | ||
put!(msg.inbox, NAME) | ||
end | ||
end | ||
catch e | ||
@error "worker: $e" | ||
rethrow() | ||
end | ||
end | ||
|
||
workerspecs = [ | ||
process("p1", myworker) | ||
process("p2", p2) | ||
process("p3", myworker) | ||
process("p4", myworker) | ||
] | ||
|
||
specs = [supervisor("boss", workerspecs; strategy=:rest_for_one)] | ||
|
||
@info "starting ..." | ||
handle = Visor.supervise(specs; wait=false) | ||
|
||
only_p1_running = false | ||
timer = Timer((tim) -> begin | ||
|
||
# check that only p1 is running | ||
boss = from("boss") | ||
procs = boss.processes | ||
if (length(procs) === 1) | ||
global only_p1_running = true | ||
end | ||
@info "boss running processes: $(boss.processes)" | ||
shutdown(handle) | ||
end, 8) | ||
|
||
@test wait(handle) === nothing | ||
|
||
# if all processes terminate the timer that shutdown thw system | ||
# is not triggered | ||
@test only_p1_running | ||
@test EXPECTED_RESTARTS === restart_count | ||
close(timer) |
dd76161
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.
@JuliaRegistrator register()
dd76161
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.
Registration pull request created: JuliaRegistries/General/101973
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: