1# Copyright 2018 the V8 project authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import time 6 7from . import base 8 9 10class TimeoutProc(base.TestProcObserver): 11 def __init__(self, duration_sec): 12 super(TimeoutProc, self).__init__() 13 self._duration_sec = duration_sec 14 self._start = time.time() 15 16 def _on_next_test(self, test): 17 self.__on_event() 18 19 def _on_result_for(self, test, result): 20 self.__on_event() 21 22 def _on_heartbeat(self): 23 self.__on_event() 24 25 def __on_event(self): 26 if not self.is_stopped: 27 if time.time() - self._start > self._duration_sec: 28 print('>>> Total timeout reached.') 29 self.stop() 30