Skip to content

Commit

Permalink
Mock receive_end_of_query with 2 seconds sleep before call
Browse files Browse the repository at this point in the history
  • Loading branch information
insomnes committed Oct 12, 2023
1 parent a1eeedc commit ce63ac6
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions tests/test_long_insert.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from time import sleep
from unittest.mock import patch

from tests.testcase import BaseTestCase


Expand All @@ -18,16 +21,30 @@ def test_long_insert(self):
This insert should work normally for all clickhouse versions,
even without response ProfileEvents on each insert.
The 100_000 rows used to provide somewaht consistent experience of
bug reproducability without too long test duration.
The 8_000 rows used to provide somewhat consistent experience of
bug reproducibility without too long of a test duration.
`send_timeout` & `receive_timeout` are set to 1,
so we can emulate the real world situation on synthetic data.
The server will send exception and timeout if the client will not
receive the ProfileEvent during this time.
We modify receive_end_of_query with sleep here to emulate long pause
before this method calling under normal circumstances.
"""
original_receive_end_of_query = self.client.receive_end_of_query

def mocked_receive_end_of_query(*args, **kwargs):
sleep(2)
return original_receive_end_of_query(*args, **kwargs)

with self.create_table('x Int32'):
data = [{'x': 1}] * 100_000
self.client.execute(
'INSERT INTO test (x) VALUES', data
)
with patch.object(
self.client,
'receive_end_of_query',
new=mocked_receive_end_of_query
):
data = [{'x': 1}] * 8_000
self.client.execute(
'INSERT INTO test (x) VALUES', data
)

0 comments on commit ce63ac6

Please sign in to comment.