@@ -1066,34 +1066,35 @@ def test_device_update_config_not_in_progress(
10661066 conf .save ()
10671067 mocked_get_working_connection .assert_called_once ()
10681068 mocked_update_config .assert_called_once ()
1069- mocked_release .assert_called_once ()
1069+ mocked_release .assert_called_once_with (
1070+ str (conf .device .pk ), "fake-lock-token"
1071+ )
10701072
10711073 def test_acquire_update_config_lock (self ):
10721074 """Test that the lock can be acquired and prevents duplicate acquisition."""
10731075 device_id = "test-device-id"
10741076 # First acquisition should succeed and return a token
10751077 token = _acquire_update_config_lock (device_id )
1078+ self .addCleanup (_release_update_config_lock , device_id , token )
10761079 self .assertIsNotNone (token )
10771080 # Second acquisition should fail (lock already held)
10781081 self .assertIsNone (_acquire_update_config_lock (device_id ))
10791082 # After releasing with correct token, acquisition should succeed again
10801083 _release_update_config_lock (device_id , token )
10811084 token2 = _acquire_update_config_lock (device_id )
1085+ self .addCleanup (_release_update_config_lock , device_id , token2 )
10821086 self .assertIsNotNone (token2 )
1083- # Cleanup
1084- _release_update_config_lock (device_id , token2 )
10851087
10861088 def test_release_update_config_lock_wrong_token (self ):
10871089 """Only the lock owner can release the lock."""
10881090 device_id = "test-device-id"
10891091 token = _acquire_update_config_lock (device_id )
1092+ self .addCleanup (_release_update_config_lock , device_id , token )
10901093 self .assertIsNotNone (token )
10911094 # Releasing with wrong token should not delete the lock
10921095 _release_update_config_lock (device_id , "wrong-token" )
10931096 # Lock should still be held
10941097 self .assertIsNone (_acquire_update_config_lock (device_id ))
1095- # Releasing with correct token should work
1096- _release_update_config_lock (device_id , token )
10971098
10981099 @mock .patch (_connect_path )
10991100 def test_schedule_command_called (self , connect_mocked ):
0 commit comments