Merge "Deal correctly with negative elapsed time"

This commit is contained in:
Jenkins 2017-05-17 19:17:04 +00:00 committed by Gerrit Code Review
commit 97d236062c
2 changed files with 11 additions and 1 deletions

View File

@ -2102,7 +2102,7 @@ class Stack(collections.Mapping):
start_time = timeutils.round_to_seconds(self.updated_time or
self.created_time)
nowish = timeutils.round_to_seconds(datetime.datetime.utcnow())
return (nowish - start_time).seconds
return int((nowish - start_time).total_seconds())
def time_remaining(self):
"""Time left before stack times out."""

View File

@ -119,6 +119,16 @@ class StackTest(common.HeatTestCase):
10, 10, 0)
self.assertEqual(600, self.stack.time_elapsed())
@mock.patch.object(stack, 'datetime')
def test_time_elapsed_negative(self, mock_dt):
self.stack = stack.Stack(self.ctx, 'test_stack', self.tmpl)
# dummy create time 10:00:00
self.stack.created_time = datetime.datetime(2015, 7, 27, 10, 0, 0)
# mock utcnow set to 09:59:50 (-10s offset)
mock_dt.datetime.utcnow.return_value = datetime.datetime(2015, 7, 27,
9, 59, 50)
self.assertEqual(-10, self.stack.time_elapsed())
@mock.patch.object(stack, 'datetime')
def test_time_elapsed_ms(self, mock_dt):
self.stack = stack.Stack(self.ctx, 'test_stack', self.tmpl)