MCPcopy
hub / github.com/etcd-io/bbolt / TestTx_Check_Panic

Function TestTx_Check_Panic

tx_check_test.go:123–158  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

121}
122
123func TestTx_Check_Panic(t *testing.T) {
124 bucketName := []byte("data")
125 t.Log("Creating db file.")
126 db := btesting.MustCreateDBWithOption(t, &bbolt.Options{PageSize: 4096})
127
128 // Each page can hold roughly 20 key/values pair, so 100 such
129 // key/value pairs will consume about 5 leaf pages.
130 err := db.Fill(bucketName, 1, 100,
131 func(tx int, k int) []byte { return []byte(fmt.Sprintf("%04d", k)) },
132 func(tx int, k int) []byte { return make([]byte, 100) },
133 )
134 require.NoError(t, err)
135
136 corruptRootPage(t, db.DB, bucketName)
137
138 path := db.Path()
139
140 require.NoError(t, db.Close())
141
142 db = btesting.MustOpenDBWithOption(t, path, &bbolt.Options{PageSize: 4096})
143
144 vErr := db.View(func(tx *bbolt.Tx) error {
145 errChan := tx.Check()
146 for cErr := range errChan {
147 fmt.Println("cErr", cErr)
148 return cErr
149 }
150 return nil
151 })
152 require.Error(t, vErr)
153 require.ErrorContains(t, vErr, "has unexpected type/flags: 0")
154
155 // Manually close the db, otherwise the PostTestCleanup will
156 // check the db again and accordingly fail the test.
157 db.MustClose()
158}
159
160// corruptRandomLeafPage corrupts one random leaf page.
161func corruptRandomLeafPageInBucket(t testing.TB, db *bbolt.DB, bucketName []byte) (victimPageId common.Pgid, validPageIds []common.Pgid) {

Callers

nothing calls this directly

Calls 10

MustCreateDBWithOptionFunction · 0.92
MustOpenDBWithOptionFunction · 0.92
corruptRootPageFunction · 0.85
FillMethod · 0.80
ViewMethod · 0.80
CheckMethod · 0.80
MustCloseMethod · 0.80
ErrorMethod · 0.65
PathMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected