Skip to content

Commit d2ad939

Browse files
test: add multiprocess helper test
1 parent 480a1e8 commit d2ad939

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

influxdb_client_3/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,10 @@ def flush(self):
740740

741741
def close(self):
742742
"""Close the client and clean up resources."""
743-
self._write_api.close()
744-
self._query_api.close()
743+
if self._write_api is not None:
744+
self._write_api.close()
745+
if self._query_api is not None:
746+
self._query_api.close()
745747

746748
def __enter__(self):
747749
return self

influxdb_client_3/write_client/client/util/multiprocessing_helper.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,16 @@ def run(self):
154154
error_callback=self.kwargs.get('error_callback', _error_callback),
155155
retry_callback=self.kwargs.get('retry_callback', _retry_callback)
156156
)
157+
158+
# Still need to create the InfluxDBClient3 because the init logics of InfluxDBClient3 will create the WriteApi.
159+
# it will make WriteApi class created properly.
157160
self.client = InfluxDBClient3(write_client_options=wco, **self.kwargs)
161+
162+
# Close and set _query_api to None because query_api is not needed in this process.
163+
# We only need write_api.
164+
self.client._query_api.close()
165+
self.client._query_api = None
166+
158167
self.write_api = self.client._write_api
159168
# Infinite loop - until poison pill
160169
while True:

tests/test_influxdb_client_3_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def test_batch_write_closed(self):
309309
list_results = reader.to_pylist()
310310
self.assertEqual(data_size, len(list_results))
311311

312-
# @pytest.mark.skipif(running_on_circleci, reason="Skipping this test on CircleCI")
312+
@pytest.mark.skipif(running_on_circleci, reason="Skipping this test on CircleCI")
313313
def test_multiprocessing_helper(self):
314314
org = 'my-org'
315315
writer = MultiprocessingWriter(

0 commit comments

Comments
 (0)