-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
service echo | ||
{ | ||
oneway void Test(1: string req) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |