2018-10-04 13:24:59 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2020-11-25 10:44:31 -08:00
|
|
|
set -eo pipefail
|
2018-10-03 18:58:34 -07:00
|
|
|
|
2019-11-26 01:34:23 +05:30
|
|
|
go version
|
|
|
|
|
|
2022-11-03 17:50:45 -05:00
|
|
|
# Check if Github Actions is running
|
2025-12-12 02:14:54 +08:00
|
|
|
if [ "$CI" = "true" ]; then
|
2025-02-05 17:00:32 -05:00
|
|
|
# Enable code coverage
|
|
|
|
|
# export because tests run in a subprocess
|
|
|
|
|
export covermode="-covermode=atomic"
|
|
|
|
|
export coverprofile="-coverprofile=cover_tmp.out"
|
|
|
|
|
echo "mode: atomic" >>cover.out
|
2022-11-03 17:50:45 -05:00
|
|
|
fi
|
|
|
|
|
|
2020-11-03 19:04:41 -08:00
|
|
|
# Run `go list` BEFORE setting GOFLAGS so that the output is in the right
|
|
|
|
|
# format for grep.
|
2020-11-05 15:23:46 +05:30
|
|
|
# export packages because the test will run in a sub process.
|
2023-02-27 16:21:42 -06:00
|
|
|
export packages=$(go list ./... | grep "github.com/dgraph-io/badger/v4/")
|
2020-01-15 15:10:34 +05:30
|
|
|
|
2020-11-11 13:02:30 -08:00
|
|
|
tags="-tags=jemalloc"
|
|
|
|
|
|
2022-11-03 17:50:45 -05:00
|
|
|
# Compile the Badger binary
|
2018-10-04 13:24:59 -07:00
|
|
|
pushd badger
|
2020-11-11 13:02:30 -08:00
|
|
|
go build -v $tags .
|
2018-10-04 13:24:59 -07:00
|
|
|
popd
|
|
|
|
|
|
2018-10-03 18:58:34 -07:00
|
|
|
# Run the memory intensive tests first.
|
2020-11-03 05:09:09 +05:30
|
|
|
manual() {
|
2025-12-10 17:11:18 -05:00
|
|
|
timeout="-timeout 5m"
|
2025-02-05 17:00:32 -05:00
|
|
|
echo "==> Running package tests for $packages"
|
|
|
|
|
set -e
|
2025-08-19 05:51:03 +00:00
|
|
|
go env -w GOTOOLCHAIN=go1.25.0+auto
|
2025-02-05 17:00:32 -05:00
|
|
|
for pkg in $packages; do
|
|
|
|
|
echo "===> Testing $pkg"
|
|
|
|
|
go test $tags -timeout=25m $covermode $coverprofile -failfast -race -parallel 16 $pkg && write_coverage || return 1
|
|
|
|
|
done
|
|
|
|
|
echo "==> DONE package tests"
|
2020-11-04 03:41:10 +05:30
|
|
|
|
2025-02-05 17:00:32 -05:00
|
|
|
echo "==> Running manual tests"
|
|
|
|
|
# Run the special Truncate test.
|
|
|
|
|
rm -rf p
|
|
|
|
|
set -e
|
|
|
|
|
go test $tags $timeout $covermode $coverprofile -run='TestTruncateVlogNoClose$' -failfast --manual=true && write_coverage || return 1
|
|
|
|
|
truncate --size=4096 p/000000.vlog
|
|
|
|
|
go test $tags $timeout $covermode $coverprofile -run='TestTruncateVlogNoClose2$' -failfast --manual=true && write_coverage || return 1
|
|
|
|
|
go test $tags $timeout $covermode $coverprofile -run='TestTruncateVlogNoClose3$' -failfast --manual=true && write_coverage || return 1
|
|
|
|
|
rm -rf p
|
2020-11-04 03:41:10 +05:30
|
|
|
|
2025-02-05 17:00:32 -05:00
|
|
|
# TODO(ibrahim): Let's make these tests have Manual prefix.
|
|
|
|
|
# go test $tags -run='TestManual' --manual=true --parallel=2
|
|
|
|
|
# TestWriteBatch
|
|
|
|
|
# TestValueGCManaged
|
|
|
|
|
# TestDropPrefix
|
|
|
|
|
# TestDropAllManaged
|
|
|
|
|
go test $tags $timeout $covermode $coverprofile -failfast -run='TestBigKeyValuePairs$' --manual=true && write_coverage || return 1
|
|
|
|
|
go test $tags $timeout $covermode $coverprofile -failfast -run='TestPushValueLogLimit' --manual=true && write_coverage || return 1
|
|
|
|
|
go test $tags $timeout $covermode $coverprofile -failfast -run='TestKeyCount' --manual=true && write_coverage || return 1
|
|
|
|
|
go test $tags $timeout $covermode $coverprofile -failfast -run='TestIteratePrefix' --manual=true && write_coverage || return 1
|
|
|
|
|
go test $tags $timeout $covermode $coverprofile -failfast -run='TestIterateParallel' --manual=true && write_coverage || return 1
|
|
|
|
|
go test $tags $timeout $covermode $coverprofile -failfast -run='TestBigStream' --manual=true && write_coverage || return 1
|
|
|
|
|
go test $tags $timeout $covermode $coverprofile -failfast -run='TestGoroutineLeak' --manual=true && write_coverage || return 1
|
|
|
|
|
go test $tags $timeout $covermode $coverprofile -failfast -run='TestGetMore' --manual=true && write_coverage || return 1
|
2020-11-04 03:41:10 +05:30
|
|
|
|
2025-02-05 17:00:32 -05:00
|
|
|
echo "==> DONE manual tests"
|
2020-11-03 05:09:09 +05:30
|
|
|
}
|
2020-01-15 15:10:34 +05:30
|
|
|
|
2020-11-03 05:09:09 +05:30
|
|
|
root() {
|
2025-02-05 17:00:32 -05:00
|
|
|
# Run the normal tests.
|
|
|
|
|
# go test -timeout=25m -v -race github.com/dgraph-io/badger/v4/...
|
2020-11-03 05:09:09 +05:30
|
|
|
|
2025-02-05 17:00:32 -05:00
|
|
|
echo "==> Running root level tests."
|
|
|
|
|
go test $tags -v -race -parallel=16 -timeout=25m -failfast $covermode $coverprofile . && write_coverage || return 1
|
|
|
|
|
echo "==> DONE root level tests"
|
2020-11-03 05:09:09 +05:30
|
|
|
}
|
|
|
|
|
|
2020-11-11 13:02:30 -08:00
|
|
|
stream() {
|
2025-02-05 17:00:32 -05:00
|
|
|
set -eo pipefail
|
|
|
|
|
pushd badger
|
|
|
|
|
baseDir=$(mktemp -d -p .)
|
|
|
|
|
./badger benchmark write -s --dir=$baseDir/test | tee $baseDir/log.txt
|
|
|
|
|
./badger benchmark read --dir=$baseDir/test --full-scan | tee --append $baseDir/log.txt
|
|
|
|
|
./badger benchmark read --dir=$baseDir/test -d=30s | tee --append $baseDir/log.txt
|
|
|
|
|
./badger stream --dir=$baseDir/test -o "$baseDir/test2" | tee --append $baseDir/log.txt
|
|
|
|
|
count=$(cat "$baseDir/log.txt" | grep "at program end: 0 B" | wc -l)
|
|
|
|
|
rm -rf $baseDir
|
|
|
|
|
if [ $count -ne 4 ]; then
|
|
|
|
|
echo "LEAK detected in Badger stream."
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
echo "==> DONE stream test"
|
|
|
|
|
popd
|
|
|
|
|
return 0
|
2020-11-11 13:02:30 -08:00
|
|
|
}
|
|
|
|
|
|
2022-11-03 17:50:45 -05:00
|
|
|
write_coverage() {
|
2025-02-05 17:00:32 -05:00
|
|
|
if [[ $CI == "true" ]]; then
|
|
|
|
|
if [[ -f cover_tmp.out ]]; then
|
|
|
|
|
sed -i '1d' cover_tmp.out
|
|
|
|
|
cat cover_tmp.out >>cover.out && rm cover_tmp.out
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
2022-11-03 17:50:45 -05:00
|
|
|
}
|
2020-11-03 05:09:09 +05:30
|
|
|
|
2022-11-03 17:50:45 -05:00
|
|
|
# parallel tests currently not working
|
|
|
|
|
# parallel --halt now,fail=1 --progress --line-buffer ::: stream manual root
|
|
|
|
|
# run tests in sequence
|
2025-12-15 22:56:42 +01:00
|
|
|
root
|
|
|
|
|
stream
|
2022-11-03 17:50:45 -05:00
|
|
|
manual
|