-
Notifications
You must be signed in to change notification settings - Fork 660
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix data race on tx.Stats #373
Changes from all commits
27ac0b8
99a93a6
f8fa364
5104c82
4e98e8f
b7f2da4
dd4458c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,89 @@ | ||
name: Tests | ||
on: [push, pull_request] | ||
jobs: | ||
test: | ||
test-linux: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ubuntu-latest, windows-latest] | ||
runs-on: ${{ matrix.os }} | ||
target: | ||
- linux-amd64-unit-test-4-cpu | ||
- linux-amd64-unit-test-4-cpu-freelist-hashmap-race | ||
- linux-amd64-unit-test-2-cpu-freelist-array-short-race | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: "1.17.13" | ||
- run: make fmt | ||
- run: make race | ||
- run: make test | ||
- env: | ||
TARGET: ${{ matrix.target }} | ||
run: | | ||
case "${TARGET}" in | ||
linux-amd64-unit-test-4-cpu) | ||
CPU=4 make test | ||
;; | ||
linux-amd64-unit-test-4-cpu-freelist-hashmap-race) | ||
CPU=4 ENABLE_RACE=true make test-freelist-hashmap | ||
;; | ||
linux-amd64-unit-test-2-cpu-freelist-array-short-race) | ||
CPU=2 ENABLE_RACE=true EXTRA_TESTFLAGS="-short" make test-freelist-array | ||
;; | ||
*) | ||
echo "Failed to find target" | ||
exit 1 | ||
;; | ||
esac | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@0ad9a0988b3973e851ab0a07adf248ec2e100376 # v3.3.1 | ||
|
||
test-windows: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
target: | ||
- windows-amd64-unit-test-4-cpu | ||
# FIXME(fuweid): | ||
# | ||
# The windows will throws the following error when enable race. | ||
# We skip it until we have solution. | ||
# | ||
# ThreadSanitizer failed to allocate 0x000200000000 (8589934592) bytes at 0x0400c0000000 (error code: 1455) | ||
# | ||
#- windows-amd64-unit-test-4-cpu-race | ||
runs-on: windows-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: "1.17.13" | ||
- run: make fmt | ||
- env: | ||
TARGET: ${{ matrix.target }} | ||
run: | | ||
case "${TARGET}" in | ||
windows-amd64-unit-test-4-cpu) | ||
CPU=4 make test | ||
;; | ||
*) | ||
echo "Failed to find target" | ||
exit 1 | ||
;; | ||
esac | ||
shell: bash | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@0ad9a0988b3973e851ab0a07adf248ec2e100376 # v3.3.1 | ||
|
||
coverage: | ||
needs: ["test-linux", "test-windows"] | ||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: "1.17.13" | ||
- run: make coverage | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,6 @@ | |
*.swp | ||
/bin/ | ||
cover.out | ||
cover-*.out | ||
/.idea | ||
*.iml |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,24 +2,42 @@ 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) $(EXTRA_TESTFLAGS) | ||
|
||
fmt: | ||
!(gofmt -l -s -d $(shell find . -name \*.go) | grep '[a-z]') | ||
|
||
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 | ||
test: test-freelist-hashmap test-freelist-array | ||
|
||
test-freelist-hashmap: | ||
@echo "hashmap freelist test" | ||
TEST_FREELIST_TYPE=hashmap go test -v ${TESTFLAGS} -timeout 30m | ||
TEST_FREELIST_TYPE=hashmap go test -v ${TESTFLAGS} ./cmd/bbolt | ||
|
||
test-freelist-array: | ||
@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 | ||
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: race fmt test lint | ||
.PHONY: fmt test test-freelist-hashmap test-freelist-array lint | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now it's still redundant... test resolves to both: test-freelist-{...} targets. And no race run by default at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried this combination in action and 75% successful rate for the race matrix 😂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me add the following matrix in the follow-up pr.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better we have the following three targets to cover the no-race cases:
Of course, it can be addressed in a separate PR if there is no any objection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do!