mirror of https://github.com/etcd-io/bbolt.git
add failpoint 'resizeFileError' to simulate file.Truncate error
Signed-off-by: Benjamin Wang <wachao@vmware.com>pull/482/head
parent
97d2cc34ac
commit
465077b9e2
2
db.go
2
db.go
|
@ -1135,6 +1135,8 @@ func (db *DB) grow(sz int) error {
|
|||
// https://github.com/boltdb/bolt/issues/284
|
||||
if !db.NoGrowSync && !db.readOnly {
|
||||
if runtime.GOOS != "windows" {
|
||||
// gofail: var resizeFileError string
|
||||
// return errors.New(resizeFileError)
|
||||
if err := db.file.Truncate(int64(sz)); err != nil {
|
||||
return fmt.Errorf("file resize error: %s", err)
|
||||
}
|
||||
|
|
|
@ -94,3 +94,31 @@ func TestFailpoint_mLockFail_When_remap(t *testing.T) {
|
|||
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestFailpoint_ResizeFileFail(t *testing.T) {
|
||||
db := btesting.MustCreateDB(t)
|
||||
|
||||
err := gofail.Enable("resizeFileError", `return("resizeFile somehow failed")`)
|
||||
require.NoError(t, err)
|
||||
|
||||
err = db.Fill([]byte("data"), 1, 10000,
|
||||
func(tx int, k int) []byte { return []byte(fmt.Sprintf("%04d", k)) },
|
||||
func(tx int, k int) []byte { return make([]byte, 100) },
|
||||
)
|
||||
|
||||
require.Error(t, err)
|
||||
require.ErrorContains(t, err, "resizeFile somehow failed")
|
||||
|
||||
// It should work after disabling the failpoint.
|
||||
err = gofail.Disable("resizeFileError")
|
||||
require.NoError(t, err)
|
||||
db.MustClose()
|
||||
db.MustReopen()
|
||||
|
||||
err = db.Fill([]byte("data"), 1, 10000,
|
||||
func(tx int, k int) []byte { return []byte(fmt.Sprintf("%04d", k)) },
|
||||
func(tx int, k int) []byte { return make([]byte, 100) },
|
||||
)
|
||||
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue