diff --git a/tests/oneway.thrift b/tests/oneway.thrift new file mode 100644 index 0000000..835f53c --- /dev/null +++ b/tests/oneway.thrift @@ -0,0 +1,3 @@ +service echo { + oneway void Test(1: string req) +} diff --git a/tests/test_oneway.py b/tests/test_oneway.py new file mode 100644 index 0000000..812cfda --- /dev/null +++ b/tests/test_oneway.py @@ -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!" + + +class TestOneway(object): + + oneway_thrift = thriftpy2.load("oneway.thrift") + + def setup_class(self): + ctx = multiprocessing.get_context("fork") + server = make_server(self.oneway_thrift.echo, Dispatcher(), '127.0.0.1', 6000) + self.p = ctx.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(self.oneway_thrift.echo, '127.0.0.1', 6000) + + assert client.Test(req) == None diff --git a/thriftpy2/contrib/aio/client.py b/thriftpy2/contrib/aio/client.py index 525e8d3..2e2136d 100644 --- a/thriftpy2/contrib/aio/client.py +++ b/thriftpy2/contrib/aio/client.py @@ -40,7 +40,9 @@ async def _req(self, _api, *args, **kwargs): return await self._recv(_api) async def _send(self, _api, **kwargs): - self._oprot.write_message_begin(_api, TMessageType.CALL, self._seqid) + oneway = getattr(getattr(self._service, _api + "_result"), "oneway") + msg_type = TMessageType.ONEWAY if oneway else TMessageType.CALL + self._oprot.write_message_begin(_api, msg_type, self._seqid) args = getattr(self._service, _api + "_args")() for k, v in kwargs.items(): setattr(args, k, v) diff --git a/thriftpy2/thrift.py b/thriftpy2/thrift.py index 0c4322b..30cc517 100644 --- a/thriftpy2/thrift.py +++ b/thriftpy2/thrift.py @@ -219,7 +219,9 @@ def _req(self, _api, *args, **kwargs): return self._recv(_api) def _send(self, _api, **kwargs): - self._oprot.write_message_begin(_api, TMessageType.CALL, self._seqid) + oneway = getattr(getattr(self._service, _api + "_result"), "oneway") + msg_type = TMessageType.ONEWAY if oneway else TMessageType.CALL + self._oprot.write_message_begin(_api, msg_type, self._seqid) args = getattr(self._service, _api + "_args")() for k, v in kwargs.items(): setattr(args, k, v)