@@ -22,8 +22,10 @@ import (
2222 "gotest.tools/v3/assert"
2323
2424 "go.etcd.io/etcd/server/v3/lease"
25+ "go.etcd.io/etcd/server/v3/lease/leasepb"
2526 "go.etcd.io/etcd/server/v3/storage/backend"
2627 "go.etcd.io/etcd/server/v3/storage/mvcc"
28+ "go.etcd.io/etcd/server/v3/storage/schema"
2729)
2830
2931func TestCalculateHashKV (t * testing.T ) {
@@ -39,20 +41,6 @@ func TestCalculateHashKV(t *testing.T) {
3941 }
4042
4143 testCases := []testCase {
42- {
43- name : "non-existent file" ,
44- setupFunc : func (t * testing.T ) (string , func ()) {
45- return "/nonexistent/path/to/db" , func () {}
46- },
47- expectError : true ,
48- },
49- {
50- name : "empty directory path" ,
51- setupFunc : func (t * testing.T ) (string , func ()) {
52- return "" , func () {}
53- },
54- expectError : true ,
55- },
5644 {
5745 name : "empty database" ,
5846 setupFunc : func (t * testing.T ) (string , func ()) {
@@ -92,6 +80,33 @@ func TestCalculateHashKV(t *testing.T) {
9280 expectedCompact : - 1 ,
9381 expectError : false ,
9482 },
83+ {
84+ name : "database with data and lease" ,
85+ setupFunc : func (t * testing.T ) (string , func ()) {
86+ tempDir := t .TempDir ()
87+ dbPath := filepath .Join (tempDir , "test_with_data_lease.db" )
88+
89+ b := backend .NewDefaultBackend (zap .NewNop (), dbPath )
90+ // create lease
91+ lpb := leasepb.Lease {ID : 1 , TTL : 60 , RemainingTTL : 60 }
92+ tx := b .BatchTx ()
93+ tx .UnsafeCreateBucket (schema .Lease )
94+ schema .MustUnsafePutLease (tx , & lpb )
95+ tx .Commit ()
96+ // put with lease id
97+ st := mvcc .NewStore (zap .NewNop (), b , & lease.FakeLessor {}, mvcc.StoreConfig {})
98+ st .Put ([]byte ("test-key" ), []byte ("test-value" ), 1 )
99+ st .Close ()
100+ b .Close ()
101+
102+ return dbPath , func () {}
103+ },
104+ revision : 0 ,
105+ expectedHash : 645561629 ,
106+ expectedRev : 2 ,
107+ expectedCompact : - 1 ,
108+ expectError : false ,
109+ },
95110 {
96111 name : "invalid revision" ,
97112 setupFunc : func (t * testing.T ) (string , func ()) {
@@ -114,12 +129,6 @@ func TestCalculateHashKV(t *testing.T) {
114129
115130 for _ , tc := range testCases {
116131 t .Run (tc .name , func (t * testing.T ) {
117- defer func () {
118- if r := recover (); r != nil {
119- t .Logf ("Recovered from panic: %v" , r )
120- }
121- }()
122-
123132 dbPath , cleanup := tc .setupFunc (t )
124133 defer cleanup ()
125134
0 commit comments