Skip to content

Commit 93f33b9

Browse files
committed
Tests: Get rid of ResourceWarning messages about unclosed sockets
ResourceWarning: unclosed <socket.socket fd=12, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 52797), raddr=('127.0.0.1', 44209)>
1 parent 30fc28e commit 93f33b9

File tree

6 files changed

+27
-4
lines changed

6 files changed

+27
-4
lines changed

src/crate/client/doctests/blob.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ Store from a file::
3939
>>> file_blob = container.put(f)
4040
>>> file_blob
4141
'ea6e03a4a4ee8a2366fe5a88af2bde61797973ea'
42+
>>> f.close()
4243

4344
If the blob data is not provided as a seekable stream the hash must be
44-
provided explicetely::
45+
provided explicitly::
4546

4647
>>> import hashlib
4748
>>> string_data = b'String data'

src/crate/client/doctests/client.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The client provides a ``connect()`` function which is used to establish a
1313
connection, the first argument is the url of the server to connect to::
1414

1515
>>> connection = client.connect(crate_host)
16+
>>> connection.close()
1617

1718
CrateDB is a clustered database providing high availability through
1819
replication. In order for clients to make use of this property it is
@@ -21,22 +22,26 @@ respond, the request is automatically routed to the next server::
2122

2223
>>> invalid_host = 'http://not_responding_host:4200'
2324
>>> connection = client.connect([invalid_host, crate_host])
25+
>>> connection.close()
2426

2527
If no ``servers`` are given, the default one ``http://127.0.0.1:4200`` is used::
2628

2729
>>> connection = client.connect()
2830
>>> connection.client._active_servers
2931
['http://127.0.0.1:4200']
32+
>>> connection.close()
3033

3134
If the option ``error_trace`` is set to ``True``, the client will print a whole
3235
traceback if a server error occurs::
3336

3437
>>> connection = client.connect([crate_host], error_trace=True)
38+
>>> connection.close()
3539

3640
It's possible to define a default timeout value in seconds for all servers
3741
using the optional parameter ``timeout``::
3842

3943
>>> connection = client.connect([crate_host, invalid_host], timeout=5)
44+
>>> connection.close()
4045

4146
Authentication
4247
--------------
@@ -50,13 +55,15 @@ connect::
5055
>>> connection.client.username
5156
'trusted_me'
5257
>>> connection.client.password
58+
>>> connection.close()
5359

5460
The username for trusted users can also be provided in the URL::
5561

5662
>>> connection = client.connect(['http://trusted_me@' + crate_host])
5763
>>> connection.client.username
5864
'trusted_me'
5965
>>> connection.client.password
66+
>>> connection.close()
6067

6168
To connect to CrateDB with as a user that requires password authentication, you
6269
also need to provide ``password`` as argument for the ``connect()`` call::
@@ -68,6 +75,7 @@ also need to provide ``password`` as argument for the ``connect()`` call::
6875
'me'
6976
>>> connection.client.password
7077
'my_secret_pw'
78+
>>> connection.close()
7179

7280
The authentication credentials can also be provided in the URL::
7381

@@ -76,6 +84,7 @@ The authentication credentials can also be provided in the URL::
7684
'me'
7785
>>> connection.client.password
7886
'my_secret_pw'
87+
>>> connection.close()
7988

8089

8190
Default Schema
@@ -86,6 +95,7 @@ provide the ``schema`` keyword argument in the ``connect()`` method, like so::
8695

8796
>>> connection = client.connect([crate_host],
8897
... schema='custom_schema')
98+
>>> connection.close()
8999

90100
Inserting Data
91101
==============

src/crate/client/doctests/cursor.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ For completeness' sake the cursor description is updated nonetheless::
263263
... "duration":123
264264
... })
265265

266+
.. Hidden: close connection
267+
268+
>>> connection.close()
266269

267270
Usually ``executemany`` sends the ``bulk_args`` parameter to the crate sql
268271
endpoint which was introduced with Crate 0.42.0.
@@ -313,3 +316,6 @@ closed connection an ``ProgrammingError`` exception will be raised::
313316
...
314317
crate.client.exceptions.ProgrammingError: Cursor closed
315318

319+
.. Hidden: close connection
320+
321+
>>> connection.close()

src/crate/client/sqlalchemy/doctests/itests.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,7 @@ Refresh "characters" table:
220220
>>> import pprint
221221
>>> pprint.pprint(char.details)
222222
{'name': {'first': 'Trillian', 'last': 'Dent'}, 'size': 45}
223+
224+
.. Hidden: close connection
225+
226+
>>> connection.close()

src/crate/client/test_http.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,15 @@ def test_connection_reset_exception(self):
116116
def test_no_connection_exception(self):
117117
client = Client()
118118
self.assertRaises(ConnectionError, client.sql, 'select foo')
119+
client.close()
119120

120121
@patch(REQUEST)
121122
def test_http_error_is_re_raised(self, request):
122123
request.side_effect = Exception
123124

124125
client = Client()
125126
self.assertRaises(ProgrammingError, client.sql, 'select foo')
127+
client.close()
126128

127129
@patch(REQUEST)
128130
def test_programming_error_contains_http_error_response_content(self, request):
@@ -283,6 +285,7 @@ def test_socket_options_contain_keepalive(self):
283285
self.assertTrue(
284286
(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1) in conn_kw['socket_options']
285287
)
288+
client.close()
286289

287290

288291
@patch(REQUEST, fail_sometimes)

src/crate/client/tests.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,11 @@ def do_GET(self):
264264
self.end_headers()
265265
self.wfile.write(payload)
266266

267-
def __init__(self):
267+
def setUp(self):
268268
self.server = self.HttpsServer(
269269
(self.HOST, self.PORT),
270270
self.HttpsHandler
271271
)
272-
273-
def setUp(self):
274272
thread = threading.Thread(target=self.serve_forever)
275273
thread.daemon = True # quit interpreter when only thread exists
276274
thread.start()
@@ -283,6 +281,7 @@ def serve_forever(self):
283281

284282
def tearDown(self):
285283
self.server.shutdown()
284+
self.server.server_close()
286285

287286
def isUp(self):
288287
"""

0 commit comments

Comments
 (0)