diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index c2b79aa..297da2a 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -3,8 +3,13 @@ on: [push, pull_request] jobs: test: strategy: + fail-fast: false matrix: os: [ubuntu-latest, windows-latest] + target: + - unit-test-2-cpu + - unit-test-4-cpu + - unit-test-4-cpu-race runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3 @@ -12,7 +17,28 @@ jobs: with: go-version: "1.17.13" - run: make fmt - - run: make race - - run: make test + - env: + TARGET: ${{ matrix.target }} + run: | + case "${TARGET}" in + unit-test-2-cpu) + CPU=2 make test-simulate + CPU=2 make test + ;; + unit-test-4-cpu) + CPU=4 make test-simulate + CPU=4 make test + ;; + unit-test-4-cpu-race) + CPU=4 ENABLE_RACE=true make test-simulate + CPU=4 ENABLE_RACE=true make test + ;; + *) + echo "Failed to find target" + exit 1 + ;; + esac + shell: bash + - run: make coverage - name: golangci-lint uses: golangci/golangci-lint-action@0ad9a0988b3973e851ab0a07adf248ec2e100376 # v3.3.1 diff --git a/.gitignore b/.gitignore index 18312f0..cca8d2b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ *.swp /bin/ cover.out +cover-*.out /.idea *.iml diff --git a/Makefile b/Makefile index 67e3390..c5256eb 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,17 @@ BRANCH=`git rev-parse --abbrev-ref HEAD` COMMIT=`git rev-parse --short HEAD` GOLDFLAGS="-X main.branch $(BRANCH) -X main.commit $(COMMIT)" -race: - @TEST_FREELIST_TYPE=hashmap go test -v -race -test.run="TestSimulate_(100op|1000op)" - @echo "array freelist test" - @TEST_FREELIST_TYPE=array go test -v -race -test.run="TestSimulate_(100op|1000op)" +TESTFLAGS_RACE=-race=false +ifdef ENABLE_RACE + TESTFLAGS_RACE=-race=true +endif + +TESTFLAGS_CPU= +ifdef CPU + TESTFLAGS_CPU=-cpu=$(CPU) +endif + +TESTFLAGS = $(TESTFLAGS_RACE) $(TESTFLAGS_CPU) fmt: !(gofmt -l -s -d $(shell find . -name \*.go) | grep '[a-z]') @@ -14,12 +21,28 @@ lint: golangci-lint run ./... test: - TEST_FREELIST_TYPE=hashmap go test -timeout 30m -v -coverprofile cover.out -covermode atomic - TEST_FREELIST_TYPE=hashmap go test -v ./cmd/bbolt + @echo "hashmap freelist test" + TEST_FREELIST_TYPE=hashmap go test -v ${TESTFLAGS} -timeout 30m + TEST_FREELIST_TYPE=hashmap go test -v ${TESTFLAGS} ./cmd/bbolt @echo "array freelist test" + TEST_FREELIST_TYPE=array go test -v ${TESTFLAGS} -timeout 30m + TEST_FREELIST_TYPE=array go test -v ${TESTFLAGS} ./cmd/bbolt - @TEST_FREELIST_TYPE=array go test -timeout 30m -v -coverprofile cover.out -covermode atomic - @TEST_FREELIST_TYPE=array go test -v ./cmd/bbolt +test-simulate: + @echo "hashmap freelist test" + TEST_FREELIST_TYPE=hashmap go test -v ${TESTFLAGS} -test.run="TestSimulate_(100op|1000op)" -.PHONY: race fmt test lint + @echo "array freelist test" + TEST_FREELIST_TYPE=array go test -v ${TESTFLAGS} -test.run="TestSimulate_(100op|1000op)" + +coverage: + @echo "hashmap freelist test" + TEST_FREELIST_TYPE=hashmap go test -v -timeout 30m \ + -coverprofile cover-freelist-hashmap.out -covermode atomic + + @echo "array freelist test" + TEST_FREELIST_TYPE=array go test -v -timeout 30m \ + -coverprofile cover-freelist-array.out -covermode atomic + +.PHONY: fmt test test-simulate lint