Sha256: fff3db848ac173f0cab3d5e0430eecdaad25d8b636cc46020e6f19fc0f837f39

Contents?: true

Size: 1.86 KB

Versions: 72

Compression:

Stored size: 1.86 KB

Contents

# frozen_string_literal: true

require "drb"
require "drb/unix" unless Gem.win_platform?

module ActiveSupport
  module Testing
    class Parallelization # :nodoc:
      class Server
        include DRb::DRbUndumped

        def initialize
          @queue = Queue.new
          @active_workers = Concurrent::Map.new
          @in_flight = Concurrent::Map.new
        end

        def record(reporter, result)
          raise DRb::DRbConnError if result.is_a?(DRb::DRbUnknown)

          @in_flight.delete([result.klass, result.name])

          reporter.synchronize do
            reporter.record(result)
          end
        end

        def <<(o)
          o[2] = DRbObject.new(o[2]) if o
          @queue << o
        end

        def pop
          if test = @queue.pop
            @in_flight[[test[0].to_s, test[1]]] = test
            test
          end
        end

        def start_worker(worker_id)
          @active_workers[worker_id] = true
        end

        def stop_worker(worker_id)
          @active_workers.delete(worker_id)
        end

        def active_workers?
          @active_workers.size > 0
        end

        def interrupt
          @queue.clear
        end

        def shutdown
          # Wait for initial queue to drain
          while @queue.length != 0
            sleep 0.1
          end

          @queue.close

          # Wait until all workers have finished
          while active_workers?
            sleep 0.1
          end

          @in_flight.values.each do |(klass, name, reporter)|
            result = Minitest::Result.from(klass.new(name))
            error = RuntimeError.new("result not reported")
            error.set_backtrace([""])
            result.failures << Minitest::UnexpectedError.new(error)
            reporter.synchronize do
              reporter.record(result)
            end
          end
        end
      end
    end
  end
end

Version data entries

72 entries across 68 versions & 10 rubygems

Version Path
activesupport-7.1.5 lib/active_support/testing/parallelization/server.rb
activesupport-7.2.1.2 lib/active_support/testing/parallelization/server.rb
activesupport-7.1.4.2 lib/active_support/testing/parallelization/server.rb
activesupport-7.0.8.6 lib/active_support/testing/parallelization/server.rb
activesupport-7.2.1.1 lib/active_support/testing/parallelization/server.rb
activesupport-7.1.4.1 lib/active_support/testing/parallelization/server.rb
activesupport-7.0.8.5 lib/active_support/testing/parallelization/server.rb
activesupport-7.1.4 lib/active_support/testing/parallelization/server.rb
activesupport-7.2.1 lib/active_support/testing/parallelization/server.rb
activesupport-7.2.0 lib/active_support/testing/parallelization/server.rb
activesupport-7.2.0.rc1 lib/active_support/testing/parallelization/server.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.8.4/lib/active_support/testing/parallelization/server.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.3.4/lib/active_support/testing/parallelization/server.rb
activesupport-7.2.0.beta3 lib/active_support/testing/parallelization/server.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activesupport-7.0.5.1/lib/active_support/testing/parallelization/server.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activesupport-7.0.5.1/lib/active_support/testing/parallelization/server.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activesupport-7.0.5.1/lib/active_support/testing/parallelization/server.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/testing/parallelization/server.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/testing/parallelization/server.rb
activesupport-7.2.0.beta2 lib/active_support/testing/parallelization/server.rb