Example #1
0
    def __call__(self, rpc_result, result=None, error=None, timeout=2):
        if error is not None:
            if callable(error):
                assert error(rpc_result.status_code, rpc_result.body
                             ), f"{rpc_result.status_code}: {rpc_result.body}"
            else:
                assert rpc_result.body.text(
                ) == error, "Expected {}, got {}".format(
                    error, rpc_result.body)
            return

        if result is not None:
            if callable(result):
                assert result(rpc_result.body), rpc_result.body
            else:
                assert rpc_result.body.json(
                ) == result, "Expected {}, got {}".format(
                    result, rpc_result.body)

            assert rpc_result.seqno >= 0 and rpc_result.view >= 0

        if self.client:
            wait_for_commit(self.client, rpc_result.seqno, rpc_result.view)
Example #2
0
    def __call__(self, rpc_result, result=None, error=None, timeout=2):
        if error is not None:
            if callable(error):
                assert error(rpc_result.status_code, rpc_result.body
                             ), f"{rpc_result.status_code}: {rpc_result.body}"
            else:
                assert rpc_result.body == error, "Expected {}, got {}".format(
                    error, rpc_result.body)
            return

        if result is not None:
            if callable(result):
                assert result(rpc_result.body), rpc_result.body
            else:
                assert rpc_result.body == result, "Expected {}, got {}".format(
                    result, rpc_result.body)

            assert rpc_result.seqno and rpc_result.view, rpc_result

        if self.client:
            wait_for_commit(self.client, rpc_result.seqno, rpc_result.view)

        if self.notification_queue:
            end_time = time.time() + timeout
            while time.time() < end_time:
                while self.notification_queue.not_empty:
                    notification = self.notification_queue.get()
                    n = json.loads(notification)["commit"]
                    assert (
                        n > self.notified_commit
                    ), f"Received notification of commit {n} after commit {self.notified_commit}"
                    self.notified_commit = n
                    if n >= rpc_result.seqno:
                        return
                time.sleep(0.5)
            raise TimeoutError("Timed out waiting for notification")