Skip to content

Commit 4eab4d7

Browse files
committed
Slightly improve HttpsTestServerLayer
- Send Content-Length header based on the encoded response body - Reduce sleep time after starting the server thread
1 parent fd15315 commit 4eab4d7

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/crate/client/tests.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def setUpMocked(test):
110110
local = '127.0.0.1'
111111
crate_host = "{host}:{port}".format(host=local, port=crate_port)
112112
crate_uri = "http://%s" % crate_host
113+
crate_layer = None
113114

114115

115116
def ensure_cratedb_layer():
@@ -213,7 +214,7 @@ class Location(Base):
213214
test.globs['CrateDialect'] = CrateDialect
214215

215216

216-
class HttpsTestServerLayer(object):
217+
class HttpsTestServerLayer:
217218
PORT = 65534
218219
HOST = "localhost"
219220
CERT_FILE = os.path.abspath(os.path.join(os.path.dirname(__file__),
@@ -241,11 +242,11 @@ class HttpsHandler(BaseHTTPRequestHandler):
241242

242243
def do_GET(self):
243244
self.send_response(200)
244-
self.send_header("Content-Length", len(self.payload))
245+
payload = self.payload.encode('UTF-8')
246+
self.send_header("Content-Length", len(payload))
245247
self.send_header("Content-Type", "application/json; charset=UTF-8")
246248
self.end_headers()
247-
self.wfile.write(self.payload.encode('UTF-8'))
248-
return
249+
self.wfile.write(payload)
249250

250251
def __init__(self):
251252
self.server = self.HttpsServer(
@@ -257,7 +258,7 @@ def setUp(self):
257258
thread = threading.Thread(target=self.serve_forever)
258259
thread.daemon = True # quit interpreter when only thread exists
259260
thread.start()
260-
time.sleep(1)
261+
time.sleep(0.5)
261262

262263
def serve_forever(self):
263264
print("listening on", self.HOST, self.PORT)

0 commit comments

Comments
 (0)