From cd9ddc3ae1c0d5a1d5c76cafbecf8e2cf857f30d Mon Sep 17 00:00:00 2001 From: Joshua Goldstein <92491720+joshua-goldstein@users.noreply.github.com> Date: Thu, 13 Oct 2022 13:51:37 -0500 Subject: [PATCH] fix(CI): fix test suite and add CI steps (#1808) ## Problem Badger tests are run through a bash script called test.sh. It is currently not working, and there are no CI workflows on the Badger repository. ## Solution We update test.sh and add CI workflow steps. Test suite now works for Linux and Mac (x86, M1). To run the test suite, simply run `make test`. If you are on Mac, see remark below. ### Why a Makefile? Badger depends on jemalloc for efficient memory allocation (see [here](https://dgraph.io/blog/post/manual-memory-management-golang-jemalloc/), and z package in Ristretto). While Badger can be built without jemalloc, many users will probably want to benefit from it. The makefile makes it easy to install the jemalloc dependency with `make jemalloc`. Also now the test.sh script contains only test related functionality. This also has the advantage that now the CI workflow only needs essentially two steps: ``` make dependency make test ``` ### Remarks - In pb/gen.sh, `go get` is [deprecated](https://go.dev/doc/go-get-install-deprecation) as a way to retrieve and install an executable into our $GOBIN, which is what we want to do here. We use `go install` instead. - In test.sh, Teamcity flags no longer needed - In test.sh, Installjemalloc no longer needed as it is in the Makefile, simplifying the test script - In test.sh, tests are now run sequentially and not in parallel (currently broken) - We remove .travisci because it is unused - Important note for Mac users: for historical reasons, certain tools on MacOS are different from the standard GNU tools everyone else uses. One of these is the `mktemp` command, which is used in the test suite. In order to get the GNU version of this tool, you can run: ``` brew install coreutils export PATH="$(brew --prefix)/opt/coreutils/libexec/gnubin:$PATH" make test ``` This will temporarily modify your path so that the GNU version of mktemp is called in the script. Without this fix the script will complain that it doesn't recognize the p flag in `mktemp -d -p .` #### To-do - tune lint tests - add code coverage - potentially add build target for badger in makefile - bring test suite to parity with [old teamcity setup](https://teamcity.dgraph.io/project.html?projectId=Badger) - prune dependencies --- .github/workflows/ci-badger-bank-tests.yml | 36 ++++++++++++++ .github/workflows/ci-badger-tests.yml | 29 ++++++++++++ .github/workflows/ci-golang-lint.yml | 27 +++++++++++ .go-version | 1 + .travis.yml | 48 ------------------- Makefile | 55 ++++++++++++++++++++++ pb/gen.sh | 3 +- test.sh | 39 ++++----------- 8 files changed, 157 insertions(+), 81 deletions(-) create mode 100644 .github/workflows/ci-badger-bank-tests.yml create mode 100644 .github/workflows/ci-badger-tests.yml create mode 100644 .github/workflows/ci-golang-lint.yml create mode 100644 .go-version delete mode 100644 .travis.yml create mode 100644 Makefile diff --git a/.github/workflows/ci-badger-bank-tests.yml b/.github/workflows/ci-badger-bank-tests.yml new file mode 100644 index 000000000..be7c0f231 --- /dev/null +++ b/.github/workflows/ci-badger-bank-tests.yml @@ -0,0 +1,36 @@ +name: ci-badger-bank-tests +on: + push: + branches: + - main + pull_request: + branches: + - main + schedule: + - cron: "*/30 * * * *" +jobs: + badger-bank: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Get Go Version + run: | + #!/bin/bash + DEFAULT_VERSION="1.18" + GOVERSION=$({ [ -f .go-version ] && cat .go-version; } || echo $DEFAULT_VERSION) + echo "GOVERSION=$GOVERSION" >> $GITHUB_ENV + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GOVERSION }} + - name: Install Dependencies + run: make dependency + - name: Install jemalloc + run: make jemalloc + - name: Install Badger + run: cd badger && go install --race --tags=jemalloc . + - name: Run Badger Bank Test + run: | + #!/bin/bash + mkdir bank && cd bank + badger bank test -v --dir=. -d=20m diff --git a/.github/workflows/ci-badger-tests.yml b/.github/workflows/ci-badger-tests.yml new file mode 100644 index 000000000..9cb4f201a --- /dev/null +++ b/.github/workflows/ci-badger-tests.yml @@ -0,0 +1,29 @@ +name: ci-badger-tests +on: + push: + branches: + - main + pull_request: + branches: + - main + schedule: + - cron: "*/30 * * * *" +jobs: + badger-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Get Go Version + run: | + #!/bin/bash + DEFAULT_VERSION="1.18" + GOVERSION=$({ [ -f .go-version ] && cat .go-version; } || echo $DEFAULT_VERSION) + echo "GOVERSION=$GOVERSION" >> $GITHUB_ENV + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version: ${{ env.GOVERSION }} + - name: Install Dependencies + run: make dependency + - name: Run Badger Tests + run: make test diff --git a/.github/workflows/ci-golang-lint.yml b/.github/workflows/ci-golang-lint.yml new file mode 100644 index 000000000..be39c7a08 --- /dev/null +++ b/.github/workflows/ci-golang-lint.yml @@ -0,0 +1,27 @@ +name: ci-golang-lint +on: + push: + branches: + - main + pull_request: + branches: + - main + schedule: + - cron: "*/30 * * * *" +jobs: + go-lint: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: golang-lint + env: + # prevent OOM + GOGC: 10 + uses: golangci/golangci-lint-action@v2 + with: + # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. + version: v1.36 + only-new-issues: true + args: --timeout=10m + skip-go-installation: true diff --git a/.go-version b/.go-version new file mode 100644 index 000000000..adc97d8e2 --- /dev/null +++ b/.go-version @@ -0,0 +1 @@ +1.18 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b671868f3..000000000 --- a/.travis.yml +++ /dev/null @@ -1,48 +0,0 @@ -language: go - -go: - - "1.12" - - "1.13" - - tip -os: - - osx -env: - jobs: - - GOARCH=386 - - GOARCH=amd64 - global: - - secure: CRkV2+/jlO0gXzzS50XGxfMS117FNwiVjxNY/LeWq06RKD+dDCPxTJl3JCNe3l0cYEPAglV2uMMYukDiTqJ7e+HI4nh4N4mv6lwx39N8dAvJe1x5ITS2T4qk4kTjuQb1Q1vw/ZOxoQqmvNKj2uRmBdJ/HHmysbRJ1OzCWML3OXdUwJf0AYlJzTjpMfkOKr7sTtE4rwyyQtd4tKH1fGdurgI9ZuFd9qvYxK2qcJhsQ6CNqMXt+7FkVkN1rIPmofjjBTNryzUr4COFXuWH95aDAif19DeBW4lbNgo1+FpDsrgmqtuhl6NAuptI8q/imow2KXBYJ8JPXsxW8DVFj0IIp0RCd3GjaEnwBEbxAyiIHLfW7AudyTS/dJOvZffPqXnuJ8xj3OPIdNe4xY0hWl8Ju2HhKfLOAHq7VadHZWd3IHLil70EiL4/JLD1rNbMImUZisFaA8pyrcIvYYebjOnk4TscwKFLedClRSX1XsMjWWd0oykQtrdkHM2IxknnBpaLu7mFnfE07f6dkG0nlpyu4SCLey7hr5FdcEmljA0nIxTSYDg6035fQkBEAbe7hlESOekkVNT9IZPwG+lmt3vU4ofi6NqNbJecOuSB+h36IiZ9s4YQtxYNnLgW14zjuFGGyT5smc3IjBT7qngDjKIgyrSVoRkY/8udy9qbUgvBeW8= - - -jobs: - allow_failures: - - go: tip - exclude: - # Exclude builds for 386 architecture on go 1.12 and tip - # Since we don't want it to run for 32 bit - - go: "1.12" - env: GOARCH=386 - - go: tip - env: GOARCH=386 - include: - # Define one extra linux build, which we use to run cross - # compiled 32 bit tests - - os: linux - arch: arm64 - go: "1.14" - env: go_32=yes - -notifications: - email: false - slack: - secure: X7uBLWYbuUhf8QFE16CoS5z7WvFR8EN9j6cEectMW6mKZ3vwXGwVXRIPsgUq/606DsQdCCx34MR8MRWYGlu6TBolbSe9y0EP0i46yipPz22YtuT7umcVUbGEyx8MZKgG0v1u/zA0O4aCsOBpGAA3gxz8h3JlEHDt+hv6U8xRsSllVLzLSNb5lwxDtcfEDxVVqP47GMEgjLPM28Pyt5qwjk7o5a4YSVzkfdxBXxd3gWzFUWzJ5E3cTacli50dK4GVfiLcQY2aQYoYO7AAvDnvP+TPfjDkBlUEE4MUz5CDIN51Xb+WW33sX7g+r3Bj7V5IRcF973RiYkpEh+3eoiPnyWyxhDZBYilty3b+Hysp6d4Ov/3I3ll7Bcny5+cYjakjkMH3l9w3gs6Y82GlpSLSJshKWS8vPRsxFe0Pstj6QSJXTd9EBaFr+l1ScXjJv/Sya9j8N9FfTuOTESWuaL1auX4Y7zEEVHlA8SCNOO8K0eTfxGZnC/YcIHsR8rePEAcFxfOYQppkyLF/XvAtnb/LMUuu0g4y2qNdme6Oelvyar1tFEMRtbl4mRCdu/krXBFtkrsfUaVY6WTPdvXAGotsFJ0wuA53zGVhlcd3+xAlSlR3c1QX95HIMeivJKb5L4nTjP+xnrmQNtnVk+tG4LSH2ltuwcZSSczModtcBmRefrk= - -script: >- - if [ $TRAVIS_OS_NAME = "linux" ] && [ $go_32 ]; then - uname -a - GOOS=linux GOARCH=arm go test -v ./... - else - go test -v ./... - # Cross-compile for Plan 9 - GOOS=plan9 go build ./... - fi diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..070b66afa --- /dev/null +++ b/Makefile @@ -0,0 +1,55 @@ +# +# Copyright 2022 Dgraph Labs, Inc. and Contributors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +USER_ID = $(shell id -u) +HAS_JEMALLOC = $(shell test -f /usr/local/lib/libjemalloc.a && echo "jemalloc") +JEMALLOC_URL = "https://github.com/jemalloc/jemalloc/releases/download/5.2.1/jemalloc-5.2.1.tar.bz2" + + +.PHONY: all test jemalloc dependency + +test: jemalloc + @echo "Running Badger tests..." + @./test.sh + +jemalloc: + @if [ -z "$(HAS_JEMALLOC)" ] ; then \ + mkdir -p /tmp/jemalloc-temp && cd /tmp/jemalloc-temp ; \ + echo "Downloading jemalloc..." ; \ + curl -s -L ${JEMALLOC_URL} -o jemalloc.tar.bz2 ; \ + tar xjf ./jemalloc.tar.bz2 ; \ + cd jemalloc-5.2.1 ; \ + ./configure --with-jemalloc-prefix='je_' --with-malloc-conf='background_thread:true,metadata_thp:auto'; \ + make ; \ + if [ "$(USER_ID)" -eq "0" ]; then \ + make install ; \ + else \ + echo "==== Need sudo access to install jemalloc" ; \ + sudo make install ; \ + fi \ + fi + +dependency: + @echo "Installing dependencies..." + @sudo apt-get update + @sudo apt-get -y upgrade + @sudo apt-get -y install \ + ca-certificates \ + curl \ + gnupg \ + lsb-release \ + build-essential \ + protobuf-compiler \ diff --git a/pb/gen.sh b/pb/gen.sh index e41208c9d..68679a268 100755 --- a/pb/gen.sh +++ b/pb/gen.sh @@ -3,6 +3,5 @@ # Run this script from its directory, so that badgerpb2.proto is where it's expected to # be. -# You might need to go get -v github.com/gogo/protobuf/... -go get -v github.com/gogo/protobuf/protoc-gen-gogofaster +go install github.com/gogo/protobuf/protoc-gen-gogofaster@latest protoc --gogofaster_out=. --gogofaster_opt=paths=source_relative -I=. badgerpb3.proto diff --git a/test.sh b/test.sh index 6922eed0b..be918aa1f 100755 --- a/test.sh +++ b/test.sh @@ -9,33 +9,6 @@ go version # export packages because the test will run in a sub process. export packages=$(go list ./... | grep "github.com/dgraph-io/badger/v3/") -if [[ ! -z "$TEAMCITY_VERSION" ]]; then - export GOFLAGS="-json" -fi - -function InstallJemalloc() { - pushd . - if [ ! -f /usr/local/lib/libjemalloc.a ]; then - USER_ID=`id -u` - JEMALLOC_URL="https://github.com/jemalloc/jemalloc/releases/download/5.2.1/jemalloc-5.2.1.tar.bz2" - - mkdir -p /tmp/jemalloc-temp && cd /tmp/jemalloc-temp ; - echo "Downloading jemalloc" ; - curl -s -L ${JEMALLOC_URL} -o jemalloc.tar.bz2 ; - tar xjf ./jemalloc.tar.bz2 ; - cd jemalloc-5.2.1 ; - ./configure --with-jemalloc-prefix='je_' ; - make ; - if [ "$USER_ID" -eq "0" ]; then - make install ; - else - echo "==== Need sudo access to install jemalloc" ; - sudo make install ; - fi - fi - popd -} - tags="-tags=jemalloc" # Ensure that we can compile the binary. @@ -43,9 +16,6 @@ pushd badger go build -v $tags . popd -# tags="" -InstallJemalloc - # Run the memory intensive tests first. manual() { timeout="-timeout 2m" @@ -110,6 +80,7 @@ stream() { return 1 fi echo "==> DONE stream test" + popd return 0 } @@ -117,4 +88,10 @@ export -f stream export -f manual export -f root -parallel --halt now,fail=1 --progress --line-buffer ::: stream manual root +# parallel tests currently not working +# parallel --halt now,fail=1 --progress --line-buffer ::: stream manual root + +# run tests in sequence +root +stream +manual