Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion spec/cases/count_open_pipes.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
# frozen_string_literal: true
require './spec/cases/helper'
count = ->(*) { `lsof -l | grep pipe | wc -l`.to_i }
count = ->(*) { Dir.children("/dev/fd").size }

if ENV["SELF_TEST"]
# verify that count detects newly opened pipes
create = 5
before = count.call
pipes = create.times.map { IO.pipe }
after = count.call
expected = before + (create * 2)
raise "expected #{expected} fds but got #{after}" unless after == expected
pipes.each do |r, w|
r.close
w.close
end
end

start = count.call
results = Parallel.map(Array.new(20), in_processes: 20, &count)
puts results.max - start
2 changes: 1 addition & 1 deletion spec/cases/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def process_diff

yield

sleep 1
sleep 0.5

processes_after = `#{cmd}`.to_i

Expand Down
2 changes: 1 addition & 1 deletion spec/cases/parallel_high_fork_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
require './spec/cases/helper'

Parallel.each((0..200).to_a, in_processes: 200) do |_x|
sleep 1
sleep 0.1
end
print 'OK'
2 changes: 1 addition & 1 deletion spec/cases/parallel_map_uneven.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
require './spec/cases/helper'

Parallel.map([1, 2, 1, 2]) do |x|
sleep 2 if x == 1
sleep 1 if x == 1
end
2 changes: 1 addition & 1 deletion spec/cases/parallel_sleeping_2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
require './spec/cases/helper'

Parallel.in_processes(5) do
sleep 2
sleep 1
end
2 changes: 1 addition & 1 deletion spec/cases/progress.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
require './spec/cases/helper'

title = (ENV["TITLE"] == "true" ? true : "Doing stuff")
Parallel.map(1..50, progress: title) do
Parallel.map(1..10, progress: title) do
sleep 1 if $stdout.tty? # for debugging
end
2 changes: 1 addition & 1 deletion spec/cases/progress_with_finish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
sum = 0
finish = ->(_item, _index, result) { sum += result }

Parallel.map(1..50, progress: "Doing stuff", finish: finish) do
Parallel.map(1..10, progress: "Doing stuff", finish: finish) do
sleep 1 if $stdout.tty? # for debugging
2
end
Expand Down
4 changes: 2 additions & 2 deletions spec/cases/with_worker_number.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
method = ENV.fetch('METHOD')
in_worker_type = :"in_#{ENV.fetch('WORKER_TYPE')}"

Parallel.public_send(method, 1..100, in_worker_type => 4) do
sleep 0.1 # so all workers get started
Parallel.public_send(method, 1..20, in_worker_type => 4) do
sleep 0.02 # so all workers get started
print Parallel.worker_number
end
12 changes: 6 additions & 6 deletions spec/parallel_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def cpus
it "saves time" do
time_taken do
ruby("spec/cases/parallel_sleeping_2.rb")
end.should < 3.5
end.should < 2.5
end

it "raises when one of the processes raises" do
Expand Down Expand Up @@ -203,12 +203,12 @@ def cpus
describe ".in_threads" do
it "saves time" do
time_taken do
Parallel.in_threads(3) { sleep 2 }
end.should < 3
Parallel.in_threads(3) { sleep 1 }
end.should < 2
end

it "does not create new processes" do
-> { Thread.new { Parallel.in_threads(2) { sleep 1 } } }.should_not(change { `ps`.split("\n").size })
-> { Thread.new { Parallel.in_threads(2) { sleep 0.5 } } }.should_not(change { `ps`.split("\n").size })
end

it "returns results as array" do
Expand Down Expand Up @@ -245,7 +245,7 @@ def cpus
it "starts new process immediately when old exists" do
time_taken do
ruby("spec/cases/parallel_map_uneven.rb")
end.should <= 3.5
end.should <= 2.5
end

it "does not flatten results" do
Expand Down Expand Up @@ -661,7 +661,7 @@ def cpus
ruby("spec/cases/progress_with_finish.rb 2>&1").strip.sub(/=+/, '==').gsub(
/\n+/,
"\n"
).should == "Doing stuff: |==|\n100"
).should == "Doing stuff: |==|\n20"
end

it "takes the title from :progress[:title] and passes options along" do
Expand Down
Loading