Skip to content

Commit 6243d07

Browse files
get full coverage check
1 parent 8a40ae8 commit 6243d07

File tree

1 file changed

+60
-30
lines changed

1 file changed

+60
-30
lines changed

test.sh

+60-30
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@ set -eo pipefail
44

55
go version
66

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+
716
# Run `go list` BEFORE setting GOFLAGS so that the output is in the right
817
# format for grep.
918
# export packages because the test will run in a sub process.
1019
export packages=$(go list ./... | grep "github.com/dgraph-io/badger/v3/")
1120

1221
tags="-tags=jemalloc"
1322

14-
# Ensure that we can compile the binary.
23+
# Compile the Badger binary
1524
pushd badger
16-
go build -v $tags .
25+
go build -v $tags .
1726
popd
1827

1928
# Run the memory intensive tests first.
@@ -23,18 +32,22 @@ manual() {
2332
set -e
2433
for pkg in $packages; do
2534
echo "===> Testing $pkg"
26-
go test $tags -timeout=25m -race $pkg -parallel 16
35+
go test $tags -timeout=25m $covermode $coverprofile -race -parallel 16 $pkg
36+
write_coverage
2737
done
2838
echo "==> DONE package tests"
2939

3040
echo "==> Running manual tests"
3141
# Run the special Truncate test.
3242
rm -rf p
3343
set -e
34-
go test $tags $timeout -run='TestTruncateVlogNoClose$' --manual=true
44+
go test $tags $timeout $covermode $coverprofile -run='TestTruncateVlogNoClose$' --manual=true
45+
write_coverage
3546
truncate --size=4096 p/000000.vlog
36-
go test $tags $timeout -run='TestTruncateVlogNoClose2$' --manual=true
37-
go test $tags $timeout -run='TestTruncateVlogNoClose3$' --manual=true
47+
go test $tags $timeout $covermode $coverprofile -run='TestTruncateVlogNoClose2$' --manual=true
48+
write_coverage
49+
go test $tags $timeout $covermode $coverprofile -run='TestTruncateVlogNoClose3$' --manual=true
50+
write_coverage
3851
rm -rf p
3952

4053
# TODO(ibrahim): Let's make these tests have Manual prefix.
@@ -43,14 +56,22 @@ manual() {
4356
# TestValueGCManaged
4457
# TestDropPrefix
4558
# TestDropAllManaged
46-
go test $tags $timeout -run='TestBigKeyValuePairs$' --manual=true
47-
go test $tags $timeout -run='TestPushValueLogLimit' --manual=true
48-
go test $tags $timeout -run='TestKeyCount' --manual=true
49-
go test $tags $timeout -run='TestIteratePrefix' --manual=true
50-
go test $tags $timeout -run='TestIterateParallel' --manual=true
51-
go test $tags $timeout -run='TestBigStream' --manual=true
52-
go test $tags $timeout -run='TestGoroutineLeak' --manual=true
53-
go test $tags $timeout -run='TestGetMore' --manual=true
59+
go test $tags $timeout $covermode $coverprofile -run='TestBigKeyValuePairs$' --manual=true
60+
write_coverage
61+
go test $tags $timeout $covermode $coverprofile -run='TestPushValueLogLimit' --manual=true
62+
write_coverage
63+
go test $tags $timeout $covermode $coverprofile -run='TestKeyCount' --manual=true
64+
write_coverage
65+
go test $tags $timeout $covermode $coverprofile -run='TestIteratePrefix' --manual=true
66+
write_coverage
67+
go test $tags $timeout $covermode $coverprofile -run='TestIterateParallel' --manual=true
68+
write_coverage
69+
go test $tags $timeout $covermode $coverprofile -run='TestBigStream' --manual=true
70+
write_coverage
71+
go test $tags $timeout $covermode $coverprofile -run='TestGoroutineLeak' --manual=true
72+
write_coverage
73+
go test $tags $timeout $covermode $coverprofile -run='TestGetMore' --manual=true
74+
write_coverage
5475

5576
echo "==> DONE manual tests"
5677
}
@@ -61,39 +82,48 @@ root() {
6182

6283
echo "==> Running root level tests."
6384
set -e
64-
go test $tags -v -race -parallel=16 -timeout=25m -covermode=atomic -coverprofile=cover_tmp.out .
65-
cat cover_tmp.out >> cover.out
85+
go test $tags -v -race -parallel=16 -timeout=25m $covermode $coverprofile .
86+
write_coverage
6687
echo "==> DONE root level tests"
6788
}
6889

6990
stream() {
7091
set -eo pipefail
7192
pushd badger
72-
baseDir=$(mktemp -d -p .)
73-
./badger benchmark write -s --dir=$baseDir/test | tee $baseDir/log.txt
74-
./badger benchmark read --dir=$baseDir/test --full-scan | tee --append $baseDir/log.txt
75-
./badger benchmark read --dir=$baseDir/test -d=30s | tee --append $baseDir/log.txt
76-
./badger stream --dir=$baseDir/test -o "$baseDir/test2" | tee --append $baseDir/log.txt
77-
count=$(cat "$baseDir/log.txt" | grep "at program end: 0 B" | wc -l)
78-
rm -rf $baseDir
79-
if [ $count -ne 4 ]; then
80-
echo "LEAK detected in Badger stream."
81-
return 1
82-
fi
83-
echo "==> DONE stream test"
93+
baseDir=$(mktemp -d -p .)
94+
./badger benchmark write -s --dir=$baseDir/test | tee $baseDir/log.txt
95+
./badger benchmark read --dir=$baseDir/test --full-scan | tee --append $baseDir/log.txt
96+
./badger benchmark read --dir=$baseDir/test -d=30s | tee --append $baseDir/log.txt
97+
./badger stream --dir=$baseDir/test -o "$baseDir/test2" | tee --append $baseDir/log.txt
98+
count=$(cat "$baseDir/log.txt" | grep "at program end: 0 B" | wc -l)
99+
rm -rf $baseDir
100+
if [ $count -ne 4 ]; then
101+
echo "LEAK detected in Badger stream."
102+
return 1
103+
fi
104+
echo "==> DONE stream test"
84105
popd
85106
return 0
86107
}
87108

109+
write_coverage() {
110+
if [ $CI = "true" ]; then
111+
if [ -f cover_tmp.out ]; then
112+
sed -i '1d' cover_tmp.out
113+
cat cover_tmp.out >> cover.out && rm cover_tmp.out
114+
fi
115+
fi
116+
117+
}
118+
88119
export -f stream
89120
export -f manual
90121
export -f root
122+
export -f write_coverage
91123

92124
# parallel tests currently not working
93125
# parallel --halt now,fail=1 --progress --line-buffer ::: stream manual root
94126

95-
touch cover.out
96-
97127
# run tests in sequence
98128
root
99129
stream

0 commit comments

Comments
 (0)