File tree Expand file tree Collapse file tree 3 files changed +31
-3
lines changed Expand file tree Collapse file tree 3 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -64,8 +64,9 @@ def read(path):
6464 ]
6565 },
6666 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' ],
6970 sqlalchemy = ['sqlalchemy>=1.0,<1.4' , 'geojson>=2.5.0' ]
7071 ),
7172 python_requires = '>=3.4' ,
Original file line number Diff line number Diff line change 2323
2424import json
2525import os
26+ import socket
2627import unittest
2728import doctest
2829from pprint import pprint
3334import threading
3435import logging
3536
37+ import stopit
38+
3639from crate .testing .layer import CrateLayer
3740from crate .testing .tests import crate_path , docs_path
3841from crate .client import connect
@@ -258,7 +261,7 @@ def setUp(self):
258261 thread = threading .Thread (target = self .serve_forever )
259262 thread .daemon = True # quit interpreter when only thread exists
260263 thread .start ()
261- time . sleep ( 0.5 )
264+ self . waitForServer ( )
262265
263266 def serve_forever (self ):
264267 print ("listening on" , self .HOST , self .PORT )
@@ -268,6 +271,29 @@ def serve_forever(self):
268271 def tearDown (self ):
269272 self .server .shutdown ()
270273
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+
271297
272298def setUpWithHttps (test ):
273299 test .globs ['HttpClient' ] = http .Client
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ zc.customdoctests = 1.0.1
2424zc.recipe.egg = 2.0.7
2525zc.recipe.testrunner = 2.2
2626zope.testing = 4.9
27+ stopit = 1.1.2
2728
2829# Required by:
2930# clint==0.5.1
You can’t perform that action at this time.
0 commit comments