Files
zapdb/y/error_test.go
Sarthak MakhijaandGitHub 2559ce12f6 Sync active memtable and value log on Db.Sync (#1847) (#1953)
Fixes https://github.com/dgraph-io/badger/issues/1847

Currently, `DB.Sync()` only syncs the value log but not the WAL of the
active memtable, however recovery happens from the WAL of the active
memtable as a part of the `DB.Open()` method.

This change attempts to sync both the logs, however there can be an
issue in syncing one of the logs. This change lists all of the possible
cases that can arise during the sync operations. Some of these issues
will be taken separately. For example,
the issue https://github.com/dgraph-io/badger/issues/1954 can arise and
shall be handled separately.

This change adds a few tests to ensure that the Sync behavior is not
broken. This change also adds a learning test `(db2_test.go ->
TestAssertValueLogIsNotWrittenToOnStartup)` to ensure that value log is
only read from (and not written to) during startup. This learning shall
be used in the next issue (the one described above (*))
2023-06-03 09:42:00 -04:00

29 lines
737 B
Go

package y
import (
"errors"
"testing"
"github.com/stretchr/testify/require"
)
func TestCombineWithBothErrorsPresent(t *testing.T) {
combinedError := CombineErrors(errors.New("one"), errors.New("two"))
require.Equal(t, "one; two", combinedError.Error())
}
func TestCombineErrorsWithOneErrorPresent(t *testing.T) {
combinedError := CombineErrors(errors.New("one"), nil)
require.Equal(t, "one", combinedError.Error())
}
func TestCombineErrorsWithOtherErrorPresent(t *testing.T) {
combinedError := CombineErrors(nil, errors.New("other"))
require.Equal(t, "other", combinedError.Error())
}
func TestCombineErrorsWithBothErrorsAsNil(t *testing.T) {
combinedError := CombineErrors(nil, nil)
require.NoError(t, combinedError)
}