diff --git a/CHANGELOG.md b/CHANGELOG.md index b84360bc..a5104ae9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,9 @@ to docs, or any other relevant information. ### Added +- `Temporalio::Worker::ThreadPool::ThreadContext` can be passed to `ThreadPool.new` as + `thread_context:` to wrap the execution of the body of each pool thread. + ### Changed - Priority is no longer marked as experimental. diff --git a/README.md b/README.md index ba765e59..0e330f81 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ Also see: - [Activity Heartbeating and Cancellation](#activity-heartbeating-and-cancellation) - [Activity Worker Shutdown](#activity-worker-shutdown) - [Activity Concurrency and Executors](#activity-concurrency-and-executors) + - [Per-Thread Setup for the Thread Pool Executor](#per-thread-setup-for-the-thread-pool-executor) - [Activity Testing](#activity-testing) - [Telemetry](#telemetry) - [Metrics](#metrics) @@ -1084,6 +1085,52 @@ Technically the executor can be customized. The `activity_executors` worker opti symbol and the value as a `Temporalio::Worker::ActivityExecutor` implementation. Users should usually not need to customize this. If general code is needed to run around activities, users should use interceptors instead. +#### Per-Thread Setup for the Thread Pool Executor + +To acquire a resource once per thread and reuse it across every activity that thread runs -- a database connection, say +-- pass a `Temporalio::Worker::ThreadPool::ThreadContext` when constructing a thread pool. The context's `call` method +receives a block that executes the worker's assigned tasks, and should be called exactly once. `call` should not +raise. Acquired resources should be released in an `ensure`, not directly after `yield`: + +```ruby +class DatabaseConnectionContext < Temporalio::Worker::ThreadPool::ThreadContext + def call + connection = MyDatabase.connect + Thread.current[:my_connection] = connection + yield + ensure + Thread.current[:my_connection] = nil + connection&.close + end +end + +pool = Temporalio::Worker::ThreadPool.new(thread_context: DatabaseConnectionContext.new) +executor = Temporalio::Worker::ActivityExecutor::ThreadPool.new(pool) + +worker = Temporalio::Worker.new( + client:, + task_queue: 'my-task-queue', + activities: [MyActivity], + activity_executors: Temporalio::Worker::ActivityExecutor.defaults.merge(default: executor) +) +``` + +Note: + +* You must explicitly construct and use a pool and executor with your custom thread context. The default pool + has no context. +* `call` must invoke the block exactly once. Invoking it again re-enters a loop the pool has stopped tracking, which + blocks that thread forever; not invoking it means the thread never runs any work. +* Clean up in an `ensure`. On a normal stop the block returns and code after the `yield` does run, but + `Temporalio::Worker::ThreadPool#kill` terminates the thread without letting the block return, so only an `ensure` + runs on every path. +* This is not an interceptor. A context wraps a thread's whole lifetime, not a single activity execution. To run code + around each activity, use an interceptor instead. +* The `call` wrapper should not raise. If it does, work already queued on the worker is dropped silently (and thus + will time out and be retried). The thread is dropped from the pool, and a new one is started when more work + arrives. Pass `restart_worker: true` to the `ThreadContext` constructor to start a replacement immediately instead; + a context that always raises will then restart without bound. + #### Activity Testing Unit testing an activity can be done via the `Temporalio::Testing::ActivityEnvironment` class. Simply instantiate the diff --git a/temporalio/lib/temporalio/worker/thread_pool.rb b/temporalio/lib/temporalio/worker/thread_pool.rb index 4d8c7d60..37f611f6 100644 --- a/temporalio/lib/temporalio/worker/thread_pool.rb +++ b/temporalio/lib/temporalio/worker/thread_pool.rb @@ -10,6 +10,56 @@ class ThreadPool # see MIT license at # https://github.com/ruby-concurrency/concurrent-ruby/blob/044020f44b36930b863b930f3ee8fa1e9f750469/LICENSE.txt + # Wraps the body of each pool thread, for acquiring a resource when a thread starts and + # releasing it when the thread exits. Since the block is invoked for the entire lifetime of + # the thread, a resource acquired around it can be released from an `ensure`. + # + # The `call` wrapper should not raise. `call` has the responsibility for calling the + # passed block exactly once, and rescuing all exceptions and errors. If the `call` wrapper + # cannot invoke the block, the block is not re-queued. + # + # If the `call` wrapper does raise, the exception is swallowed, and the worker dies. + # The `restart_worker` constructor parameter determines whether a new worker is + # immediately created to replace the one that died. It defaults to false to avoid + # a rapid fail-and-restart loop. + # + # @note The same instance is used by every thread in the pool, so implementations must be + # thread safe. Per-thread state belongs in the block, not in the ThreadContext object. + class ThreadContext + # @return [ThreadContext] Default context that just invokes the block. + def self.default + @default ||= NoOp.new + end + + # @return [Boolean] Whether a thread whose context raised is replaced with a new one. + attr_reader :restart_worker + + # @param restart_worker [Boolean] What to do when {call} raises. When false, the thread is + # dropped from the pool and a new one is started only when more work arrives. When true, + # a replacement thread is started immediately, which invokes {call} again -- so a context + # that always raises will restart without bound. + def initialize(restart_worker: false) + @restart_worker = restart_worker + end + + # Invoke the given block for the lifetime of a pool thread. Implementations must invoke + # the block exactly once; invoking it again re-enters a loop the pool has stopped tracking, + # which blocks that thread forever and skips the rest of this method. + # + # @yield Block to invoke for the lifetime of the thread. + def call(&) + raise NotImplementedError + end + + # @!visibility private + class NoOp < ThreadContext + # @see ThreadContext.call + def call(&) + yield + end + end + end + # @return [ThreadPool] Default/shared thread pool instance with unlimited max threads. def self.default @default ||= new @@ -25,9 +75,12 @@ def self._monotonic_time # @param max_threads [Integer, nil] Maximum number of thread workers to create, or nil for unlimited max. # @param idle_timeout [Float] Number of seconds before a thread worker with no work should be stopped. Note, # the check of whether a thread worker is idle is only done on each new {execute} call. - def initialize(max_threads: nil, idle_timeout: 20) + # @param thread_context [ThreadContext] Invoked around the body of each thread this pool starts, for + # acquiring and releasing per-thread resources. Defaults to one that adds no behavior. + def initialize(max_threads: nil, idle_timeout: 20, thread_context: ThreadContext.default) @max_threads = max_threads @idle_timeout = idle_timeout + @thread_context = thread_context @mutex = Mutex.new @pool = [] @@ -123,6 +176,16 @@ def _worker_task_completed @mutex.synchronize { @completed_task_count += 1 } end + # @!visibility private + def _thread_context + @thread_context + end + + # @!visibility private + def _remove_ready_worker(worker) + @mutex.synchronize { @ready.reject! { |ready_worker, _| ready_worker.equal?(worker) } } + end + private def locked_assign_worker(&block) # rubocop:disable Naming/PredicateMethod @@ -188,12 +251,34 @@ def locked_worker_died(worker) class Worker def initialize(pool, id) @queue = Queue.new - @thread = Thread.new(@queue, pool) do |my_queue, my_pool| + @thread = Thread.new(@queue, pool) { |my_queue, my_pool| worker_loop(my_queue, my_pool) } + @thread.name = "temporal-thread-#{id}" + end + + # @!visibility private + def <<(block) + @queue << block + end + + # @!visibility private + def stop + @queue << :stop + end + + # @!visibility private + def kill + @thread.kill + end + + private + + def worker_loop(my_queue, my_pool) + my_pool._thread_context.call do catch(:stop) do loop do case block = my_queue.pop when :stop - pool._remove_busy_worker(self) + my_pool._remove_busy_worker(self) throw :stop else begin @@ -212,22 +297,19 @@ def initialize(pool, id) end end end - @thread.name = "temporal-thread-#{id}" + rescue Exception => e # rubocop:disable Lint/RescueException + handle_thread_context_exception(my_pool, e) end - # @!visibility private - def <<(block) - @queue << block - end - - # @!visibility private - def stop - @queue << :stop - end - - # @!visibility private - def kill - @thread.kill + # Removes the worker, and creates a replacement iff restart_worker is true. + def handle_thread_context_exception(my_pool, err) + warn("Unexpected thread context exception: #{err.full_message}") + my_pool._remove_ready_worker(self) + if my_pool._thread_context.restart_worker + my_pool._worker_died(self) + else + my_pool._remove_busy_worker(self) + end end end diff --git a/temporalio/rbi/temporalio/worker/thread_pool.rbi b/temporalio/rbi/temporalio/worker/thread_pool.rbi index 8f069417..77c03f3b 100644 --- a/temporalio/rbi/temporalio/worker/thread_pool.rbi +++ b/temporalio/rbi/temporalio/worker/thread_pool.rbi @@ -6,8 +6,14 @@ class Temporalio::Worker::ThreadPool sig { returns(Temporalio::Worker::ThreadPool) } def self.default; end - sig { params(max_threads: T.nilable(Integer), idle_timeout: Float).void } - def initialize(max_threads: T.unsafe(nil), idle_timeout: T.unsafe(nil)); end + sig do + params( + max_threads: T.nilable(Integer), + idle_timeout: Float, + thread_context: Temporalio::Worker::ThreadPool::ThreadContext + ).void + end + def initialize(max_threads: T.unsafe(nil), idle_timeout: T.unsafe(nil), thread_context: T.unsafe(nil)); end sig { params(block: T.proc.void).void } def execute(&block); end @@ -36,3 +42,26 @@ class Temporalio::Worker::ThreadPool sig { void } def kill; end end + +class Temporalio::Worker::ThreadPool::ThreadContext + extend T::Sig + + sig { returns(Temporalio::Worker::ThreadPool::ThreadContext) } + def self.default; end + + sig { returns(T::Boolean) } + attr_reader :restart_worker + + sig { params(restart_worker: T::Boolean).void } + def initialize(restart_worker: T.unsafe(nil)); end + + sig { params(block: T.proc.void).void } + def call(&block); end +end + +class Temporalio::Worker::ThreadPool::ThreadContext::NoOp < Temporalio::Worker::ThreadPool::ThreadContext + extend T::Sig + + sig { params(block: T.proc.void).void } + def call(&block); end +end diff --git a/temporalio/sig/temporalio/worker/activity_executor/thread_pool.rbs b/temporalio/sig/temporalio/worker/activity_executor/thread_pool.rbs index 037f93b7..5af7d78c 100644 --- a/temporalio/sig/temporalio/worker/activity_executor/thread_pool.rbs +++ b/temporalio/sig/temporalio/worker/activity_executor/thread_pool.rbs @@ -4,7 +4,7 @@ module Temporalio class ThreadPool < ActivityExecutor def self.default: -> ThreadPool - def initialize: (?ThreadPool thread_poll) -> void + def initialize: (?::Temporalio::Worker::ThreadPool thread_pool) -> void end end end diff --git a/temporalio/sig/temporalio/worker/thread_pool.rbs b/temporalio/sig/temporalio/worker/thread_pool.rbs index 66986c9a..a9787abb 100644 --- a/temporalio/sig/temporalio/worker/thread_pool.rbs +++ b/temporalio/sig/temporalio/worker/thread_pool.rbs @@ -1,13 +1,25 @@ module Temporalio class Worker class ThreadPool + class ThreadContext + def self.default: -> ThreadContext + attr_reader restart_worker: bool + def initialize: (?restart_worker: bool) -> void + def call: { -> void } -> void + + class NoOp < ThreadContext + def call: { -> void } -> void + end + end + def self.default: -> ThreadPool def self._monotonic_time: -> Float def initialize: ( ?max_threads: Integer?, - ?idle_timeout: Float + ?idle_timeout: Float, + ?thread_context: ThreadContext ) -> void def execute: { -> void } -> void @@ -25,6 +37,8 @@ module Temporalio def _ready_worker: (Worker worker, Float last_message) -> void def _worker_died: (Worker worker) -> void def _worker_task_completed: -> void + def _thread_context: -> ThreadContext + def _remove_ready_worker: (Worker worker) -> void private def locked_assign_worker: { (?) -> untyped } -> void private def locked_enqueue: { (?) -> untyped } -> void private def locked_add_busy_worker: -> Worker? @@ -38,6 +52,9 @@ module Temporalio def <<: (Proc block) -> void def stop: -> void def kill: -> void + + private def worker_loop: (Thread::Queue my_queue, ThreadPool my_pool) -> void + private def handle_thread_context_exception: (ThreadPool my_pool, Exception err) -> void end end end diff --git a/temporalio/test/sig/worker_thread_context_test.rbs b/temporalio/test/sig/worker_thread_context_test.rbs new file mode 100644 index 00000000..6fc5ad94 --- /dev/null +++ b/temporalio/test/sig/worker_thread_context_test.rbs @@ -0,0 +1,9 @@ +class WorkerThreadContextTest < Test + class CountingContext < Temporalio::Worker::ThreadPool::ThreadContext + def initialize: (fail_times: Numeric, ?restart_worker: bool) -> void + def count: -> Integer + def call: { -> void } -> void + end + + def run_and_wait: (Temporalio::Worker::ThreadPool pool, ?timeout: Float) -> void +end diff --git a/temporalio/test/thread_context_recorder.rb b/temporalio/test/thread_context_recorder.rb new file mode 100644 index 00000000..e23173fb --- /dev/null +++ b/temporalio/test/thread_context_recorder.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +require 'temporalio/worker/thread_pool' + +# Thread context for tests: sets a thread-local for the lifetime of each pool thread and clears it +# on the way out, so work running on that thread can observe it and a test can observe the +# teardown. `entered`, `returned` and `exited` are queues because they are pushed to from pool +# threads, which outlive the work they run. +# +# `returned` records reaching the statement after the `yield`, which only happens when the block +# returns normally -- not when the thread is killed inside it. +class ThreadContextRecorder < Temporalio::Worker::ThreadPool::ThreadContext + VALUE_KEY = :thread_context_value + + attr_reader :entered, :returned, :exited + + def initialize(value: 'acquired') + super() + @value = value + @entered = Queue.new + @returned = Queue.new + @exited = Queue.new + end + + def call + Thread.current[VALUE_KEY] = @value + @entered.push(Thread.current.name) + yield + @returned.push(Thread.current.name) + ensure + Thread.current[VALUE_KEY] = nil + @exited.push(Thread.current.name) + end +end diff --git a/temporalio/test/worker_activity_test.rb b/temporalio/test/worker_activity_test.rb index b4ad7800..62381fe8 100644 --- a/temporalio/test/worker_activity_test.rb +++ b/temporalio/test/worker_activity_test.rb @@ -8,6 +8,7 @@ require 'temporalio/testing' require 'temporalio/worker' require 'test' +require 'thread_context_recorder' class WorkerActivityTest < Test also_run_all_tests_in_fiber @@ -910,6 +911,33 @@ def test_custom_executor execute_activity(CustomExecutorActivity, activity_executors: { my_executor: CustomExecutor.new }) end + class ThreadContextActivity < Temporalio::Activity::Definition + activity_executor :context_executor + + def execute + "context val: #{Thread.current[ThreadContextRecorder::VALUE_KEY]}" + end + end + + exclude_from_cloud :needs_cloud_adaptation, + 'The Go kitchen-sink worker does not receive Cloud TLS configuration.' + def test_thread_pool_thread_context_wraps_activity + context = ThreadContextRecorder.new + pool = Temporalio::Worker::ThreadPool.new(thread_context: context) + executor = Temporalio::Worker::ActivityExecutor::ThreadPool.new(pool) + + assert_equal 'context val: acquired', + execute_activity(ThreadContextActivity, activity_executors: { context_executor: executor }) + + # The context is still active + assert_empty context.exited + + pool.shutdown + assert_eventually { refute_empty context.exited, 'thread context did not release when the pool shut down' } + ensure + pool&.kill + end + class ConcurrentActivity < Temporalio::Activity::Definition def initialize @started = Queue.new diff --git a/temporalio/test/worker_thread_context_test.rb b/temporalio/test/worker_thread_context_test.rb new file mode 100644 index 00000000..d0325c1e --- /dev/null +++ b/temporalio/test/worker_thread_context_test.rb @@ -0,0 +1,280 @@ +# frozen_string_literal: true + +require 'temporalio/worker/thread_pool' +require 'test' +require 'thread_context_recorder' + +class WorkerThreadContextTest < Test + # Raises the first `fail_times` invocations, then yields. `count` is the number of + # invocations/threads. + class CountingContext < Temporalio::Worker::ThreadPool::ThreadContext + def initialize(fail_times:, restart_worker: false) + super(restart_worker:) + @fail_times = fail_times + @mutex = Mutex.new + @count = 0 + end + + def count + @mutex.synchronize { @count } + end + + def call + n = @mutex.synchronize { @count += 1 } + raise "context failed (attempt #{n})" if n <= @fail_times + + yield + end + end + + # Blocks until the pool runs something on a thread, so the thread is known to exist and to have + # entered its context. Fails rather than hanging if that never happens. + def run_and_wait(pool, timeout: 10) + done = Queue.new + pool.execute { done.push(:ran) } + assert_equal :ran, done.pop(timeout:), 'pool never ran the block' + end + + def test_default_context_is_no_op + pool = Temporalio::Worker::ThreadPool.new + ran = Queue.new + pool.execute { ran.push(42) } + seen = ran.pop(timeout: 10) + assert_equal seen, 42, 'pool never ran the block' + ensure + pool&.shutdown + end + + def test_context_wraps_work_on_the_thread + context = ThreadContextRecorder.new + pool = Temporalio::Worker::ThreadPool.new(thread_context: context) + + seen = Queue.new + pool.execute { seen.push(Thread.current[ThreadContextRecorder::VALUE_KEY]) } + + assert_equal 'acquired', seen.pop(timeout: 10) + refute_empty context.entered + assert_empty context.exited, 'context must not have exited while the thread is still alive' + ensure + pool&.shutdown + end + + def test_context_wraps_every_thread_in_the_pool + context = ThreadContextRecorder.new + pool = Temporalio::Worker::ThreadPool.new(thread_context: context) + + release = Queue.new + seen = Queue.new + # Ensure two threads are running. + 2.times do + pool.execute do + seen.push(Thread.current[ThreadContextRecorder::VALUE_KEY]) + release.pop + end + end + assert_equal %w[acquired acquired], [seen.pop, seen.pop] + 2.times { release.push(nil) } + + assert_equal 2, pool.largest_length + assert_equal 2, context.entered.size + ensure + 2.times { release&.push(nil) } + pool&.shutdown + end + + def test_context_released_on_graceful_shutdown + context = ThreadContextRecorder.new + pool = Temporalio::Worker::ThreadPool.new(thread_context: context) + run_and_wait(pool) + assert_empty context.exited + + pool.shutdown + + assert_eventually { refute_empty context.exited, 'context did not exit on graceful shutdown' } + end + + def test_context_released_on_idle_timeout_prune + context = ThreadContextRecorder.new + # We need two threads to make sure there is one that can be pruned. + pool = Temporalio::Worker::ThreadPool.new(idle_timeout: 0.05, thread_context: context) + release = Queue.new + started = Queue.new + 2.times do + pool.execute do + started.push(:started) + release.pop + end + end + 2.times { assert_equal :started, started.pop(timeout: 10), 'thread never started' } + 2.times { release.push(nil) } + assert_eventually { assert_equal 0, pool.active_count, 'threads did not go idle' } + assert_equal 2, pool.length + assert_empty context.exited + + # Pruning only happens inside `execute`. + sleep(0.2) + assert_eventually do + pool.execute { nil } + refute_empty context.exited, 'context did not exit when its idle thread was pruned' + end + assert_eventually { assert_operator pool.length, :<, 2, 'pruned thread was not removed from the pool' } + ensure + pool&.shutdown + end + + def test_context_released_on_kill + context = ThreadContextRecorder.new + pool = Temporalio::Worker::ThreadPool.new(thread_context: context) + started = Queue.new + blocked = Queue.new + pool.execute do + started.push(:started) + blocked.pop # blocks + end + assert_equal :started, started.pop(timeout: 10), 'thread never started' + assert_empty context.exited + + pool.kill + + assert_eventually { refute_empty context.exited, 'context did not exit on kill' } + end + + def test_stop_runs_code_after_the_yield + context = ThreadContextRecorder.new + pool = Temporalio::Worker::ThreadPool.new(thread_context: context) + run_and_wait(pool) + assert_empty context.returned + + pool.shutdown + + assert_eventually { refute_empty context.exited, 'context did not exit on graceful shutdown' } + refute_empty context.returned, 'stop did not return through the context; code after the yield never ran' + end + + def test_kill_does_not_run_code_after_the_yield + context = ThreadContextRecorder.new + pool = Temporalio::Worker::ThreadPool.new(thread_context: context) + started = Queue.new + blocked = Queue.new + pool.execute do + started.push(:started) + blocked.pop # blocks + end + assert_equal :started, started.pop(timeout: 10), 'thread never started' + + pool.kill + + assert_eventually { refute_empty context.exited, 'context did not exit on kill' } + assert_empty context.returned, 'kill let the context return normally' + end + + def test_raising_context_kills_only_its_own_thread + context = CountingContext.new(fail_times: 1) + pool = Temporalio::Worker::ThreadPool.new(thread_context: context) + + # Submit both up front. The first worker's context raises, so that worker never completes a + # task and so never enters the ready list -- which makes the second `execute` create a fresh + # worker rather than reuse the dead one. + first = Queue.new + second = Queue.new + safe_capture_io do + pool.execute { first.push(:ran) } + pool.execute { second.push(:ran) } + + assert_eventually { assert_operator context.count, :>=, 1, 'context never raised' } + assert_equal :ran, second.pop(timeout: 10), 'second thread never ran its work' + end + + assert_empty first, 'block ran even though its context raised' + assert_equal 2, context.count, 'a second thread was not created' + ensure + pool&.kill + end + + # A worker whose context raises must not be left in the pool with a dead thread behind it. + def test_raising_context_removes_its_worker_from_the_pool + context = CountingContext.new(fail_times: Float::INFINITY) + pool = Temporalio::Worker::ThreadPool.new(thread_context: context) + + safe_capture_io do + pool.execute { nil } + assert_eventually { assert_operator context.count, :>=, 1, 'context never raised' } + end + + assert_eventually { assert_equal 0, pool.length, 'dead worker was left in the pool' } + ensure + pool&.kill + end + + def test_raising_context_does_not_spawn_replacement_threads + context = CountingContext.new(fail_times: Float::INFINITY) + pool = Temporalio::Worker::ThreadPool.new(thread_context: context) + + safe_capture_io do + pool.execute { nil } + assert_eventually { assert_operator context.count, :>=, 1, 'context never raised' } + end + + sleep(0.5) + assert_equal 1, context.count, 'context ran on new replacement threads' + ensure + pool&.kill + end + + def test_kill_does_not_spawn_replacement_threads + context = ThreadContextRecorder.new + pool = Temporalio::Worker::ThreadPool.new(thread_context: context) + run_and_wait(pool) + assert_equal 1, pool.length + + pool.kill + + assert_eventually { refute_empty context.exited, 'context did not exit on kill' } + sleep(0.3) + assert_equal 0, pool.length, 'kill left workers in the pool' + assert_equal 1, pool.largest_length, 'kill spawned a replacement thread' + end + + def test_restart_worker_restarts_the_thread_until_the_context_succeeds + context = CountingContext.new(fail_times: 10, restart_worker: true) + pool = Temporalio::Worker::ThreadPool.new(thread_context: context) + + safe_capture_io do + pool.execute { nil } + # Each restart re-invokes the context with no further work submitted, so reaching 11 means + # the 10 failures each produced a replacement thread. + assert_eventually { assert_operator context.count, :>=, 11, 'context did not restart until it succeeded' } + end + + sleep(0.3) + assert_equal 11, context.count, 'context kept restarting after it stopped raising' + assert_equal 1, pool.length, 'only the last restart should leave a thread in the pool' + + live = pool.instance_variable_get(:@pool) + ready = pool.instance_variable_get(:@ready).map(&:first) + assert_empty ready.reject { |w| live.include?(w) }, 'restarts left dead workers in the ready list' + + ran = Queue.new + 10.times { pool.execute { ran.push(:ran) } } + assert_eventually { assert_equal 10, ran.size, 'not all tasks ran after the restarts' } + ensure + pool&.kill + end + + def test_base_context_is_abstract + pool = Temporalio::Worker::ThreadPool.new(thread_context: Temporalio::Worker::ThreadPool::ThreadContext.new) + + ran = Queue.new + # The thread warns before dropping itself from the pool, so an empty pool means the message has + # already been written. + _, err = safe_capture_io do + pool.execute { ran.push(:ran) } + assert_eventually { assert_equal 0, pool.length, 'abstract context left its worker in the pool' } + end + + assert_includes err, 'NotImplementedError' + assert_empty ran, 'block ran even though the context is abstract' + ensure + pool&.kill + end +end