Reviewing leaf usage in progs, it always occurs right after reap. Combining leaf and reap methods avoids a redundant query for the strand's children. It's typical for nap or donate to be called after the leaf check after reap. Also build this into reap, by calling donate by default, or nap if a nap keyword argument is given. There are a few cases where reap was called without leaf/donate. Add a fallthrough keyword argument to support this, so if there are no children, it does not call either nap or donate Vm::HostNexus#wait_prep and Kubernetes::UpgradeKubernetesNode#wait_new_node both need the return value of the reapable child(ren). Add a reaper keyword argument for this, which is called once for each child. The most common pattern for using reap/leaf/donate was: ```ruby reap hop_download_lb_cert if leaf? donate ``` This turns into: ```ruby reap(:download_lb_cert) ``` The second most common pattern was: ```ruby reap donate unless leaf? pop "upgrade cancelled" # or other code ``` This turns into: ```ruby reap { pop "upgrade cancelled" } ``` In a few places, I changed operations on strand.children to strand.children_dataset. Now that we are no longer using cached children by default, it's better to do these checks in the database intead of in Ruby. These places deserve careful review: * Prog::Minio::MinioServerNexus#unavailable * Prog::Postgres::PostgresResourceNexus#wait * Prog::Postgres::PostgresServerNexus#unavailable For Prog::Vnet::LoadBalancerNexus#wait_update_vm_load_balancers, I removed a check on the children completely. It was checking for an exitval using children_dataset directly after reap, which should only be true if there was still an active lease for the child. This also deserves careful review. This broke many mocked tests. This fixes the mocked tests to use database-backed objects, ensuring that we are testing observable behavior and not implementation details.
144 lines
2.4 KiB
Ruby
144 lines
2.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
# A no-operation prog for testing.
|
|
class Prog::Test < Prog::Base
|
|
subject_is :sshable
|
|
semaphore :test_semaphore
|
|
|
|
label def start
|
|
end
|
|
|
|
private def fib(n)
|
|
if n < 2
|
|
1
|
|
else
|
|
fib(n - 2) + fib(n - 1)
|
|
end
|
|
end
|
|
|
|
megabyte = (" " * 1024 * 1024)
|
|
|
|
3.times do |n|
|
|
n1 = n + 1
|
|
label(define_method(:"smoke_test_#{n1}") do
|
|
when_test_semaphore_set? do
|
|
decr_test_semaphore
|
|
dynamic_hop :"smoke_test_#{n}"
|
|
end
|
|
|
|
incr_test_semaphore
|
|
|
|
# CPU
|
|
fib(rand(15...25))
|
|
|
|
# IO
|
|
rand(20).times do
|
|
File.write(File::NULL, megabyte)
|
|
end
|
|
|
|
print n1
|
|
nap rand
|
|
end)
|
|
end
|
|
|
|
label def smoke_test_0
|
|
nap 1000
|
|
end
|
|
|
|
label def pusher1
|
|
pop "1" if retval
|
|
push Prog::Test, {test_level: "2"}, :pusher2
|
|
end
|
|
|
|
label def pusher2
|
|
pop frame["test_level"] if retval
|
|
push Prog::Test, {test_level: "3"}, :pusher3
|
|
end
|
|
|
|
label def pusher3
|
|
pop frame["test_level"]
|
|
end
|
|
|
|
label def hop_entry
|
|
hop_hop_exit
|
|
end
|
|
|
|
label def hop_exit
|
|
pop({msg: "hop finished"})
|
|
end
|
|
|
|
label def reaper
|
|
# below loop is only for ensuring we are able to process reaped strands
|
|
reap(reaper: :exitval.to_proc)
|
|
end
|
|
|
|
label def reap_exit_no_children
|
|
reap { pop({msg: "reap_exit_no_children"}) }
|
|
end
|
|
|
|
label def napper
|
|
nap(123)
|
|
end
|
|
|
|
label def popper
|
|
pop({msg: "popped"})
|
|
end
|
|
|
|
label def invalid_hop
|
|
dynamic_hop "hop_exit"
|
|
end
|
|
|
|
label def invalid_hop_target
|
|
dynamic_hop :black_hole
|
|
end
|
|
|
|
label def budder
|
|
bud self.class, frame, :popper
|
|
hop_reaper
|
|
end
|
|
|
|
label def increment_semaphore
|
|
incr_test_semaphore
|
|
donate
|
|
end
|
|
|
|
label def decrement_semaphore
|
|
decr_test_semaphore
|
|
donate
|
|
end
|
|
|
|
label def set_expired_deadline
|
|
register_deadline("pusher2", -1)
|
|
hop_pusher1
|
|
end
|
|
|
|
label def extend_deadline
|
|
register_deadline("pusher2", 1, allow_extension: true)
|
|
hop_pusher1
|
|
end
|
|
|
|
label def set_popping_deadline1
|
|
push Prog::Test, {}, :set_popping_deadline2
|
|
end
|
|
|
|
label def set_popping_deadline_via_bud
|
|
bud Prog::Test, {}, :set_popping_deadline2
|
|
hop_reaper
|
|
end
|
|
|
|
label def set_popping_deadline2
|
|
register_deadline("pusher2", -1)
|
|
hop_popper
|
|
end
|
|
|
|
label def bad_pop
|
|
pop nil
|
|
end
|
|
|
|
label def push_subject_id
|
|
push Prog::Test, {"subject_id" => "70b633b7-1d24-4526-a47f-d2580597d53f"}
|
|
end
|
|
end
|
|
|
|
class Prog::Test2 < Prog::Test
|
|
end
|