Repository: django/asgiref

Issue:
Has StatelessServer been updated to the ASGI 3.0 spec? 
I'm currently trying to upgrade my app from Channels 2.4.0 to Channels 3.0.0 and I'm having issues with running my worker.

After some investigation, I'm under the impression that the `StatelessServer` provided in `asgiref` hasn't been updated to the new Application specifications in ASGI 3.0.

Part of StatelessServer that is trying to instantiate an application with a scope, then call it using the receive and send arguments:
https://github.com/django/asgiref/blob/5c249e818bd5e7acef957e236535098c3aff7b42/asgiref/server.py#L87-L94

Specification for the new Application format:
https://asgi.readthedocs.io/en/latest/specs/main.html#applications

That is: `coroutine application(scope, receive, send)`

Since the Worker in Channels is based on `StatelessServer`, this is breaking the worker functionality in Channels 3.0.0.
Is this something that is in the works? Anything I can do to help with this?

Discussion:
andrewgodwin: I'll happily take this if you fix the lint issue!
andrewgodwin: I'll be happy to take this if you fix the linting errors!
lsaavedr: why a comma is needed? T_T
carltongibson: I added a test case for the change. Thanks @lsaavedr. What do you think @andrewgodwin?
lsaavedr: Thanks @carltongibson I need to learn how to make test cases 😔
andrewgodwin: Looks good to me! I'll merge it in now.

Patch:
diff --git a/asgiref/server.py b/asgiref/server.py
index 9fd2e0c..a83b7bf 100644
--- a/asgiref/server.py
+++ b/asgiref/server.py
@@ -3,6 +3,8 @@ import logging
 import time
 import traceback
 
+from .compatibility import guarantee_single_callable
+
 logger = logging.getLogger(__name__)
 
 
@@ -84,10 +86,11 @@ class StatelessServer:
             self.delete_oldest_application_instance()
         # Make an instance of the application
         input_queue = asyncio.Queue()
-        application_instance = self.application(scope=scope)
+        application_instance = guarantee_single_callable(self.application)
         # Run it, and stash the future for later checking
         future = asyncio.ensure_future(
             application_instance(
+                scope=scope,
                 receive=input_queue.get,
                 send=lambda message: self.application_send(scope, message),
             )


Test patch:
diff --git a/tests/test_server.py b/tests/test_server.py
new file mode 100644
index 0000000..77bbd4d
--- /dev/null
+++ b/tests/test_server.py
@@ -0,0 +1,11 @@
+from asgiref.server import StatelessServer
+
+
+def test_stateless_server():
+    """StatlessServer can be instantiated with an ASGI 3 application."""
+
+    async def app(scope, receive, send):
+        pass
+
+    server = StatelessServer(app)
+    server.get_or_create_application_instance("scope_id", {})