Skip to content
Open
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
4 changes: 2 additions & 2 deletions lib/wraith/save_images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def run_command(command)
end

def parallel_task(jobs)
Parallel.each(jobs, :in_threads => wraith.threads) do |_label, _path, width, url, filename, selector, global_before_capture, path_before_capture|
Parallel.each(jobs, :in_threads => wraith.threads) do |_label, _path, width, url, filename, selector, global_before_capture, path_before_capture, invalid_image_name|
begin
if meta.engine == "chrome"
capture_image_selenium(width, url, filename, selector, global_before_capture, path_before_capture)
Expand Down Expand Up @@ -143,7 +143,7 @@ def capture_image_selenium(screen_sizes, url, file_name, selector, global_before
crop_selector(driver, selector, new_file_name) if selector && selector.length > 0
break
rescue Net::ReadTimeout => e
logger.error "Got #{e} on attempt #{attempt} at screen size #{screensize}. URL = #{url}"
logger.error "Got #{e} on attempt #{attempt} at screen size #{screen_size}. URL = #{url}"
end
end
end
Expand Down
27 changes: 27 additions & 0 deletions spec/save_images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,31 @@
expect(File).to exist("shots/thumbnails/test/test_diff.png")
end
end

describe "when parallelising jobs" do
context "when something goes wrong" do
it "creates a dummy invalid image" do
allow(saving).to receive(:attempt_image_capture).and_raise("boom")
# Create the image at the original res of the invalid image, so that we
# can compare its md5 easily
jobs = [
['test', '/test/path', '1500x1500', test_url1, test_image1, nil, nil, nil,
'invalid1.jpg']
]
saving.parallel_task(jobs)
# Create the expected image so we can compare them, because they'll
# differ between imagemagick versions and platforms and so we can't just
# use a fixture.
saving.create_invalid_image("shots/test/invalid1.png", 1500, "invalid1.jpg")
Wraith::CompareImages.new(config_name).compare_task(
test_image1,
"shots/test/invalid1.png",
"shots/test/test_diff.png",
"shots/test/test.txt"
)
diff = File.open("shots/test/test.txt", "rb").read
expect(diff).to eq "0.0"
end
end
end
end