Skip to content

Commit

Permalink
chore: add unittest for oneway req
Browse files Browse the repository at this point in the history
  • Loading branch information
1C4nfaN authored and aisk committed Oct 23, 2023
1 parent 64e4b2c commit 94cdb82
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/oneway.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
service echo
{
oneway void Test(1: string req)
}
32 changes: 32 additions & 0 deletions tests/test_oneway.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import multiprocessing
import thriftpy2
import time
from thriftpy2.rpc import make_client, make_server


class Dispatcher(object):
def Test(self, req):
print("Get req msg: %s" % req)

assert req == "Hello!"


oneway_thrift = thriftpy2.load("oneway.thrift", module_name="oneway_thrift")
multiprocessing.set_start_method("fork")


class TestOneway(object):
def setup_class(self):
server = make_server(oneway_thrift.echo, Dispatcher(), '127.0.0.1', 6000)
self.p = multiprocessing.Process(target=server.serve)
self.p.start()
time.sleep(1) # Wait a second for server to start.

def teardown_class(self):
self.p.terminate()

def test_echo(self):
req = "Hello!"
client = make_client(oneway_thrift.echo, '127.0.0.1', 6000)

assert client.Test(req) == None

0 comments on commit 94cdb82

Please sign in to comment.