From d6e8388b6c9c92ce10de228bf925f26ee0a94491 Mon Sep 17 00:00:00 2001 From: Konrad Wojas Date: Thu, 7 Dec 2023 20:45:47 +0800 Subject: [PATCH] Improve readonly Txn tests --- lmdb/txn_test.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lmdb/txn_test.go b/lmdb/txn_test.go index 6c6e0a3..b9ef8d0 100644 --- a/lmdb/txn_test.go +++ b/lmdb/txn_test.go @@ -943,6 +943,9 @@ func TestTxn_Reset_readonly_C_free(t *testing.T) { // Since this is a readonly transaction, the global Env key/val cannot be // reused and new C memory must be allocated. + if txn.key == env.ckey || txn.val == env.cval { + t.Error("env.ckey and cval must not be used in a readonly Txn") + } if txn.cbuf == nil { t.Error("cbuf expected to not be nil when opening a readonly Txn") } @@ -951,6 +954,18 @@ func TestTxn_Reset_readonly_C_free(t *testing.T) { txn.Reset() if txn.cbuf == nil { t.Error("cbuf must not be nil after Reset") + return + } + + // Renew must not free the buffer + err = txn.Renew() + if err != nil { + t.Error(err) + return + } + if txn.cbuf == nil { + t.Error("cbuf must not be nil after Reset") + return } // Abort must free the buffer