Skip to content

Commit

Permalink
Pass invalid_image_name into each image saving job
Browse files Browse the repository at this point in the history
I think this got accidentally merged away in:
546c713#diff-b6c1420e088ed8e1127a35c6ac8ec84eL79

Without it, when we fail to capture an image, we also fail to create a
dummy one to stand in for it.
  • Loading branch information
Steve Day authored and Steve Day committed Sep 7, 2018
1 parent f4859e5 commit 68ccfe6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion 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
Binary file added spec/images/invalid1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions spec/save_images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,25 @@
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 it's md5 easily
jobs = [
['test', '/test/path', '1500x1500', test_url1, test_image1, nil, nil, nil,
'invalid1.jpg']
]
saving.parallel_task(jobs)
# Test fixture image created from the original invalid image because
# the original is a jpg
invalid_image = get_path_relative_to __FILE__, "./images/invalid1.png"
invalid_md5 = Digest::MD5.hexdigest(File.read(invalid_image))
created_md5 = Digest::MD5.hexdigest(File.read(test_image1))
expect(created_md5).to eq invalid_md5
end
end
end
end

0 comments on commit 68ccfe6

Please sign in to comment.