def _acall(name): client = AioClient("perftestapp") client.mesh_service_address = ("127.0.0.1", 12201) fs = [ client.invoke_async( interface, "hello", SampleServicePbRequest(name=str(name)).SerializeToString(), timeout_ms=1000, spanctx=SpanContext()) for i in range(100) ] wait(fs)
def _call(name): client = AioClient("perftestapp") client.mesh_service_address = ("127.0.0.1", 12201) for i in range(100): try: ret = client.invoke_sync( interface, "hello", SampleServicePbRequest(name=str(name)).SerializeToString(), timeout_ms=1000, spanctx=SpanContext()) except Exception as e: pass print("{} finished".format(name))
def run_client(text): print("client start", text) spanctx = SpanContext() client = Client("test_app") client.subscribe(interface) content = client.invoke_sync(interface, "hello", SampleServicePbRequest(name=text).SerializeToString(), timeout_ms=5000, spanctx=spanctx) print("client", content) result = SampleServicePbResult() result.ParseFromString(content) print("client", result)
def test_aio_client(self): client = AioClient("anthunderTestApp") _result = list() _ts = list() def _call(name): content = client.invoke_sync( self.interface, "hello", SampleServicePbRequest(name=str(name)).SerializeToString(), timeout_ms=5000, spanctx=SpanContext()) result = SampleServicePbResult() result.ParseFromString(content) print(result.result == str(name)) _result.append(result.result == str(name)) for i in range(10): t = threading.Thread(target=_call, args=(i, )) t.start() _ts.append(t) for t in _ts: t.join() self.assertEqual(len(_result), 10) self.assertTrue(all(_result))
def test_aio_client_async(self): print("async client") client = AioClient("anthunderTestApp") _result = list() def _cb(content, expect): result = SampleServicePbResult() result.ParseFromString(content) print(expect == result.result) _result.append(expect == result.result) def _acall(name): return client.invoke_async( self.interface, "hello", SampleServicePbRequest(name="async" + str(name)).SerializeToString(), timeout_ms=500, callback=functools.partial(_cb, expect="async" + str(name)), spanctx=SpanContext()) fs = [_acall(i) for i in range(10)] concurrent.futures.wait(fs, timeout=1.5) time.sleep(0.1) self.assertEqual(len(_result), 10) self.assertTrue(all(_result))
def test_aio_client(self): client = AioClient( "anthunderTestApp", service_register=FixedAddressRegistry("127.0.0.1:12200")) _result = list() _ts = list() def _call(name): content = client.invoke_sync( self.interface, "hello", SampleServicePbRequest(name=str(name)).SerializeToString(), timeout_ms=5000, spanctx=SpanContext()) result = SampleServicePbResult() result.ParseFromString(content) print(result.result == str(name)) _result.append(result.result == str(name)) for i in range(10): t = threading.Thread(target=_call, args=(i, )) t.start() _ts.append(t) for t in _ts: t.join() for task in all_tasks(client._loop): print(task) # _recv_response * 1 # _heartbeat_timer * 1 self.assertLessEqual(len(all_tasks(client._loop)), 2) self.assertEqual(len(_result), 10) self.assertTrue(all(_result))