@@ -34,6 +34,24 @@ def getsockname(self):
3434 def getpeername (self ):
3535 return '127.0.0.1' , 8091
3636
37+ class FakePoller (object ):
38+ def __init__ (self , timeout = 0.1 ):
39+ self ._fds = []
40+
41+ def release (self ):
42+ self ._fds = []
43+
44+ def register (self , fd ):
45+ if fd not in self ._fds :
46+ self ._fds .append (fd )
47+
48+ def unregister (self , fd ):
49+ if fd in self ._fds :
50+ self ._fds .remove (fd )
51+
52+ def poll (self ):
53+ return self ._fds
54+
3755class App (object ):
3856 @cherrypy .expose
3957 def ws (self ):
@@ -48,6 +66,8 @@ def setup_engine():
4866 cherrypy .engine .websocket = WebSocketPlugin (cherrypy .engine )
4967 cherrypy .engine .websocket .subscribe ()
5068
69+ cherrypy .engine .websocket .manager .poller = FakePoller ()
70+
5171 cherrypy .tools .websocket = WebSocketTool ()
5272
5373 config = {'/ws' : {'tools.websocket.on' : True ,
@@ -75,8 +95,10 @@ def test_plugin(self):
7595 self .assertEquals (len (manager ), 1 )
7696 self .assertIn (h , manager )
7797
78- h .close () # initiate closing handshake
79- h .client_terminated = True # we aren't actually connected so pretend the client shutdown
98+ h .close ()
99+
100+ # the poller runs a thread, give it time to get there
101+ time .sleep (0.5 )
80102
81103 # TODO: Implement a fake poller so that works...
82104 self .assertEquals (len (manager ), 0 )
0 commit comments