Skip to content

Commit efa47ae

Browse files
committed
avro test: wait for mock server start rather than arbitrary sleep
This makes the tests more robust and faster
1 parent b181d3c commit efa47ae

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

tests/avro/mock_registry.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import json
2525
import re
2626

27-
from threading import Thread
27+
from threading import Thread, Event
2828

2929
from tests.avro.mock_schema_registry_client import MockSchemaRegistryClient
3030
from confluent_kafka import avro
@@ -176,11 +176,18 @@ def __init__(self, port):
176176
self.server = None
177177
self.port = port
178178
self.daemon = True
179+
self.started = Event()
179180

180181
def run(self):
181182
self.server = MockServer(('127.0.0.1', self.port), ReqHandler)
183+
self.started.set()
182184
self.server.serve_forever()
183185

186+
def start(self):
187+
"""Start, and wait for server to be fully started, before returning."""
188+
super(ServerThread, self).start()
189+
self.started.wait()
190+
184191
def shutdown(self):
185192
if self.server:
186193
self.server.shutdown()

tests/avro/test_cached_client.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
# derived from https://github.com/verisign/python-confluent-schemaregistry.git
2121
#
2222

23-
import time
24-
2523
import unittest
2624

2725
from tests.avro import mock_registry
@@ -34,7 +32,6 @@ class TestCacheSchemaRegistryClient(unittest.TestCase):
3432
def setUp(self):
3533
self.server = mock_registry.ServerThread(0)
3634
self.server.start()
37-
time.sleep(1)
3835
self.client = CachedSchemaRegistryClient('http://127.0.0.1:' + str(self.server.server.server_port))
3936

4037
def tearDown(self):

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy