Repository: bokeh/bokeh

Issue:
Tests sometimes fail on AppVeyor
They fail on and off, usually a few restarts help:
```
-- Docs: https://docs.pytest.org/en/latest/warnings.html
----------- generated xml file: C:\projects\bokeh\test_results.xml ------------
= 1 failed, 3444 passed, 1 skipped, 981 deselected, 78 warnings in 241.84 seconds =
Task was destroyed but it is pending!
task: <Task pending coro=<RequestHandler._execute() running at C:\Miniconda36-x64\lib\site-packages\tornado\web.py:1699> wait_for=<Future pending cb=[coroutine.<locals>.wrapper.<locals>.<lambda>() at C:\Miniconda36-x64\lib\site-packages\tornado\gen.py:226, <1 more>, <TaskWakeupMethWrapper object at 0x000000A280615888>()]> cb=[_HandlerDelegate.execute.<locals>.<lambda>() at C:\Miniconda36-x64\lib\site-packages\tornado\web.py:2329]>
Exception ignored in: <generator object send at 0x000000A28051F5C8>
Traceback (most recent call last):
  File "C:\projects\bokeh\bokeh\protocol\message.py", line 281, in send
    raise gen.Return(sent)
  File "C:\Miniconda36-x64\lib\site-packages\tornado\locks.py", line 282, in __exit__
    self._obj.release()
  File "C:\Miniconda36-x64\lib\site-packages\tornado\locks.py", line 482, in release
    super(BoundedSemaphore, self).release()
  File "C:\Miniconda36-x64\lib\site-packages\tornado\locks.py", line 411, in release
    waiter.set_result(_ReleasingContextManager(self))
  File "C:\Miniconda36-x64\lib\asyncio\base_events.py", line 575, in call_soon
    self._check_closed()
  File "C:\Miniconda36-x64\lib\asyncio\base_events.py", line 358, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Future exception was never retrieved
future: <Future finished exception=WebSocketClosedError()>
Traceback (most recent call last):
  File "C:\Miniconda36-x64\lib\site-packages\tornado\websocket.py", line 1100, in wrapper
    await fut
tornado.iostream.StreamClosedError: Stream is closed
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Miniconda36-x64\lib\site-packages\tornado\gen.py", line 736, in run
    yielded = self.gen.throw(*exc_info)  # type: ignore
  File "C:\projects\bokeh\bokeh\server\views\ws.py", line 269, in write_message
    yield super(WSHandler, self).write_message(message, binary)
  File "C:\Miniconda36-x64\lib\site-packages\tornado\gen.py", line 729, in run
    value = future.result()
  File "C:\Miniconda36-x64\lib\site-packages\tornado\websocket.py", line 1102, in wrapper
    raise WebSocketClosedError()
tornado.websocket.WebSocketClosedError
Exception ignored in: <generator object _needs_document_lock_wrapper at 0x000000A280606B48>
Traceback (most recent call last):
  File "C:\projects\bokeh\bokeh\server\session.py", line 78, in _needs_document_lock_wrapper
    yield p
  File "C:\Miniconda36-x64\lib\site-packages\tornado\locks.py", line 282, in __exit__
    self._obj.release()
  File "C:\Miniconda36-x64\lib\site-packages\tornado\locks.py", line 482, in release
    super(BoundedSemaphore, self).release()
  File "C:\Miniconda36-x64\lib\site-packages\tornado\locks.py", line 411, in release
    waiter.set_result(_ReleasingContextManager(self))
  File "C:\Miniconda36-x64\lib\asyncio\base_events.py", line 575, in call_soon
    self._check_closed()
  File "C:\Miniconda36-x64\lib\asyncio\base_events.py", line 358, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Command exited with code 1
$wc = New-Object 'System.Net.WebClient'
```


Discussion:
Appveyor is failing consistently, actually. I expect it is that Tornado 6 was just released. 
It was failing yesterday (or two days ago) for hours in a similar fashion and then just suddenly started working again.
Well, Tornado 6 was released a day or two ago :) I am not sure why it would intermittently work after that, but I can't get anything to pass after ~8 restarts
from bdarnell: "ah, close_all_connections probably became a no-op for you because you're not awaiting it (and it changed from a decorated coroutine to a native one)... you should be able to use yield instead of await when you're calling close_all_connections"

Resolving patch:
diff --git a/bokeh/server/server.py b/bokeh/server/server.py
--- a/bokeh/server/server.py
+++ b/bokeh/server/server.py
@@ -161,7 +161,7 @@ def unlisten(self):
             None
 
         '''
-        self._http.close_all_connections()
+        yield self._http.close_all_connections()
         self._http.stop()
 
     def run_until_shutdown(self):


Test patch:
diff --git a/bokeh/tests/test_client_server.py b/bokeh/tests/test_client_server.py
--- a/bokeh/tests/test_client_server.py
+++ b/bokeh/tests/test_client_server.py
@@ -20,6 +20,7 @@
 import logging
 from mock import patch
 import os
+import sys
 
 # External imports
 from tornado import gen
@@ -292,6 +293,7 @@ def test_request_server_info(self):
             session.loop_until_closed(suppress_warning=True)
             assert not session.connected
 
+    @pytest.mark.skipif(sys.platform == "win32", reason="uninmportant failure on win")
     def test_ping(self):
         application = Application()
         with ManagedServerLoop(application, keep_alive_milliseconds=0) as server: