Skip to content

Commit 0bb2fe9

Browse files
committed
Explicitly stop servers in unit tests.
Relying on garbage collection to stop servers breaks with gevent.
1 parent 1ead89f commit 0bb2fe9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/python/grpcio_tests/tests/protoc_plugin/_python_plugin_test.py

+22
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ def testUpDown(self):
237237
self.assertIsNotNone(service.servicer_methods)
238238
self.assertIsNotNone(service.server)
239239
self.assertIsNotNone(service.stub)
240+
service.server.stop(None)
240241

241242
def testIncompleteServicer(self):
242243
service = _CreateIncompleteService()
@@ -245,6 +246,7 @@ def testIncompleteServicer(self):
245246
service.stub.UnaryCall(request)
246247
self.assertIs(exception_context.exception.code(),
247248
grpc.StatusCode.UNIMPLEMENTED)
249+
service.server.stop(None)
248250

249251
def testUnaryCall(self):
250252
service = _CreateService()
@@ -253,6 +255,7 @@ def testUnaryCall(self):
253255
expected_response = service.servicer_methods.UnaryCall(
254256
request, 'not a real context!')
255257
self.assertEqual(expected_response, response)
258+
service.server.stop(None)
256259

257260
def testUnaryCallFuture(self):
258261
service = _CreateService()
@@ -264,6 +267,7 @@ def testUnaryCallFuture(self):
264267
expected_response = service.servicer_methods.UnaryCall(
265268
request, 'not a real RpcContext!')
266269
self.assertEqual(expected_response, response)
270+
service.server.stop(None)
267271

268272
def testUnaryCallFutureExpired(self):
269273
service = _CreateService()
@@ -276,6 +280,7 @@ def testUnaryCallFutureExpired(self):
276280
self.assertIs(exception_context.exception.code(),
277281
grpc.StatusCode.DEADLINE_EXCEEDED)
278282
self.assertIs(response_future.code(), grpc.StatusCode.DEADLINE_EXCEEDED)
283+
service.server.stop(None)
279284

280285
def testUnaryCallFutureCancelled(self):
281286
service = _CreateService()
@@ -285,6 +290,7 @@ def testUnaryCallFutureCancelled(self):
285290
response_future.cancel()
286291
self.assertTrue(response_future.cancelled())
287292
self.assertIs(response_future.code(), grpc.StatusCode.CANCELLED)
293+
service.server.stop(None)
288294

289295
def testUnaryCallFutureFailed(self):
290296
service = _CreateService()
@@ -293,6 +299,7 @@ def testUnaryCallFutureFailed(self):
293299
response_future = service.stub.UnaryCall.future(request)
294300
self.assertIsNotNone(response_future.exception())
295301
self.assertIs(response_future.code(), grpc.StatusCode.UNKNOWN)
302+
service.server.stop(None)
296303

297304
def testStreamingOutputCall(self):
298305
service = _CreateService()
@@ -303,6 +310,7 @@ def testStreamingOutputCall(self):
303310
for expected_response, response in moves.zip_longest(
304311
expected_responses, responses):
305312
self.assertEqual(expected_response, response)
313+
service.server.stop(None)
306314

307315
def testStreamingOutputCallExpired(self):
308316
service = _CreateService()
@@ -314,6 +322,7 @@ def testStreamingOutputCallExpired(self):
314322
list(responses)
315323
self.assertIs(exception_context.exception.code(),
316324
grpc.StatusCode.DEADLINE_EXCEEDED)
325+
service.server.stop(None)
317326

318327
def testStreamingOutputCallCancelled(self):
319328
service = _CreateService()
@@ -324,6 +333,7 @@ def testStreamingOutputCallCancelled(self):
324333
with self.assertRaises(grpc.RpcError) as exception_context:
325334
next(responses)
326335
self.assertIs(responses.code(), grpc.StatusCode.CANCELLED)
336+
service.server.stop(None)
327337

328338
def testStreamingOutputCallFailed(self):
329339
service = _CreateService()
@@ -335,6 +345,7 @@ def testStreamingOutputCallFailed(self):
335345
next(responses)
336346
self.assertIs(exception_context.exception.code(),
337347
grpc.StatusCode.UNKNOWN)
348+
service.server.stop(None)
338349

