@@ -48,9 +48,14 @@ def tearDown(self):
4848 asyncio .get_event_loop ().run_until_complete (
4949 self .communicator .wait ()
5050 )
51-
51+
52+ async def create_communicator (self , app ):
53+ return ApplicationCommunicator (app , self .scope )
54+
5255 def seed_app (self , app ):
53- self .communicator = ApplicationCommunicator (app , self .scope )
56+ self .communicator = asyncio .get_event_loop ().run_until_complete (
57+ self .create_communicator (app )
58+ )
5459
5560 def send_input (self , payload ):
5661 asyncio .get_event_loop ().run_until_complete (
@@ -148,9 +153,9 @@ def test_gzip(self):
148153 increments = 2
149154 self .increment_metrics (metric_name , help_text , increments )
150155 app = make_asgi_app (self .registry )
151- self .seed_app (app )
152156 # Send input with gzip header.
153157 self .scope ["headers" ] = [(b"accept-encoding" , b"gzip" )]
158+ self .seed_app (app )
154159 self .send_input ({"type" : "http.request" , "body" : b"" })
155160 # Assert outputs are compressed.
156161 outputs = self .get_all_output ()
@@ -164,9 +169,9 @@ def test_gzip_disabled(self):
164169 self .increment_metrics (metric_name , help_text , increments )
165170 # Disable compression explicitly.
166171 app = make_asgi_app (self .registry , disable_compression = True )
167- self .seed_app (app )
168172 # Send input with gzip header.
169173 self .scope ["headers" ] = [(b"accept-encoding" , b"gzip" )]
174+ self .seed_app (app )
170175 self .send_input ({"type" : "http.request" , "body" : b"" })
171176 # Assert outputs are not compressed.
172177 outputs = self .get_all_output ()
@@ -175,8 +180,8 @@ def test_gzip_disabled(self):
175180 def test_openmetrics_encoding (self ):
176181 """Response content type is application/openmetrics-text when appropriate Accept header is in request"""
177182 app = make_asgi_app (self .registry )
178- self .seed_app (app )
179183 self .scope ["headers" ] = [(b"Accept" , b"application/openmetrics-text" )]
184+ self .seed_app (app )
180185 self .send_input ({"type" : "http.request" , "body" : b"" })
181186
182187 content_type = self .get_response_header_value ('Content-Type' ).split (";" )[0 ]
0 commit comments