Merge "Deal correctly with negative elapsed time"
This commit is contained in:
commit
97d236062c
@ -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."""
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user