Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some small bugs in error handlers for image capture #583

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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