Skip to content

Commit

Permalink
use pytest-retry to auto-retry
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbrew committed Sep 28, 2023
1 parent 34fa2ff commit 0ca85bc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def readme():
'moto[server]>=4.0',
'mock>=4.0',
'pytest>=7.2',
'pytest-retry',
],
},
)
3 changes: 3 additions & 0 deletions tests/test_result_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Request(object):

class S3StorageTestCase(S3MockedAsyncTestCase):

@mark.flaky
@gen_test(timeout=45)
async def test_can_get_image(self):
config = Config(TC_AWS_RESULT_STORAGE_BUCKET=s3_bucket)
Expand All @@ -37,6 +38,7 @@ async def test_can_get_image(self):

self.assertEqual(topic.buffer, IMAGE_BYTES)

@mark.flaky
@gen_test(timeout=45)
async def test_can_get_randomized_image(self):
config = Config(TC_AWS_RESULT_STORAGE_BUCKET=s3_bucket, TC_AWS_RANDOMIZE_KEYS=True)
Expand All @@ -51,6 +53,7 @@ async def test_can_get_randomized_image(self):

self.assertEqual(topic.buffer, IMAGE_BYTES)

@mark.flaky
@gen_test(timeout=45)
async def test_can_get_image_with_metadata(self):
config = Config(TC_AWS_RESULT_STORAGE_BUCKET=s3_bucket, TC_AWS_STORE_METADATA=True)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_s3_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from thumbor.context import Context
from thumbor.loaders import LoaderResult
from tornado.testing import gen_test
from pytest import mark

from .fixtures.storage_fixture import IMAGE_PATH, IMAGE_BYTES, s3_bucket
from tc_aws.loaders import s3_loader
Expand All @@ -18,6 +19,7 @@

class S3LoaderTestCase(S3MockedAsyncTestCase):

@mark.flaky
@gen_test(timeout=45)
async def test_can_load_image(self):
client = botocore.session.get_session().create_client('s3', endpoint_url='http://localhost:5000')
Expand All @@ -39,6 +41,7 @@ async def test_can_load_image(self):
self.assertTrue('size' in loader_result.metadata)
self.assertIsNone(loader_result.error)

@mark.flaky
@gen_test(timeout=45)
async def test_returns_404_on_no_image(self):
conf = Config(
Expand All @@ -51,6 +54,7 @@ async def test_returns_404_on_no_image(self):
self.assertIsNone(loader_result.buffer)
self.assertEqual(loader_result.error, LoaderResult.ERROR_NOT_FOUND)

@mark.flaky
@gen_test(timeout=45)
async def test_can_validate_buckets(self):
conf = Config(
Expand All @@ -62,13 +66,15 @@ async def test_can_validate_buckets(self):
self.assertIsNone(image.buffer)

@patch('thumbor.loaders.http_loader.load')
@mark.flaky
@gen_test(timeout=45)
async def test_should_use_http_loader(self, load_sync_patch):
conf = Config(TC_AWS_ENABLE_HTTP_LOADER=True)
await s3_loader.load(Context(config=conf), 'http://foo.bar')
self.assertTrue(load_sync_patch.called)

@patch('thumbor.loaders.http_loader.load')
@mark.flaky
@gen_test(timeout=45)
async def test_should_not_use_http_loader_if_not_prefixed_with_scheme(self, load_sync_patch):
conf = Config(TC_AWS_ENABLE_HTTP_LOADER=True)
Expand Down
12 changes: 11 additions & 1 deletion tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from datetime import datetime, timedelta
from unittest import TestCase
from pytest import raises
from pytest import raises, mark

from dateutil.tz import tzutc
from thumbor.config import Config
Expand All @@ -22,6 +22,7 @@

class S3StorageTestCase(S3MockedAsyncTestCase):

@mark.flaky
@gen_test(timeout=45)
async def test_can_store_image(self):
config = Config(TC_AWS_STORAGE_BUCKET=s3_bucket)
Expand All @@ -32,6 +33,7 @@ async def test_can_store_image(self):

self.assertEqual(topic, IMAGE_BYTES)

@mark.flaky
@gen_test(timeout=45)
async def test_can_get_image_existance(self):
config = Config(TC_AWS_STORAGE_BUCKET=s3_bucket)
Expand All @@ -42,6 +44,7 @@ async def test_can_get_image_existance(self):

self.assertTrue(topic)

@mark.flaky
@gen_test(timeout=45)
async def test_can_get_image_inexistance(self):
config = Config(TC_AWS_STORAGE_BUCKET=s3_bucket)
Expand All @@ -51,6 +54,7 @@ async def test_can_get_image_inexistance(self):

self.assertFalse(topic)

@mark.flaky
@gen_test(timeout=45)
async def test_can_remove_instance(self):
config = Config(TC_AWS_STORAGE_BUCKET=s3_bucket,TC_AWS_STORAGE_ROOT_PATH='nana')
Expand All @@ -61,6 +65,7 @@ async def test_can_remove_instance(self):

self.assertFalse(topic)

@mark.flaky
@gen_test(timeout=45)
async def test_can_remove_then_put_image(self):
config = Config(TC_AWS_STORAGE_BUCKET=s3_bucket)
Expand Down Expand Up @@ -94,6 +99,7 @@ def should_normalize_slash(self):

class CryptoS3StorageTestCase(S3MockedAsyncTestCase):

@mark.flaky
@gen_test(timeout=45)
async def test_should_raise_on_invalid_config(self):
config = Config(TC_AWS_STORAGE_BUCKET=s3_bucket, STORES_CRYPTO_KEY_FOR_EACH_IMAGE=True)
Expand All @@ -104,6 +110,7 @@ async def test_should_raise_on_invalid_config(self):
with raises(RuntimeError, match='STORES_CRYPTO_KEY_FOR_EACH_IMAGE can\'t be True if no SECURITY_KEY specified'):
await storage.put_crypto(IMAGE_URL % '9999')

@mark.flaky
@gen_test(timeout=45)
async def test_getting_crypto_for_a_new_image_returns_none(self):
config = Config(TC_AWS_STORAGE_BUCKET=s3_bucket, STORES_CRYPTO_KEY_FOR_EACH_IMAGE=True)
Expand All @@ -120,6 +127,7 @@ async def test_does_not_store_if_config_says_not_to(self):
topic = await storage.get_crypto(IMAGE_URL % '9998')
self.assertIsNone(topic)

@mark.flaky
@gen_test(timeout=45)
async def test_can_store_crypto(self):
config = Config(TC_AWS_STORAGE_BUCKET=s3_bucket, STORES_CRYPTO_KEY_FOR_EACH_IMAGE=True)
Expand All @@ -135,6 +143,7 @@ async def test_can_store_crypto(self):

class DetectorS3StorageTestCase(S3MockedAsyncTestCase):

@mark.flaky
@gen_test(timeout=45)
async def test_can_store_detector_data(self):
config = Config(TC_AWS_STORAGE_BUCKET=s3_bucket)
Expand All @@ -145,6 +154,7 @@ async def test_can_store_detector_data(self):

self.assertEqual(topic, 'some-data')

@mark.flaky
@gen_test(timeout=45)
async def test_returns_none_if_no_detector_data(self):
config = Config(TC_AWS_STORAGE_BUCKET=s3_bucket)
Expand Down

0 comments on commit 0ca85bc

Please sign in to comment.