/
executor_spec.rb
41 lines (33 loc) · 1.11 KB
/
executor_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# typed: strict
# frozen_string_literal: true
require "spec_helper"
module Tapioca
class ExecutorSpec < Minitest::Spec
describe "Tapioca::Executor" do
before do
@queue = T.let((0...8).to_a, T::Array[Integer])
@executor = T.let(Executor.new(@queue), Executor)
end
it "runs sequentially when the number of workers is one" do
executor = Executor.new(@queue, number_of_workers: 1)
parent_pid = Process.pid
executor.run_in_parallel do
assert_equal(parent_pid, Process.pid)
end
end
it "forks different processes if number of workers is greater than one" do
executor = Executor.new(@queue, number_of_workers: 4)
parent_pid = Process.pid
executor.run_in_parallel do
refute_equal(parent_pid, Process.pid)
end
end
it "can return a value from the parallelized block" do
queue = @queue.dup
executor = Executor.new(@queue, number_of_workers: 4)
result = executor.run_in_parallel { |number| number }
assert_equal(queue, result.sort)
end
end
end
end