diff --git a/tests/__init__.py b/tests/__init__.py index 91a12bb..69fc850 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,3 +1,9 @@ # SPDX-FileCopyrightText: 2023-present LingKa # # SPDX-License-Identifier: Apache 2.0 + +import sys + +sys.path.append("./api/curp") + +sys.path.append("./api/xline") diff --git a/tests/protocol_test.py b/tests/protocol_test.py new file mode 100755 index 0000000..bfd96cd --- /dev/null +++ b/tests/protocol_test.py @@ -0,0 +1,37 @@ +"""Tests for the protocol client.""" + +import unittest +import uuid + +from api.xline import rpc_pb2, xline_command_pb2 +from client.protocol import build_from_addrs + + +class TestProtocolClient(unittest.TestCase): + """test protocol client""" + + def setUp(self) -> None: + curp_members = ["172.20.0.3:2379", "172.20.0.4:2379", "172.20.0.5:2379"] + + cmd = xline_command_pb2.Command( + request=xline_command_pb2.RequestWithToken( + put_request=rpc_pb2.PutRequest( + key=bytes("hello", encoding="utf8"), + value=bytes("xline", encoding="utf8"), + ) + ), + propose_id=f"client-{uuid.uuid4()}", + ) + + self.cmd = cmd + self.client = build_from_addrs(curp_members) + + def test_fast_path(self): + """test fast path""" + res = self.client.propose(self.cmd, True) + self.assertIsNotNone(res) + + def test_slow_path(self): + """test slow path""" + res = self.client.propose(self.cmd, False) + self.assertIsNotNone(res)