Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the message_type of client #226

Merged
merged 4 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/oneway.thrift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
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!"


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
4 changes: 3 additions & 1 deletion thriftpy2/contrib/aio/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion thriftpy2/thrift.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down