wtdb: let DeleteCommitedUpdates move session to terminal

In this commit, we adjust the DeleteCommitmentUpdate method so that it
marks a session as Terminal (if there are updates to delete) since once
we have deleted a commitment update from a session - the session is no
longer useable.
This commit is contained in:
Elle Mouton committed 2024-02-20 14:44:11 +02:00
1 parent 5cb8c8df7e
commit cbf08940ca
2 files changed
+71 -10

No files matched your search

+38
View File
@@ -1002,6 +1002,44 @@ func testMarkChannelClosed(h *clientDBHarness) {
// Assert that we now can delete the session.
h.deleteSession(session1.ID, nil)
require.Empty(h.t, h.listClosableSessions(nil))
// We also want to test that a session can be deleted if it has been
// marked as terminal.
// Create session2 with MaxUpdates set to 5.
session2 := h.randSession(h.t, tower.ID, 5)
h.insertSession(session2, nil)
// Create and register channel 7.
chanID7 := randChannelID(h.t)
h.registerChan(chanID7, nil, nil)
// Add two updates for channel 7 in session 2. Ack one of them so that
// the mapping from this channel to this session is created but don't
// ack the other since we want to delete the committed update later.
update = randCommittedUpdateForChannel(h.t, chanID7, 1)
h.commitUpdate(&session2.ID, update, nil)
h.ackUpdate(&session2.ID, 1, 1, nil)
update = randCommittedUpdateForChannel(h.t, chanID7, 2)
h.commitUpdate(&session2.ID, update, nil)
// Check that attempting to delete the session will fail since it is not
// yet considered closable.
h.deleteSession(session2.ID, wtdb.ErrSessionNotClosable)
// Now delete the added committed updates. This should put the
// session in the terminal state after which we should be able to
// delete the session.
h.deleteCommittedUpdates(&session2.ID, nil)
// Marking channel 7 as closed will now return session 2 since it has
// been marked as terminal.
sl = h.markChannelClosed(chanID7, 1, nil)
require.ElementsMatch(h.t, sl, []wtdb.SessionID{session2.ID})
// We should now be able to delete the session.
h.deleteSession(session2.ID, nil)
}
// testAckUpdate asserts the behavior of AckUpdate.