Skip to content

Commit

Permalink
Itest with race detector (#1329)
Browse files Browse the repository at this point in the history
* Itest with race detector

* Use one dockerfile for regular itests and itests with race.

* Add race dependencies to 'builder' stage of 'docker build'.
  • Loading branch information
nickeskov authored Feb 13, 2024
1 parent 24ad13d commit 6fb828a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/itests_race.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "ITestsWithRaceDetector"
on:
workflow_dispatch:
schedule:
- cron: '23 1-6 * * *'

jobs:
itest-race:
name: integration_tests_with_race_detector
runs-on: self-hosted
if: github.repository == 'wavesplatform/gowaves'

steps:
- name: Set up Go 1.21
uses: actions/setup-go@v5.0.0
with:
go-version: 1.21.x
check-latest: true
cache: true
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v4

- name: Get dependencies
run: go mod vendor

- name: Tests
run: make itest-race

- name: Upload itest logs
uses: actions/upload-artifact@v4
if: failure()
with:
name: itest_logs
path: build/logs/
if-no-files-found: warn
retention-days: 5
5 changes: 3 additions & 2 deletions Dockerfile.gowaves-it
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM golang:1.22.0-alpine3.19 as builder
LABEL wavesplatform-gowaves-itests-tmp=true
WORKDIR /app

RUN apk add --no-cache make
RUN apk add --no-cache make musl-dev gcc

COPY go.mod .
COPY go.sum .
Expand All @@ -13,7 +13,8 @@ COPY Makefile .
COPY cmd cmd
COPY pkg pkg

RUN make build-node-linux-amd64
ARG WITH_RACE_SUFFIX=""
RUN make build-node-linux-amd64${WITH_RACE_SUFFIX}

FROM alpine:3.19.1
ENV TZ=Etc/UTC \
Expand Down
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ itest:
mkdir -p build/logs
go test -timeout 40m -parallel 3 $$(go list ./... | grep "/itests")

itest-race:
mkdir -p build/config
mkdir -p build/logs
ITESTS_WITH_RACE_DETECTOR="true" go test -timeout 60m -parallel 3 $$(go list ./... | grep "/itests")

smoke:
mkdir -p build/config
mkdir -p build/logs
Expand Down Expand Up @@ -103,6 +108,8 @@ build-node-native:
@go build -o build/bin/native/node -ldflags="-X 'github.com/wavesplatform/gowaves/pkg/versioning.Version=$(VERSION)'" ./cmd/node
build-node-linux-amd64:
@CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o build/bin/linux-amd64/node -ldflags="-X 'github.com/wavesplatform/gowaves/pkg/versioning.Version=$(VERSION)'" ./cmd/node
build-node-linux-amd64-with-race:
@CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -race -o build/bin/linux-amd64/node -ldflags="-X 'github.com/wavesplatform/gowaves/pkg/versioning.Version=$(VERSION)'" ./cmd/node
build-node-linux-i386:
@CGO_ENABLED=0 GOOS=linux GOARCH=386 go build -o build/bin/linux-i386/node -ldflags="-X 'github.com/wavesplatform/gowaves/pkg/versioning.Version=$(VERSION)'" ./cmd/node
build-node-linux-arm:
Expand Down
24 changes: 20 additions & 4 deletions itests/init_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,45 @@ import (
)

const dockerfilePath = "./../Dockerfile.gowaves-it"
const keepDanglingEnvKey = "ITESTS_KEEP_DANGLING"
const (
keepDanglingEnvKey = "ITESTS_KEEP_DANGLING"
withRaceDetectorEnvKey = "ITESTS_WITH_RACE_DETECTOR"
)

const (
withRaceDetectorSuffixArgumentName = "WITH_RACE_SUFFIX"
withRaceDetectorSuffixArgumentValue = "-with-race"
)

func TestMain(m *testing.M) {
pwd, err := os.Getwd()
if err != nil {
log.Fatalf("Failed to get pwd: %v", err)
}
keepDangling := mustBoolEnv(keepDanglingEnvKey)

var (
keepDangling = mustBoolEnv(keepDanglingEnvKey)
withRaceDetector = mustBoolEnv(withRaceDetectorEnvKey)
)
pool, err := dockertest.NewPool("")
if err != nil {
log.Fatalf("Failed to create docker pool: %v", err)
}
if err := pool.Client.PullImage(dc.PullImageOptions{Repository: "wavesplatform/wavesnode", Tag: "latest"}, dc.AuthConfiguration{}); err != nil {
log.Fatalf("Failed to pull node image: %v", err)
}
var buildArgs []dc.BuildArg
if withRaceDetector {
buildArgs = append(buildArgs, dc.BuildArg{
Name: withRaceDetectorSuffixArgumentName, Value: withRaceDetectorSuffixArgumentValue,
})
}
dir, file := filepath.Split(filepath.Join(pwd, dockerfilePath))
err = pool.Client.BuildImage(dc.BuildImageOptions{
Name: "go-node",
Dockerfile: file,
ContextDir: dir,
OutputStream: io.Discard,
BuildArgs: nil,
BuildArgs: buildArgs,
Platform: "",
RmTmpContainer: true,
})
Expand Down

0 comments on commit 6fb828a

Please sign in to comment.