Skip to content

Commit 48f1adb

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 cef2803 commit 48f1adb

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/crate/client/tests.py

Lines changed: 6 additions & 5 deletions
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__),
@@ -238,11 +239,11 @@ class HttpsHandler(BaseHTTPRequestHandler):
238239

239240
def do_GET(self):
240241
self.send_response(200)
241-
self.send_header("Content-Length", len(self.payload))
242+
payload = self.payload.encode('UTF-8')
243+
self.send_header("Content-Length", len(payload))
242244
self.send_header("Content-Type", "application/json; charset=UTF-8")
243245
self.end_headers()
244-
self.wfile.write(self.payload.encode('UTF-8'))
245-
return
246+
self.wfile.write(payload)
246247

247248
def __init__(self):
248249
self.server = self.HttpsServer(
@@ -254,7 +255,7 @@ def setUp(self):
254255
thread = threading.Thread(target=self.serve_forever)
255256
thread.daemon = True # quit interpreter when only thread exists
256257
thread.start()
257-
time.sleep(1)
258+
time.sleep(0.5)
258259

259260
def serve_forever(self):
260261
print("listening on", self.HOST, self.PORT)

0 commit comments

Comments
 (0)