This repository was archived by the owner on Apr 1, 2026. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -145,7 +145,8 @@ def __init__(
145145 self ._executor = concurrent .futures .ThreadPoolExecutor ()
146146 self ._is_open = True
147147 atexit .register (self .close )
148- threading .Timer (flush_interval , self .flush ).start ()
148+ self ._timer = threading .Timer (flush_interval , self .flush )
149+ self ._timer .start ()
149150
150151 @property
151152 def flush_count (self ):
Original file line number Diff line number Diff line change 1414
1515
1616import mock
17+ import time
18+
1719import pytest
1820
1921from google .cloud .bigtable .row import DirectRow
@@ -180,12 +182,29 @@ def test_mutations_batcher_mutate_after_batcher_closed_raise_error():
180182
181183 assert table .mutation_calls == 0
182184 with pytest .raises (BatcherIsClosedError ):
183- mutation_batcher .close ()
184185 row = DirectRow (row_key = b"row_key" )
185186 row .set_cell ("cf1" , b"c1" , 1 )
186187 mutation_batcher .mutate (row )
187188
188189
190+ @mock .patch ("google.cloud.bigtable.batcher.MutationsBatcher.flush" )
191+ def test_mutations_batcher_flush_interval (mocked_flush ):
192+ table = _Table (TABLE_NAME )
193+ flush_interval = 0.5
194+ mutation_batcher = MutationsBatcher (table = table , flush_interval = flush_interval )
195+
196+ assert mutation_batcher ._timer .interval == flush_interval
197+ mocked_flush .assert_not_called ()
198+
199+ time .sleep (0.4 )
200+ mocked_flush .assert_not_called ()
201+
202+ time .sleep (0.1 )
203+ mocked_flush .assert_called_once_with ()
204+
205+ mutation_batcher .close ()
206+
207+
189208class _Instance (object ):
190209 def __init__ (self , client = None ):
191210 self ._client = client
You can’t perform that action at this time.
0 commit comments