test.sh 3.9 KB

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