Skip to content

Commit

Permalink
test: add protocol client
Browse files Browse the repository at this point in the history
Signed-off-by: LingKa <[email protected]>
  • Loading branch information
LingKa28 committed Sep 30, 2023
1 parent 0b55b35 commit cacbe79
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# SPDX-FileCopyrightText: 2023-present LingKa <[email protected]>
#
# SPDX-License-Identifier: Apache 2.0

import sys

sys.path.append("./api/curp")

sys.path.append("./api/xline")
37 changes: 37 additions & 0 deletions tests/protocol_test.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit cacbe79

Please sign in to comment.