1818from cloudquery .sdk .schema import Column
1919from cloudquery .sdk .schema .arrow import METADATA_TABLE_NAME
2020from cloudquery .sdk .schema .table import Table
21+ from cloudquery .sdk .stateclient import SyncNotRunningError
2122from cloudquery .sdk .stateclient .stateclient import (
2223 ConnectedStateClient ,
2324 StateClient ,
@@ -223,6 +224,31 @@ def test_flush_writes_to_the_backend_without_checkpoints():
223224 assert state .writes [- 1 ] == [("a" , "3" )]
224225
225226
227+ def test_setting_an_unchanged_value_is_not_a_change ():
228+ state = MemoryStateClient (checkpoints = None )
229+ state .backend ["a" ] = "1"
230+ state .read_all_state ()
231+ state .set_key ("a" , "1" )
232+ state .flush ()
233+ assert state .writes == []
234+
235+ state .set_key ("a" , "2" )
236+ state .set_key ("a" , "2" )
237+ state .flush ()
238+ assert state .writes == [[("a" , "2" )]]
239+
240+
241+ def test_setting_an_unchanged_value_adds_the_caller_to_the_pending_change ():
242+ scheduler = Scheduler (1 )
243+ state = MemoryStateClient (checkpoints = scheduler .checkpoints )
244+ state .set_key ("a" , "1" )
245+ scope = scheduler .checkpoints .new_scope (None )
246+ with scheduler .checkpoints .entered (scope ):
247+ state .set_key ("a" , "1" )
248+ scheduler .shutdown ()
249+ assert state .changes ["a" ] == {None , scope }
250+
251+
226252def test_failed_flush_keeps_the_changes ():
227253 state = MemoryStateClient (checkpoints = None , fail_writes = True )
228254 state .set_key ("a" , "1" )
@@ -238,7 +264,7 @@ def test_checkpoint_flush_outside_a_sync_fails_and_keeps_the_changes():
238264 scheduler = Scheduler (1 )
239265 state = MemoryStateClient (checkpoints = scheduler .checkpoints )
240266 state .set_key ("a" , "1" )
241- with pytest .raises (RuntimeError ):
267+ with pytest .raises (SyncNotRunningError ):
242268 state .flush ()
243269 assert "a" in state .changes
244270 assert state .writes == []
0 commit comments