Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Commit 2db6e86

Browse files
authored
fix: safely handle multiple deletions of a breakpoint (#58)
1 parent 82dc9a7 commit 2db6e86

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/googleclouddebugger/firebase_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,8 @@ def _ActiveBreakpointCallback(self, event):
373373
# If deleting, event.path will be /{breakpointid}
374374
if event.path != '/':
375375
breakpoint_id = event.path[1:]
376-
del self._breakpoints[breakpoint_id]
376+
# Breakpoint may have already been deleted, so pop for possible no-op.
377+
self._breakpoints.pop(breakpoint_id, None)
377378
else:
378379
if event.path == '/':
379380
# New set of breakpoints.

tests/firebase_client_test.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,12 @@ def callback(self, new_breakpoints):
219219
},
220220
]
221221

222-
expected_results = [[breakpoints[0]], [breakpoints[0], breakpoints[1]],
222+
expected_results = [[breakpoints[0]],
223+
[breakpoints[0], breakpoints[1]],
223224
[breakpoints[0], breakpoints[1], breakpoints[2]],
224-
[breakpoints[1], breakpoints[2]]]
225+
[breakpoints[1], breakpoints[2]],
226+
[breakpoints[1], breakpoints[2]]
227+
]
225228
result_checker = ResultChecker(expected_results, self)
226229

227230
self._client.on_active_breakpoints_changed = result_checker.callback
@@ -231,12 +234,19 @@ def callback(self, new_breakpoints):
231234
self._client.subscription_complete.wait()
232235

233236
# Send in updates to trigger the subscription callback.
237+
238+
# Initial state.
234239
self._fake_subscribe_ref.update('put', '/',
235240
{breakpoints[0]['id']: breakpoints[0]})
241+
# Add a breakpoint via patch.
236242
self._fake_subscribe_ref.update('patch', '/',
237243
{breakpoints[1]['id']: breakpoints[1]})
244+
# Add a breakpoint via put.
238245
self._fake_subscribe_ref.update('put', f'/{breakpoints[2]["id"]}',
239246
breakpoints[2])
247+
# Delete a breakpoint.
248+
self._fake_subscribe_ref.update('put', f'/{breakpoints[0]["id"]}', None)
249+
# Delete the breakpoint a second time; should handle this gracefully.
240250
self._fake_subscribe_ref.update('put', f'/{breakpoints[0]["id"]}', None)
241251

242252
self.assertEqual(len(expected_results), result_checker._change_count)

0 commit comments

Comments
 (0)