@@ -200,3 +200,50 @@ def test_gql():
200
200
client = Client (schema = schema )
201
201
result = client .execute (query )
202
202
assert result ["user" ] is None
203
+
204
+
205
+ @pytest .mark .requests
206
+ def test_sync_transport_close_on_schema_retrieval_failure ():
207
+ """
208
+ Ensure that the transport session is closed if an error occurs when
209
+ entering the context manager (e.g., because schema retrieval fails)
210
+ """
211
+
212
+ from gql .transport .requests import RequestsHTTPTransport
213
+
214
+ transport = RequestsHTTPTransport (url = "http://localhost/" )
215
+ client = Client (transport = transport , fetch_schema_from_transport = True )
216
+
217
+ try :
218
+ with client :
219
+ pass
220
+ except Exception :
221
+ # we don't care what exception is thrown, we just want to check if the
222
+ # transport is closed afterwards
223
+ pass
224
+
225
+ assert client .transport .session is None
226
+
227
+
228
+ @pytest .mark .aiohttp
229
+ @pytest .mark .asyncio
230
+ async def test_async_transport_close_on_schema_retrieval_failure ():
231
+ """
232
+ Ensure that the transport session is closed if an error occurs when
233
+ entering the context manager (e.g., because schema retrieval fails)
234
+ """
235
+
236
+ from gql .transport .aiohttp import AIOHTTPTransport
237
+
238
+ transport = AIOHTTPTransport (url = "http://localhost/" )
239
+ client = Client (transport = transport , fetch_schema_from_transport = True )
240
+
241
+ try :
242
+ async with client :
243
+ pass
244
+ except Exception :
245
+ # we don't care what exception is thrown, we just want to check if the
246
+ # transport is closed afterwards
247
+ pass
248
+
249
+ assert client .transport .session is None
0 commit comments