Skip to content

Commit

Permalink
Fix failing integration test.
Browse files Browse the repository at this point in the history
This fixes a problem where running the integration tests in parallel
would result in errors because the resource names were based on a
timestamp. Now, a new utility method is used which gives back a
unique ID based on a name, a timestamp, and a random integer.
  • Loading branch information
danielgtaylor committed Dec 5, 2014
1 parent 83e8135 commit 8ea77b9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
13 changes: 13 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

import random
import sys
import time


# The unittest module got a significant overhaul
Expand All @@ -30,6 +32,17 @@
from unittest import mock


def unique_id(name):
"""
Generate a unique ID that includes the given name,
a timestamp and a random number. This helps when running
integration tests in parallel that must create remote
resources.
"""
return '{0}-{1}-{2}'.format(name, int(time.time()),
random.randint(0, 10000))


class BaseTestCase(unittest.TestCase):
"""
A base test case which mocks out the low-level session to prevent
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

import time
import boto3.session

from tests import unittest
from tests import unittest, unique_id


class TestS3Resource(unittest.TestCase):
def setUp(self):
self.session = boto3.session.Session(region_name='us-west-2')
self.s3 = self.session.resource('s3')
self.bucket_name = 'boto3-test-{0}'.format(int(time.time()))
self.bucket_name = unique_id('boto3-test')

def test_s3(self):
client = self.s3.meta['client']
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/test_sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.

import time
import boto3.session

from tests import unittest
from tests import unittest, unique_id


class TestSQSResource(unittest.TestCase):
def setUp(self):
self.session = boto3.session.Session(region_name='us-west-2')
self.sqs = self.session.resource('sqs')
self.queue_name = 'boto3-test-{0}'.format(int(time.time()))
self.queue_name = unique_id('boto3-test')

def test_s3(self):
# Create a new resource
Expand Down

0 comments on commit 8ea77b9

Please sign in to comment.