Skip to content

Commit 3a7c427

Browse files
authored
test: Guarantee that revisions work after commit (#1558)
## Why this should be merged After running into a hang during `(*Proposal).Commit()` in a re-execution test, I thought it would be nice to guarantee that revisions can be held through the commit. ## How this works Guarantees behavior that a revision is still valid if it's underlying proposal has been committed ## How this was tested Go
1 parent 6d0fb86 commit 3a7c427

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

ffi/firewood_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,45 @@ func TestRevisionOutlivesProposal(t *testing.T) {
889889
r.NoError(rev.Drop())
890890
}
891891

892+
// Tests that after committing a proposal, the corresponding revision is still accessible.
893+
func TestCommitWithRevisionHeld(t *testing.T) {
894+
r := require.New(t)
895+
db := newTestDatabase(t)
896+
897+
keys, vals := kvForTest(20)
898+
root, err := db.Update(keys[:10], vals[:10])
899+
r.NoError(err)
900+
base, err := db.Revision(root)
901+
r.NoError(err)
902+
903+
// Create a proposal with 10 key-value pairs.
904+
nKeys, nVals := keys[10:], vals[10:]
905+
proposal, err := db.Propose(nKeys, nVals)
906+
r.NoError(err)
907+
root, err = proposal.Root()
908+
r.NoError(err)
909+
910+
rev, err := db.Revision(root)
911+
r.NoError(err)
912+
913+
// both revisions should be accessible after commit
914+
r.NoError(proposal.Commit())
915+
for i, key := range keys {
916+
val, err := base.Get(key)
917+
r.NoErrorf(err, "base.Get(): %d", i)
918+
if i < 10 {
919+
r.Equalf(val, vals[i], "base.Get(): %d", i)
920+
} else {
921+
r.Emptyf(val, "base.Get(): %d", i)
922+
}
923+
val, err = rev.Get(key)
924+
r.NoErrorf(err, "rev.Get(): %d", i)
925+
r.Equalf(val, vals[i], "rev.Get(): %d", i)
926+
}
927+
r.NoError(base.Drop())
928+
r.NoError(rev.Drop())
929+
}
930+
892931
// Tests that holding a reference to revision will prevent from it being reaped
893932
func TestRevisionOutlivesReaping(t *testing.T) {
894933
r := require.New(t)

0 commit comments

Comments
 (0)