File: worker_pool_test.rb

package info (click to toggle)
ruby-bootsnap 1.22.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 520 kB
  • sloc: ruby: 3,637; ansic: 844; sh: 14; makefile: 9
file content (23 lines) | stat: -rw-r--r-- 581 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

require "test_helper"
require "bootsnap/cli"

module Bootsnap
  class WorkerPoolTestTest < Minitest::Test
    def test_dispatch
      @pool = CLI::WorkerPool.create(size: 2, jobs: {touch: ->(path) { File.write(path, Process.pid.to_s) }})
      @pool.spawn

      Dir.mktmpdir("bootsnap-test") do |tmpdir|
        10.times do |i|
          @pool.push(:touch, File.join(tmpdir, i.to_s))
        end

        @pool.shutdown
        files = Dir.chdir(tmpdir) { Dir["*"] }.sort
        assert_equal 10.times.map(&:to_s), files
      end
    end
  end
end