Skip to content

Commit 4fc0aaa

Browse files
committed
test: cover multiprocessing writer defaults
1 parent 948ea36 commit 4fc0aaa

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

tests/test_multiprocessing_helper.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
import logging
22
import queue
3-
from unittest.mock import Mock
3+
from unittest.mock import Mock, patch
44

55
import pytest
66

7-
from influxdb_client_3.write_client.client.util.multiprocessing_helper import MultiprocessingWriter, _PoisonPill
7+
from influxdb_client_3.write_client.client.util.multiprocessing_helper import (
8+
MultiprocessingWriter,
9+
_PoisonPill,
10+
_error_callback,
11+
_retry_callback,
12+
_success_callback,
13+
)
814

915

1016
def make_writer(**kwargs):
@@ -121,6 +127,37 @@ def test_get_start_processing_method_returns_context_method():
121127
assert make_writer().get_start_processing_method() == "spawn"
122128

123129

130+
def test_default_callbacks_log_batch_events(caplog):
131+
caplog.set_level(logging.DEBUG)
132+
conf = ("database", "org", "precision")
133+
exception = ValueError("write failed")
134+
135+
_success_callback(conf, "data")
136+
_error_callback(conf, "data", exception)
137+
_retry_callback(conf, "data", exception)
138+
139+
assert "Written batch" in caplog.text
140+
assert "Cannot write batch" in caplog.text
141+
assert "Retryable error occurs" in caplog.text
142+
143+
144+
def test_constructor_builds_rest_client_from_host_and_token():
145+
rest_client_path = "influxdb_client_3.write_client.client.util.multiprocessing_helper.rest_client.RestClient"
146+
with patch(rest_client_path) as rest_client:
147+
writer = MultiprocessingWriter(
148+
start_method="spawn",
149+
host="http://localhost:8086",
150+
token="my-token",
151+
database="test",
152+
)
153+
154+
rest_client.assert_called_once_with(
155+
base_url="http://localhost:8086",
156+
default_header={"Authorization": "Token my-token"},
157+
)
158+
writer.close()
159+
160+
124161
def test_worker_timeout_closes_api_and_invokes_callback_once():
125162
writer = make_writer(process_ttl=0.01)
126163
writer.queue_ = Mock()

0 commit comments

Comments
 (0)