Beispiel #1
0
    def DispatchNotifications(self, timeout):
        current_time = self._mock_timer.time()
        if not self._responses:
            self._mock_timer.SetTime(current_time + timeout + 1)
            raise websocket.WebSocketTimeoutException()

        response, time = self._responses[0]
        if time - current_time > timeout:
            self._mock_timer.SetTime(current_time + timeout + 1)
            raise websocket.WebSocketTimeoutException()

        self._responses.pop(0)
        self._mock_timer.SetTime(time + 1)
        self._handler(response)
Beispiel #2
0
    def DispatchNotifications(self, timeout):
        current_time = self._mock_timer.time()
        if not self._notifications:
            self._mock_timer.SetTime(current_time + timeout + 1)
            raise websocket.WebSocketTimeoutException()

        response, time, kind = self._notifications[0]
        if time - current_time > timeout:
            self._mock_timer.SetTime(current_time + timeout + 1)
            raise websocket.WebSocketTimeoutException()

        self._notifications.pop(0)
        self._mock_timer.SetTime(time + 1)
        if kind == self._NOTIFICATION_EVENT:
            self._handler(response)
        elif kind == self._NOTIFICATION_CALLBACK:
            callback = self._pending_callbacks.get(response['method']).pop(0)
            callback(response)
        else:
            raise Exception('Unexpected response type')
Beispiel #3
0
    def recv(self):
        if not self._responses:
            raise Exception('No more recorded responses.')

        response, time = self._responses.pop(0)
        current_time = self._mock_timer.time()
        if self._timeout is not None and time - current_time > self._timeout:
            self._mock_timer.SetTime(current_time + self._timeout + 1)
            raise websocket.WebSocketTimeoutException()

        self._mock_timer.SetTime(time)
        return response
  def recv(self): # pylint: disable=invalid-name
    if not self._responses:
      raise Exception('No more recorded responses.')

    response, time = self._responses.pop(0)
    current_time = self._fake_timer.time()
    if self._timeout is not None and time - current_time > self._timeout:
      self._fake_timer.SetTime(current_time + self._timeout + 1)
      raise websocket.WebSocketTimeoutException()

    self._fake_timer.SetTime(time)
    if isinstance(response, Exception):
      raise response
    return response