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

fix: safely handle multiple deletions of a breakpoint #58

Merged
merged 1 commit into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/googleclouddebugger/firebase_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ def _ActiveBreakpointCallback(self, event):
# If deleting, event.path will be /{breakpointid}
if event.path != '/':
breakpoint_id = event.path[1:]
del self._breakpoints[breakpoint_id]
# Breakpoint may have already been deleted, so pop for possible no-op.
self._breakpoints.pop(breakpoint_id, None)
else:
if event.path == '/':
# New set of breakpoints.
Expand Down
14 changes: 12 additions & 2 deletions tests/firebase_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,12 @@ def callback(self, new_breakpoints):
},
]

expected_results = [[breakpoints[0]], [breakpoints[0], breakpoints[1]],
expected_results = [[breakpoints[0]],
[breakpoints[0], breakpoints[1]],
[breakpoints[0], breakpoints[1], breakpoints[2]],
[breakpoints[1], breakpoints[2]]]
[breakpoints[1], breakpoints[2]],
[breakpoints[1], breakpoints[2]]
]
result_checker = ResultChecker(expected_results, self)

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

# Send in updates to trigger the subscription callback.

# Initial state.
self._fake_subscribe_ref.update('put', '/',
{breakpoints[0]['id']: breakpoints[0]})
# Add a breakpoint via patch.
self._fake_subscribe_ref.update('patch', '/',
{breakpoints[1]['id']: breakpoints[1]})
# Add a breakpoint via put.
self._fake_subscribe_ref.update('put', f'/{breakpoints[2]["id"]}',
breakpoints[2])
# Delete a breakpoint.
self._fake_subscribe_ref.update('put', f'/{breakpoints[0]["id"]}', None)
# Delete the breakpoint a second time; should handle this gracefully.
self._fake_subscribe_ref.update('put', f'/{breakpoints[0]["id"]}', None)

self.assertEqual(len(expected_results), result_checker._change_count)
Expand Down