22from django .test import TestCase
33
44from channels .db import database_sync_to_async
5+ from channels .generic .http import AsyncHttpConsumer
56from channels .generic .websocket import AsyncWebsocketConsumer
6- from channels .testing import WebsocketCommunicator
7+ from channels .testing import HttpCommunicator , WebsocketCommunicator
78
89
910@database_sync_to_async
@@ -19,8 +20,18 @@ async def connect(self):
1920 await self .accept ("fun" )
2021
2122
23+ class HttpConsumer (AsyncHttpConsumer ):
24+ async def handle (self , body ):
25+ await basic_query ()
26+ await self .send_response (
27+ 200 ,
28+ b"" ,
29+ headers = {b"Content-Type" : b"text/plain" },
30+ )
31+
32+
2233class ConnectionClosingTests (TestCase ):
23- async def test_doesnt_close_connections_in_test_case (self ):
34+ async def test_websocket (self ):
2435 self .assertNotRegex (
2536 db .connections ["default" ].settings_dict .get ("NAME" ),
2637 "memorydb" ,
@@ -30,3 +41,15 @@ async def test_doesnt_close_connections_in_test_case(self):
3041 connected , subprotocol = await communicator .connect ()
3142 self .assertTrue (connected )
3243 self .assertEqual (subprotocol , "fun" )
44+
45+ async def test_http (self ):
46+ self .assertNotRegex (
47+ db .connections ["default" ].settings_dict .get ("NAME" ),
48+ "memorydb" ,
49+ "This bug only occurs when the database is materialized on disk" ,
50+ )
51+ communicator = HttpCommunicator (
52+ HttpConsumer .as_asgi (), method = "GET" , path = "/test/"
53+ )
54+ connected = await communicator .get_response ()
55+ self .assertTrue (connected )
0 commit comments