339350
def testStreamingInputCall(self):
340351
service = _CreateService()
@@ -343,6 +354,7 @@ def testStreamingInputCall(self):
343354
expected_response = service.servicer_methods.StreamingInputCall(
344355
_streaming_input_request_iterator(), 'not a real RpcContext!')
345356
self.assertEqual(expected_response, response)
357+
service.server.stop(None)
346358

347359
def testStreamingInputCallFuture(self):
348360
service = _CreateService()
@@ -353,6 +365,7 @@ def testStreamingInputCallFuture(self):
353365
expected_response = service.servicer_methods.StreamingInputCall(
354366
_streaming_input_request_iterator(), 'not a real RpcContext!')
355367
self.assertEqual(expected_response, response)
368+
service.server.stop(None)
356369

357370
def testStreamingInputCallFutureExpired(self):
358371
service = _CreateService()
@@ -367,6 +380,7 @@ def testStreamingInputCallFutureExpired(self):
367380
grpc.StatusCode.DEADLINE_EXCEEDED)
368381
self.assertIs(exception_context.exception.code(),
369382
grpc.StatusCode.DEADLINE_EXCEEDED)
383+
service.server.stop(None)
370384

371385
def testStreamingInputCallFutureCancelled(self):
372386
service = _CreateService()
@@ -377,6 +391,7 @@ def testStreamingInputCallFutureCancelled(self):
377391
self.assertTrue(response_future.cancelled())
378392
with self.assertRaises(grpc.FutureCancelledError):
379393
response_future.result()
394+
service.server.stop(None)
380395

381396
def testStreamingInputCallFutureFailed(self):
382397
service = _CreateService()
@@ -385,6 +400,7 @@ def testStreamingInputCallFutureFailed(self):
385400
_streaming_input_request_iterator())
386401
self.assertIsNotNone(response_future.exception())
387402
self.assertIs(response_future.code(), grpc.StatusCode.UNKNOWN)
403+
service.server.stop(None)
388404

389405
def testFullDuplexCall(self):
390406
service = _CreateService()
@@ -394,6 +410,7 @@ def testFullDuplexCall(self):
394410
for expected_response, response in moves.zip_longest(
395411
expected_responses, responses):
396412
self.assertEqual(expected_response, response)
413+
service.server.stop(None)
397414

398415
def testFullDuplexCallExpired(self):
399416
request_iterator = _full_duplex_request_iterator()
@@ -405,6 +422,7 @@ def testFullDuplexCallExpired(self):
405422
list(responses)
406423
self.assertIs(exception_context.exception.code(),
407424
grpc.StatusCode.DEADLINE_EXCEEDED)
425+
service.server.stop(None)
408426

409427
def testFullDuplexCallCancelled(self):
410428
service = _CreateService()
@@ -416,6 +434,7 @@ def testFullDuplexCallCancelled(self):
416434
next(responses)
417435
self.assertIs(exception_context.exception.code(),
418436
grpc.StatusCode.CANCELLED)
437+
service.server.stop(None)
419438

420439
def testFullDuplexCallFailed(self):
421440
request_iterator = _full_duplex_request_iterator()
@@ -426,6 +445,7 @@ def testFullDuplexCallFailed(self):
426445
next(responses)
427446
self.assertIs(exception_context.exception.code(),
428447
grpc.StatusCode.UNKNOWN)
448+
service.server.stop(None)
429449

430450
def testHalfDuplexCall(self):
431451
service = _CreateService()
@@ -445,6 +465,7 @@ def half_duplex_request_iterator():
445465
for expected_response, response in moves.zip_longest(
446466
expected_responses, responses):
447467
self.assertEqual(expected_response, response)
468+
service.server.stop(None)
448469

449470
def testHalfDuplexCallWedged(self):
450471
condition = threading.Condition()
@@ -478,6 +499,7 @@ def half_duplex_request_iterator():
478499
next(responses)
479500
self.assertIs(exception_context.exception.code(),
480501
grpc.StatusCode.DEADLINE_EXCEEDED)
502+
service.server.stop(None)
481503

482504

483505
if __name__ == '__main__':

src/python/grpcio_tests/tests/protoc_plugin/_split_definitions_test.py

+1
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ def test_call(self):
271271
stub = services_module.TestServiceStub(channel)
272272
response = stub.Call(self._messages_pb2.Request())
273273
self.assertEqual(self._messages_pb2.Response(), response)
274+
server.stop(None)
274275

275276

276277
def _create_test_case_class(split_proto, protoc_style):

0 commit comments

Comments
 (0)