File tree 3 files changed +31
-3
lines changed
3 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -64,8 +64,9 @@ def read(path):
64
64
]
65
65
},
66
66
extras_require = dict (
67
- test = ['zope.testing' ,
68
- 'zc.customdoctests>=1.0.1' ],
67
+ test = ['zope.testing>=4,<5' ,
68
+ 'zc.customdoctests>=1.0.1,<2' ,
69
+ 'stopit>=1.1.2,<2' ],
69
70
sqlalchemy = ['sqlalchemy>=1.0,<1.4' , 'geojson>=2.5.0' ]
70
71
),
71
72
python_requires = '>=3.4' ,
Original file line number Diff line number Diff line change 23
23
24
24
import json
25
25
import os
26
+ import socket
26
27
import unittest
27
28
import doctest
28
29
from pprint import pprint
33
34
import threading
34
35
import logging
35
36
37
+ import stopit
38
+
36
39
from crate .testing .layer import CrateLayer
37
40
from crate .testing .tests import crate_path , docs_path
38
41
from crate .client import connect
@@ -258,7 +261,7 @@ def setUp(self):
258
261
thread = threading .Thread (target = self .serve_forever )
259
262
thread .daemon = True # quit interpreter when only thread exists
260
263
thread .start ()
261
- time . sleep ( 0.5 )
264
+ self . waitForServer ( )
262
265
263
266
def serve_forever (self ):
264
267
print ("listening on" , self .HOST , self .PORT )
@@ -268,6 +271,29 @@ def serve_forever(self):
268
271
def tearDown (self ):
269
272
self .server .shutdown ()
270
273
274
+ def isUp (self ):
275
+ """
276
+ Test if a host is up.
277
+ """
278
+ s = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
279
+ ex = s .connect_ex ((self .HOST , self .PORT ))
280
+ s .close ()
281
+ return ex == 0
282
+
283
+ def waitForServer (self , timeout = 5 ):
284
+ """
285
+ Wait for the host to be available.
286
+ """
287
+ with stopit .ThreadingTimeout (timeout ) as to_ctx_mgr :
288
+ while True :
289
+ if self .isUp ():
290
+ break
291
+ time .sleep (0.001 )
292
+
293
+ if not to_ctx_mgr :
294
+ raise TimeoutError ("Could not properly start embedded webserver "
295
+ "within {} seconds" .format (timeout ))
296
+
271
297
272
298
def setUpWithHttps (test ):
273
299
test .globs ['HttpClient' ] = http .Client
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ zc.customdoctests = 1.0.1
24
24
zc.recipe.egg = 2.0.7
25
25
zc.recipe.testrunner = 2.2
26
26
zope.testing = 4.9
27
+ stopit = 1.1.2
27
28
28
29
# Required by:
29
30
# clint==0.5.1
You can’t perform that action at this time.
0 commit comments