mirror of
https://github.com/sdsykes/fastimage.git
synced 2025-08-10 00:01:04 -04:00
Correctly break out of http fetches to ensure fast return
This commit is contained in:
parent
cb664556ce
commit
a25363e5bb
@ -201,6 +201,8 @@ class FastImage
|
||||
res.read_body do |str|
|
||||
break if parse_packet(str)
|
||||
end
|
||||
|
||||
break # needed to actively quit out of the fetch
|
||||
end
|
||||
end
|
||||
|
||||
|
1
test/.rbenv-version
Normal file
1
test/.rbenv-version
Normal file
@ -0,0 +1 @@
|
||||
1.8.7-p357
|
19
test/test.rb
19
test/test.rb
@ -26,6 +26,12 @@ BadFixtures = [
|
||||
|
||||
TestUrl = "http://example.nowhere/"
|
||||
|
||||
# this image fetch allows me to really test that fastimage is truly fast
|
||||
# but it's not ideal relying on external resources and connectivity speed
|
||||
LargeImage = "http://upload.wikimedia.org/wikipedia/commons/b/b4/Mardin_1350660_1350692_33_images.jpg"
|
||||
LargeImageInfo = [:jpeg, [9545, 6623]]
|
||||
LargeImageFetchLimit = 2 # seconds
|
||||
|
||||
GoodFixtures.each do |fn, info|
|
||||
FakeWeb.register_uri(:get, "#{TestUrl}#{fn}", :body => File.join(FixturePath, fn))
|
||||
end
|
||||
@ -172,4 +178,17 @@ class FastImageTest < Test::Unit::TestCase
|
||||
resp['Location'] = to
|
||||
FakeWeb.register_uri(:get, from, :response=>resp)
|
||||
end
|
||||
|
||||
def test_should_fetch_info_of_large_image_faster_than_downloading_the_whole_thing
|
||||
time = Time.now
|
||||
size = FastImage.size(LargeImage)
|
||||
size_time = Time.now
|
||||
assert size_time - time < LargeImageFetchLimit
|
||||
assert_equal LargeImageInfo[1], size
|
||||
time = Time.now
|
||||
type = FastImage.type(LargeImage)
|
||||
type_time = Time.now
|
||||
assert type_time - time < LargeImageFetchLimit
|
||||
assert_equal LargeImageInfo[0], type
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user