Sha256: 023aefef155491e7b58b5d3ac31c486c5688702cc759d0925f43f139e1429d32

Contents?: true

Size: 1.92 KB

Versions: 5

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

require_relative '../../test_queue'
require_relative '../runner'

module TestQueue
  class Runner
    class Example < Runner
      def initialize(args)
        super(TestFramework::Example.new(args))
      end

      def spawn_workers
        puts "Spawning #{@concurrency} workers"
        super
      end

      def after_fork(num)
        puts "  -- worker #{num} booted as pid #{$$}"
        super
      end

      def run_worker(iterator)
        iterator.inject(0) do |sum, item|
          puts "  #{item.inspect}"
          sum + item.to_i
        end
      end

      def summarize_worker(worker)
        worker.summary = worker.output.scan(/^\s*(\d+)/).join(', ')
        worker.failure_output = ''
      end
    end
  end

  class TestFramework
    class Example < TestFramework
      def initialize(args)
        super()

        @args = args.map(&:to_s)
      end

      def all_suite_files
        @args
      end

      def suites_from_file(_path)
        @args.map { |i| [i, i] }
      end
    end
  end
end

if __FILE__ == $0
  TestQueue::Runner::Example.new(Array(1..10)).execute
end

__END__

Spawning 4 workers
  -- worker 0 booted as pid 40406
  -- worker 1 booted as pid 40407
  -- worker 2 booted as pid 40408
  -- worker 3 booted as pid 40409

==> Starting ruby test-queue worker [1] (40407)

  2
  5
  8

==> Starting ruby test-queue worker [3] (40409)


==> Starting ruby test-queue worker [2] (40408)

  3
  6
  9

==> Starting ruby test-queue worker [0] (40406)

  1
  4
  7
  10

==> Summary

    [1]                                                 2, 5, 8      in 0.0024s      (pid 40407 exit 15)
    [3]                                                              in 0.0036s      (pid 40409 exit 0)
    [2]                                                 3, 6, 9      in 0.0038s      (pid 40408 exit 18)
    [0]                                             1, 4, 7, 10      in 0.0044s      (pid 40406 exit 22)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
test-queue-0.11.1 lib/test_queue/runner/example.rb
test-queue-0.11.0 lib/test_queue/runner/example.rb
test-queue-0.10.0 lib/test_queue/runner/example.rb
test-queue-0.9.0 lib/test_queue/runner/example.rb
test-queue-0.8.0 lib/test_queue/runner/example.rb