test.sh raw
1 #!/bin/bash
2
3 set -eo pipefail
4
5 go version
6
7 # Check if Github Actions is running
8 if [ $CI = "true" ]; then
9 # Enable code coverage
10 # export because tests run in a subprocess
11 export covermode="-covermode=atomic"
12 export coverprofile="-coverprofile=cover_tmp.out"
13 echo "mode: atomic" >>cover.out
14 fi
15
16 # Run `go list` BEFORE setting GOFLAGS so that the output is in the right
17 # format for grep.
18 # export packages because the test will run in a sub process.
19 export packages=$(go list ./... | grep "github.com/dgraph-io/badger/v4/")
20
21 tags="-tags=jemalloc"
22
23 # Compile the Badger binary
24 pushd badger
25 go build -v $tags .
26 popd
27
28 # Run the memory intensive tests first.
29 manual() {
30 timeout="-timeout 2m"
31 echo "==> Running package tests for $packages"
32 set -e
33 for pkg in $packages; do
34 echo "===> Testing $pkg"
35 go test $tags -timeout=25m $covermode $coverprofile -failfast -race -parallel 16 $pkg && write_coverage || return 1
36 done
37 echo "==> DONE package tests"
38
39 echo "==> Running manual tests"
40 # Run the special Truncate test.
41 rm -rf p
42 set -e
43 go test $tags $timeout $covermode $coverprofile -run='TestTruncateVlogNoClose$' -failfast --manual=true && write_coverage || return 1
44 truncate --size=4096 p/000000.vlog
45 go test $tags $timeout $covermode $coverprofile -run='TestTruncateVlogNoClose2$' -failfast --manual=true && write_coverage || return 1
46 go test $tags $timeout $covermode $coverprofile -run='TestTruncateVlogNoClose3$' -failfast --manual=true && write_coverage || return 1
47 rm -rf p
48
49 # TODO(ibrahim): Let's make these tests have Manual prefix.
50 # go test $tags -run='TestManual' --manual=true --parallel=2
51 # TestWriteBatch
52 # TestValueGCManaged
53 # TestDropPrefix
54 # TestDropAllManaged
55 go test $tags $timeout $covermode $coverprofile -failfast -run='TestBigKeyValuePairs$' --manual=true && write_coverage || return 1
56 go test $tags $timeout $covermode $coverprofile -failfast -run='TestPushValueLogLimit' --manual=true && write_coverage || return 1
57 go test $tags $timeout $covermode $coverprofile -failfast -run='TestKeyCount' --manual=true && write_coverage || return 1
58 go test $tags $timeout $covermode $coverprofile -failfast -run='TestIteratePrefix' --manual=true && write_coverage || return 1
59 go test $tags $timeout $covermode $coverprofile -failfast -run='TestIterateParallel' --manual=true && write_coverage || return 1
60 go test $tags $timeout $covermode $coverprofile -failfast -run='TestBigStream' --manual=true && write_coverage || return 1
61 go test $tags $timeout $covermode $coverprofile -failfast -run='TestGoroutineLeak' --manual=true && write_coverage || return 1
62 go test $tags $timeout $covermode $coverprofile -failfast -run='TestGetMore' --manual=true && write_coverage || return 1
63
64 echo "==> DONE manual tests"
65 }
66
67 root() {
68 # Run the normal tests.
69 # go test -timeout=25m -v -race github.com/dgraph-io/badger/v4/...
70
71 echo "==> Running root level tests."
72 go test $tags -v -race -parallel=16 -timeout=25m -failfast $covermode $coverprofile . && write_coverage || return 1
73 echo "==> DONE root level tests"
74 }
75
76 stream() {
77 set -eo pipefail
78 pushd badger
79 baseDir=$(mktemp -d -p .)
80 ./badger benchmark write -s --dir=$baseDir/test | tee $baseDir/log.txt
81 ./badger benchmark read --dir=$baseDir/test --full-scan | tee --append $baseDir/log.txt
82 ./badger benchmark read --dir=$baseDir/test -d=30s | tee --append $baseDir/log.txt
83 ./badger stream --dir=$baseDir/test -o "$baseDir/test2" | tee --append $baseDir/log.txt
84 count=$(cat "$baseDir/log.txt" | grep "at program end: 0 B" | wc -l)
85 rm -rf $baseDir
86 if [ $count -ne 4 ]; then
87 echo "LEAK detected in Badger stream."
88 return 1
89 fi
90 echo "==> DONE stream test"
91 popd
92 return 0
93 }
94
95 write_coverage() {
96 if [[ $CI == "true" ]]; then
97 if [[ -f cover_tmp.out ]]; then
98 sed -i '1d' cover_tmp.out
99 cat cover_tmp.out >>cover.out && rm cover_tmp.out
100 fi
101 fi
102
103 }
104
105 # parallel tests currently not working
106 # parallel --halt now,fail=1 --progress --line-buffer ::: stream manual root
107 # run tests in sequence
108 root
109 stream
110 manual
111