watchtower: update DeleteCommittedUpdate to delete all

This commit updates the DeleteCommittedUpdate DB method to delete all of
a given session's committed updates instead of just one at a time. The
reason for this is that in an upcoming commit, we will introduce a
"Terminal" session state - once we have deleted a committed update for a
session it should be considered "Terminal" and there is never a case
where we would only want to delete one committed update and not the
rest. So we want these two actions (deleting committed updates of a
session and setting it's status to terminal) to be atomic.
This commit is contained in:
Elle Mouton committed 2024-02-20 08:58:45 +02:00
1 parent a3bf2c70e5
commit 1ae802812c
4 files changed
+55 -51

No files matched your search

+4 -15
View File
@@ -194,12 +194,12 @@ func (h *clientDBHarness) ackUpdate(id *wtdb.SessionID, seqNum uint16,
require.ErrorIs(h.t, err, expErr)
}
func (h *clientDBHarness) deleteCommittedUpdate(id *wtdb.SessionID,
seqNum uint16, expErr error) {
func (h *clientDBHarness) deleteCommittedUpdates(id *wtdb.SessionID,
expErr error) {
h.t.Helper()
err := h.db.DeleteCommittedUpdate(id, seqNum)
err := h.db.DeleteCommittedUpdates(id)
require.ErrorIs(h.t, err, expErr)
}
@@ -660,18 +660,7 @@ func testCommitUpdate(h *clientDBHarness) {
// We will now also test that the DeleteCommittedUpdates method also
// works.
// First, try to delete a committed update that does not exist.
h.deleteCommittedUpdate(
&session.ID, update4.SeqNum, wtdb.ErrCommittedUpdateNotFound,
)
// Now delete an existing committed update and ensure that it succeeds.
h.deleteCommittedUpdate(&session.ID, update1.SeqNum, nil)
h.assertUpdates(session.ID, []wtdb.CommittedUpdate{
*update2,
}, nil)
h.deleteCommittedUpdate(&session.ID, update2.SeqNum, nil)
h.deleteCommittedUpdates(&session.ID, nil)
h.assertUpdates(session.ID, []wtdb.CommittedUpdate{}, nil)
}