Merge "Don't use override_time but mock instead"

This commit is contained in:
Jenkins
2014-01-23 18:29:49 +00:00
committed by Gerrit Code Review
3 changed files with 42 additions and 39 deletions

View File

@@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import datetime
import time import time
import uuid import uuid
@@ -209,15 +210,12 @@ class MongodbMessageTests(base.MessageControllerTest):
unchanged = self.queue_controller._inc_counter(queue_name, window=10) unchanged = self.queue_controller._inc_counter(queue_name, window=10)
self.assertIsNone(unchanged) self.assertIsNone(unchanged)
# TODO(kgriffs): Pass utcnow to work around bug now = timeutils.utcnow() + datetime.timedelta(seconds=10)
# in set_time_override until we merge the fix in timeutils_utcnow = 'marconi.openstack.common.timeutils.utcnow'
# from upstream. with mock.patch(timeutils_utcnow) as mock_utcnow:
timeutils.set_time_override(timeutils.utcnow()) mock_utcnow.return_value = now
timeutils.advance_time_seconds(10)
changed = self.queue_controller._inc_counter(queue_name, window=5) changed = self.queue_controller._inc_counter(queue_name, window=5)
self.assertEqual(changed, reference_value + 1) self.assertEqual(changed, reference_value + 1)
timeutils.clear_time_override()
def test_race_condition_on_post(self): def test_race_condition_on_post(self):
queue_name = 'marker_test' queue_name = 'marker_test'

View File

@@ -13,11 +13,13 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import datetime
import json import json
import uuid import uuid
import ddt import ddt
import falcon import falcon
import mock
from testtools import matchers from testtools import matchers
from . import base # noqa from . import base # noqa
@@ -137,12 +139,12 @@ class ClaimsBaseTest(base.TestBase):
self.assertEqual(self.srmock.status, falcon.HTTP_200) self.assertEqual(self.srmock.status, falcon.HTTP_200)
self.assertEqual(len(listed['messages']), len(claimed)) self.assertEqual(len(listed['messages']), len(claimed))
# Check the claim's metadata now = timeutils.utcnow() + datetime.timedelta(seconds=10)
## NOTE(cpp-cabrera): advance time to force claim aging timeutils_utcnow = 'marconi.openstack.common.timeutils.utcnow'
timeutils.set_time_override(timeutils.utcnow()) with mock.patch(timeutils_utcnow) as mock_utcnow:
timeutils.advance_time_seconds(10) mock_utcnow.return_value = now
body = self.simulate_get(claim_href, self.project_id) body = self.simulate_get(claim_href, self.project_id)
timeutils.clear_time_override()
claim = json.loads(body[0]) claim = json.loads(body[0])
self.assertEqual(self.srmock.status, falcon.HTTP_200) self.assertEqual(self.srmock.status, falcon.HTTP_200)

View File

@@ -13,11 +13,13 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import datetime
import json import json
import uuid import uuid
import ddt import ddt
import falcon import falcon
import mock
import six import six
from testtools import matchers from testtools import matchers
@@ -83,8 +85,10 @@ class MessagesBaseTest(base.TestBase):
# Test GET on the message resource directly # Test GET on the message resource directly
# NOTE(cpp-cabrera): force the passing of time to age a message # NOTE(cpp-cabrera): force the passing of time to age a message
timeutils.set_time_override(timeutils.utcnow()) timeutils_utcnow = 'marconi.openstack.common.timeutils.utcnow'
timeutils.advance_time_seconds(10) now = timeutils.utcnow() + datetime.timedelta(seconds=10)
with mock.patch(timeutils_utcnow) as mock_utcnow:
mock_utcnow.return_value = now
for msg_id in msg_ids: for msg_id in msg_ids:
message_uri = self.messages_path + '/' + msg_id message_uri = self.messages_path + '/' + msg_id
@@ -107,7 +111,6 @@ class MessagesBaseTest(base.TestBase):
# NOTE(cpp-cabrera): testtools lacks GreaterThanEqual on py26 # NOTE(cpp-cabrera): testtools lacks GreaterThanEqual on py26
self.assertThat(message['age'], self.assertThat(message['age'],
matchers.GreaterThan(-1)) matchers.GreaterThan(-1))
timeutils.clear_time_override()
# Test bulk GET # Test bulk GET
query_string = 'ids=' + ','.join(msg_ids) query_string = 'ids=' + ','.join(msg_ids)
@@ -275,7 +278,7 @@ class MessagesBaseTest(base.TestBase):
def test_bulk_delete(self): def test_bulk_delete(self):
path = self.queue_path + '/messages' path = self.queue_path + '/messages'
self._post_messages(path, repeat=5) self._post_messages(path, repeat=5)
[target, params] = self.srmock.headers_dict['Location'].split('?') [target, params] = self.srmock.headers_dict['location'].split('?')
# Deleting the whole collection is denied # Deleting the whole collection is denied
self.simulate_delete(path, self.project_id) self.simulate_delete(path, self.project_id)
@@ -378,7 +381,7 @@ class MessagesBaseTest(base.TestBase):
self.simulate_post(path + '/claims', self.project_id, self.simulate_post(path + '/claims', self.project_id,
body='{"ttl": 100, "grace": 100}') body='{"ttl": 100, "grace": 100}')
self.assertEqual(self.srmock.status, falcon.HTTP_201) self.assertEqual(self.srmock.status, falcon.HTTP_201)
location = self.srmock.headers_dict['Location'] location = self.srmock.headers_dict['location']
# release claim # release claim
self.simulate_delete(location, self.project_id) self.simulate_delete(location, self.project_id)
@@ -446,7 +449,7 @@ class MessagesBaseTest(base.TestBase):
return self._get_msg_ids(headers)[0] return self._get_msg_ids(headers)[0]
def _get_msg_ids(self, headers): def _get_msg_ids(self, headers):
return headers['Location'].rsplit('=', 1)[-1].split(',') return headers['location'].rsplit('=', 1)[-1].split(',')
class MessagesSQLiteTests(MessagesBaseTest): class MessagesSQLiteTests(MessagesBaseTest):