Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(tests): unbreak tests on Windows #1775

Merged
merged 2 commits into from
Dec 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion db2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ func TestWindowsDataLoss(t *testing.T) {
err := db.Update(func(txn *Txn) error {
key := []byte(fmt.Sprintf("%d", i))
v := []byte("barValuebarValuebarValuebarValuebarValue")
require.Greater(t, len(v), db.valueThreshold())
require.Greater(t, int64(len(v)), db.valueThreshold())

//32 bytes length and now it's not working
err := txn.Set(key, v)
Expand All @@ -710,6 +710,7 @@ func TestWindowsDataLoss(t *testing.T) {
// Don't use vlog.Close here. We don't want to fix the file size. Only un-mmap
// the data so that we can truncate the file durning the next vlog.Open.
require.NoError(t, z.Munmap(db.vlog.filesMap[db.vlog.maxFid].Data))
require.NoError(t, db.mt.wal.Close(-1))
for _, f := range db.vlog.filesMap {
require.NoError(t, f.Fd.Close())
}
Expand Down
32 changes: 21 additions & 11 deletions db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2234,11 +2234,13 @@ func TestOpenDBReadOnly(t *testing.T) {

ops.ReadOnly = true
db, err = Open(ops)
require.NoError(t, err)
require.NoError(t, db.Close())
if runtime.GOOS == "windows" {
require.Equal(t, err, ErrWindowsNotSupported)
} else {
require.NoError(t, err)
require.NoError(t, db.Close())
}

db, err = Open(ops)
require.NoError(t, err)
var count int
read := func() {
count = 0
Expand All @@ -2256,9 +2258,13 @@ func TestOpenDBReadOnly(t *testing.T) {
return nil
})
}
read()
require.Equal(t, 10, count)
require.NoError(t, db.Close())
if runtime.GOOS != "windows" {
db, err = Open(ops)
require.NoError(t, err)
read()
require.Equal(t, 10, count)
require.NoError(t, db.Close())
}

ops.ReadOnly = false
db, err = Open(ops)
Expand All @@ -2279,10 +2285,14 @@ func TestOpenDBReadOnly(t *testing.T) {

ops.ReadOnly = true
db, err = Open(ops)
require.NoError(t, err)
read()
require.Equal(t, 20, count)
require.NoError(t, db.Close())
if runtime.GOOS == "windows" {
require.Equal(t, err, ErrWindowsNotSupported)
} else {
require.NoError(t, err)
read()
require.Equal(t, 20, count)
require.NoError(t, db.Close())
}
}

func TestBannedPrefixes(t *testing.T) {
Expand Down
6 changes: 6 additions & 0 deletions iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"math/rand"
"os"
"path/filepath"
"runtime"
"strings"
"testing"

Expand Down Expand Up @@ -303,6 +304,11 @@ func TestIteratorReadOnlyWithNoData(t *testing.T) {

opts.ReadOnly = true
db, err = Open(opts)
if runtime.GOOS == "windows" {
require.Equal(t, err, ErrWindowsNotSupported)
return
}

require.NoError(t, err)
defer func() {
require.NoError(t, db.Close())
Expand Down
4 changes: 4 additions & 0 deletions pb/protos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package pb

import (
"os/exec"
"runtime"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -32,6 +33,9 @@ func Exec(argv ...string) error {
}

func TestProtosRegenerate(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("protobuf regeneration is not supported on Windows")
}
err := Exec("./gen.sh")
require.NoError(t, err, "Got error while regenerating protos: %v\n", err)

Expand Down
13 changes: 11 additions & 2 deletions value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"math/rand"
"os"
"reflect"
"runtime"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -726,8 +727,12 @@ func TestReadOnlyOpenWithPartialAppendToWAL(t *testing.T) {
opts.ReadOnly = true
// Badger should fail a read-only open with values to replay
_, err = Open(opts)
require.Error(t, err)
require.Regexp(t, "Log truncate required", err.Error())
if runtime.GOOS == "windows" {
require.Equal(t, err, ErrWindowsNotSupported)
} else {
require.Error(t, err)
require.Regexp(t, "Log truncate required", err.Error())
}
}

func TestValueLogTrigger(t *testing.T) {
Expand Down Expand Up @@ -796,6 +801,10 @@ func createMemFile(t *testing.T, entries []*Entry) ([]byte, uint32) {

// This test creates two mem files and corrupts the last bit of the first file.
func TestPenultimateMemCorruption(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping corruption tests on Windows since it does not allow removal of mmaped files")
}

dir, err := ioutil.TempDir("", "badger-test")
require.NoError(t, err)
defer removeDir(dir)
Expand Down