Skip to content

Commit

Permalink
Test with background thread
Browse files Browse the repository at this point in the history
Use the test case from puma#1868

Looks like puma#1961 does not test with a
background thread
  • Loading branch information
dentarg committed Sep 23, 2019
1 parent 120f247 commit 09e685c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
47 changes: 47 additions & 0 deletions test/rackup/jruby-sigint.ru
@@ -0,0 +1,47 @@
# frozen_string_literal: true

java_import java.util.concurrent.ThreadPoolExecutor
java_import java.lang.Runnable

# From https://github.com/ruby-concurrency/concurrent-ruby/blob/d11b29c37b81320ca7126cc9cd85f4f3d17a78a3/lib/concurrent/executor/java_thread_pool_executor.rb#L111-L117
pool = java.util.concurrent.ThreadPoolExecutor.new(
2,
2,
60,
java.util.concurrent.TimeUnit::SECONDS,
java.util.concurrent.LinkedBlockingQueue.new,
java.util.concurrent.ThreadPoolExecutor::AbortPolicy.new
)

# From concurrent-ruby: https://github.com/ruby-concurrency/concurrent-ruby/blob/d11b29c37b81320ca7126cc9cd85f4f3d17a78a3/lib/concurrent/executor/java_executor_service.rb#L77-L87
class Job
include Runnable
def initialize(args, block)
@args = args
@block = block
end

def run
@block.call(*@args)
end
end

2.times do
pool.submit Job.new(nil, proc { sleep })
end

at_exit do
# Request threadpool shutdown.
pool.shutdown
# Add two seconds wait to let the threads finish and then kill the threads.
deadline = Time.now + 2
while true
break if pool.get_active_count.zero?
if Time.now > deadline
pool.shutdownNow
break
end
end
end

run lambda { |env| [200, {"Content-Type" => "text/plain"}, ["Hello World"]] }
2 changes: 1 addition & 1 deletion test/test_integration_single.rb
Expand Up @@ -75,7 +75,7 @@ def test_term_not_accepts_new_connections
def test_int_refuse
skip_unless_signal_exist? :INT

cli_server 'test/rackup/hello.ru'
cli_server 'test/rackup/jruby-sigint.ru'
begin
sock = TCPSocket.new(HOST, @tcp_port)
sock.close
Expand Down

0 comments on commit 09e685c

Please sign in to comment.