Skip to content

Commit 25b139c

Browse files
committed
Add hup-test example.
1 parent ab31f7e commit 25b139c

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

examples/hup-test/child.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env ruby
2+
3+
require_relative '../../lib/async'
4+
require 'console'
5+
6+
Async do |task|
7+
while true
8+
task.async do
9+
Console.logger.info("Child running.")
10+
sleep 0.1
11+
end.wait
12+
end
13+
end
14+
15+
# ruby3-tcp-server-mini-benchmark$ ruby loop.rb async-scheduler.rb
16+
# spawn
17+
# /usr/bin/wrk -t1 -c1 -d1s http://localhost:9090
18+
# waiting for process to die
19+
# spawn
20+
# /usr/bin/wrk -t1 -c1 -d1s http://localhost:9090
21+
# waiting for process to die
22+
# ^Cloop.rb:24:in `waitpid': Interrupt
23+
# from loop.rb:24:in `block in <main>'
24+
# from loop.rb:15:in `loop'
25+
# from loop.rb:15:in `<main>'
26+
# /home/jsaak/.gem/ruby/3.2.1/gems/async-2.6.1/lib/async/list.rb:250:in `initialize': Interrupt
27+
# from /home/jsaak/.gem/ruby/3.2.1/gems/async-2.6.1/lib/async/list.rb:298:in `new'
28+
# from /home/jsaak/.gem/ruby/3.2.1/gems/async-2.6.1/lib/async/list.rb:298:in `each'
29+
# from /home/jsaak/.gem/ruby/3.2.1/gems/async-2.6.1/lib/async/list.rb:176:in `each'
30+
# from /home/jsaak/.gem/ruby/3.2.1/gems/async-2.6.1/lib/async/node.rb:240:in `terminate'
31+
# from /home/jsaak/.gem/ruby/3.2.1/gems/async-2.6.1/lib/async/scheduler.rb:52:in `close'
32+
# from /home/jsaak/.gem/ruby/3.2.1/gems/async-2.6.1/lib/async/scheduler.rb:46:in `ensure in scheduler_close'
33+
# from /home/jsaak/.gem/ruby/3.2.1/gems/async-2.6.1/lib/async/scheduler.rb:46:in `scheduler_close'
34+
# /home/jsaak/.gem/ruby/3.2.1/gems/async-2.6.1/lib/async/node.rb:110:in `transient?': SIGHUP (SignalException)
35+
# from /home/jsaak/.gem/ruby/3.2.1/gems/async-2.6.1/lib/async/node.rb:47:in `removed'
36+
# from /home/jsaak/.gem/ruby/3.2.1/gems/async-2.6.1/lib/async/list.rb:132:in `remove!'
37+
# from /home/jsaak/.gem/ruby/3.2.1/gems/async-2.6.1/lib/async/list.rb:121:in `remove'
38+
# from /home/jsaak/.gem/ruby/3.2.1/gems/async-2.6.1/lib/async/node.rb:182:in `remove_child'
39+
# from /home/jsaak/.gem/ruby/3.2.1/gems/async-2.6.1/lib/async/node.rb:197:in `consume'
40+
# from /home/jsaak/.gem/ruby/3.2.1/gems/async-2.6.1/lib/async/task.rb:287:in `finish!'
41+
# from /home/jsaak/.gem/ruby/3.2.1/gems/async-2.6.1/lib/async/task.rb:360:in `block in schedule'
42+

examples/hup-test/main.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env ruby
2+
3+
require 'console'
4+
5+
while true
6+
pid = Process.spawn("./child.rb")
7+
Console.logger.info("Spawned child.", pid: pid)
8+
sleep 2
9+
Console.logger.info("Sending HUP to child.", pid: pid)
10+
Process.kill(:HUP, pid)
11+
status = Process.waitpid(pid)
12+
Console.logger.info("Child exited.", pid: pid, status: status)
13+
end

0 commit comments

Comments
 (0)