Commit 99472a8f authored by Alessio Caiazza's avatar Alessio Caiazza

Merge branch 'improve-unit-tests-output' into 'master'

Add coverage report for unit tests

See merge request gitlab-org/gitlab-runner!928
parents e7179829 43017968
Pipeline #27004995 passed with stages
in 27 minutes and 45 seconds
......@@ -17,5 +17,11 @@ artifacts
tmp/gitlab-test
/.gopath/
testsdefinitions.txt
/.testoutput/
/.cover/
codeclimate.json
# Ignore the generated binary
/gitlab-runner
......@@ -2,6 +2,7 @@ stages:
- prepare
- prebuild
- test
- coverage
- build
- package
- release
......@@ -29,7 +30,7 @@ image: $CI_IMAGE
- docker:dind
variables: &docker_variables
CI_IMAGE: registry.gitlab.com/gitlab-org/gitlab-runner/ci:1.8.7-0
DOCKER_DRIVER: overlay
DOCKER_DRIVER: overlay2
DOCKER_HOST: tcp://docker:2375
tags:
- docker
......@@ -135,6 +136,24 @@ review-docs-cleanup:
script:
- ./trigger-build-docs cleanup
tests definitions:
stage: prebuild
# Using Go 1.10, because the `go test -list` is unavailable in <1.9
# and it's much faster in 1.10. And since there is no real test execution
# in this step, the version difference doesn't matter
image: golang:1.10
script:
- apt update
- apt install make
- source ci/touch_make_dependencies
- make parallel_test_prepare
artifacts:
paths:
- testsdefinitions.txt
expire_in: 7d
tags:
- gitlab-org
#
# Test stage
#
......@@ -154,26 +173,43 @@ code_quality:
- ./scripts/codequality analyze -f json --dev | tee gl-code-quality-report.json
artifacts:
paths: [gl-code-quality-report.json]
expire_in: 1 week
expire_in: 7d
unit tests (no race):
.unit_tests: &unit_tests
<<: *docker
stage: test
retry: 2
script:
- JOB_NAME=( $CI_JOB_NAME )
- export SUITE_INDEX=${JOB_NAME[-2]}
- export SUITE_TOTAL=${JOB_NAME[-1]}
- source ci/touch_make_dependencies
- docker pull alpine
- docker pull docker:dind
- docker pull docker:git
- make test
- make parallel_test_execute
artifacts:
paths:
- .cover/*
- .testoutput/*
when: always
expire_in: 7d
unit tests:
<<: *docker
stage: test
.unit_tests_with_race: &unit_tests_with_race
<<: *unit_tests
allow_failure: true
script:
- source ci/touch_make_dependencies
- CGO_ENABLED=1 TESTFLAGS="-cover -race" make test
variables:
<<: *docker_variables
CGO_ENABLED: "1"
TESTFLAGS: "-cover -race"
unit tests 0 5: *unit_tests
unit tests 1 5: *unit_tests
unit tests 2 5: *unit_tests
unit tests 3 5: *unit_tests
unit tests 4 5: *unit_tests
unit tests with race 0 5: *unit_tests_with_race
unit tests with race 1 5: *unit_tests_with_race
unit tests with race 2 5: *unit_tests_with_race
unit tests with race 3 5: *unit_tests_with_race
unit tests with race 4 5: *unit_tests_with_race
docs check links:
image: "registry.gitlab.com/gitlab-org/gitlab-build-images:nanoc-bootstrap-ruby-2.4-alpine"
......@@ -213,13 +249,6 @@ integration windows:
- integration
- windows
race conditions detector:
<<: *docker
stage: test
script:
- source ci/touch_make_dependencies
- make check_race_conditions
git 1.7.1:
<<: *except_docs
image: centos:6
......@@ -238,6 +267,30 @@ git 1.7.1:
script:
- make test
#
# Coverage stage
#
test coverage report: &test_coverage_report
stage: coverage
image: golang:1.10
coverage: /regular total:\s+\(statements\)\s+\d+.\d+\%/
script:
- source ci/touch_make_dependencies
- make parallel_test_coverage_report
- make parallel_test_coverage_report TESTFLAGS="-cover -race"
artifacts:
paths:
- out/coverage/*
expire_in: 7d
race conditions detector:
stage: coverage
image: golang:1.10
script:
- source ci/touch_make_dependencies
- make check_race_conditions
#
# Build stage
#
......@@ -254,7 +307,7 @@ git 1.7.1:
- out/binaries/
expire_in: 7d
tags:
- docker
- gitlab-org
binaries darwin/386 darwin/amd64: *binaries
binaries freebsd/386 freebsd/amd64 freebsd/arm: *binaries
......@@ -287,7 +340,7 @@ binaries windows/386 windows/amd64: *binaries
- out/rpm/
expire_in: 7d
tags:
- docker
- gitlab-org
package-deb: *packages
package-rpm: *packages
......
......@@ -4,7 +4,7 @@ export VERSION := $(shell ./ci/version)
REVISION := $(shell git rev-parse --short=8 HEAD || echo unknown)
BRANCH := $(shell git show-ref | grep "$(REVISION)" | grep -v HEAD | awk '{print $$2}' | sed 's|refs/remotes/origin/||' | sed 's|refs/heads/||' | sort | head -n 1)
BUILT := $(shell date +%Y-%m-%dT%H:%M:%S%:z)
TESTFLAGS ?= -cover
export TESTFLAGS ?= -cover
LATEST_STABLE_TAG := $(shell git -c versionsort.prereleaseSuffix="-rc" -c versionsort.prereleaseSuffix="-RC" tag -l "v*.*.*" --sort=-v:refname | awk '!/rc/' | head -n 1)
export IS_LATEST :=
......@@ -45,7 +45,7 @@ export PATH := $(GOPATH_BIN):$(PATH)
# Packages in vendor/ are included in ./...
# https://github.com/golang/go/issues/11659
OUR_PACKAGES ?= $(subst _$(BUILD_DIR),$(PKG),$(shell go list ./... | grep -v '/vendor/'))
export OUR_PACKAGES ?= $(subst _$(BUILD_DIR),$(PKG),$(shell go list ./... | grep -v '/vendor/'))
GO_LDFLAGS ?= -X $(COMMON_PACKAGE_NAMESPACE).NAME=$(PACKAGE_NAME) -X $(COMMON_PACKAGE_NAMESPACE).VERSION=$(VERSION) \
-X $(COMMON_PACKAGE_NAMESPACE).REVISION=$(REVISION) -X $(COMMON_PACKAGE_NAMESPACE).BUILT=$(BUILT) \
......@@ -125,6 +125,22 @@ test: $(PKG_BUILD_DIR) docker
# Running tests...
go test $(OUR_PACKAGES) $(TESTFLAGS)
parallel_test_prepare: $(GOPATH_SETUP)
# Preparing test commands
@./scripts/go_test_with_coverage_report prepare
parallel_test_execute: $(GOPATH_SETUP) pull_images_for_tests
# executing tests
@./scripts/go_test_with_coverage_report execute
parallel_test_coverage_report: $(GOPATH_SETUP)
# Preparing coverage report
@./scripts/go_test_with_coverage_report coverage
pull_images_for_tests: $(GOPATH_SETUP)
# Pulling images required for some tests
@go run ./scripts/pull-images-for-tests/main.go
install:
go install --ldflags="$(GO_LDFLAGS)" $(PKG)
......
......@@ -27,3 +27,10 @@ const DefaultCacheRequestTimeout = 10
const DefaultNetworkClientTimeout = 60 * time.Minute
var PreparationRetryInterval = 3 * time.Second
const (
TestAlpineImage = "alpine:3.7"
TestAlpineNoRootImage = "registry.gitlab.com/gitlab-org/gitlab-runner/alpine-no-root:latest"
TestDockerDindImage = "docker:18-dind"
TestDockerGitImage = "docker:18-git"
)
......@@ -35,7 +35,7 @@ func TestDockerCommandSuccessRun(t *testing.T) {
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "alpine",
Image: common.TestAlpineImage,
PullPolicy: common.PullPolicyIfNotPresent,
},
},
......@@ -54,13 +54,15 @@ func TestDockerCommandNoRootImage(t *testing.T) {
successfulBuild, err := common.GetRemoteSuccessfulBuildWithDumpedVariables()
assert.NoError(t, err)
successfulBuild.Image.Name = "registry.gitlab.com/gitlab-org/gitlab-runner/alpine-no-root"
successfulBuild.Image.Name = common.TestAlpineNoRootImage
build := &common.Build{
JobResponse: successfulBuild,
Runner: &common.RunnerConfig{
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{},
Docker: &common.DockerConfig{
PullPolicy: common.PullPolicyIfNotPresent,
},
},
},
}
......@@ -82,7 +84,7 @@ func TestDockerCommandBuildFail(t *testing.T) {
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "alpine",
Image: common.TestAlpineImage,
PullPolicy: common.PullPolicyIfNotPresent,
},
},
......@@ -104,12 +106,12 @@ func TestDockerCommandWithAllowedImagesRun(t *testing.T) {
successfulBuild.Image = common.Image{Name: "$IMAGE_NAME"}
successfulBuild.Variables = append(successfulBuild.Variables, common.JobVariable{
Key: "IMAGE_NAME",
Value: "alpine",
Value: common.TestAlpineImage,
Public: true,
Internal: false,
File: false,
})
successfulBuild.Services = append(successfulBuild.Services, common.Image{Name: "docker:dind"})
successfulBuild.Services = append(successfulBuild.Services, common.Image{Name: common.TestDockerDindImage})
assert.NoError(t, err)
build := &common.Build{
JobResponse: successfulBuild,
......@@ -117,9 +119,10 @@ func TestDockerCommandWithAllowedImagesRun(t *testing.T) {
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
AllowedImages: []string{"alpine"},
AllowedServices: []string{"docker:dind"},
AllowedImages: []string{common.TestAlpineImage},
AllowedServices: []string{common.TestDockerDindImage},
Privileged: true,
PullPolicy: common.PullPolicyIfNotPresent,
},
},
},
......@@ -209,7 +212,7 @@ func TestDockerCommandBuildAbort(t *testing.T) {
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "alpine",
Image: common.TestAlpineImage,
PullPolicy: common.PullPolicyIfNotPresent,
},
},
......@@ -246,7 +249,7 @@ func TestDockerCommandBuildCancel(t *testing.T) {
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "alpine",
Image: common.TestAlpineImage,
PullPolicy: common.PullPolicyIfNotPresent,
},
},
......@@ -279,8 +282,8 @@ func TestDockerCommandTwoServicesFromOneImage(t *testing.T) {
successfulBuild, err := common.GetRemoteSuccessfulBuild()
successfulBuild.Services = common.Services{
{Name: "alpine", Alias: "service-1"},
{Name: "alpine", Alias: "service-2"},
{Name: common.TestAlpineImage, Alias: "service-1"},
{Name: common.TestAlpineImage, Alias: "service-2"},
}
assert.NoError(t, err)
build := &common.Build{
......@@ -289,7 +292,7 @@ func TestDockerCommandTwoServicesFromOneImage(t *testing.T) {
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "alpine",
Image: common.TestAlpineImage,
PullPolicy: common.PullPolicyIfNotPresent,
},
},
......@@ -320,7 +323,7 @@ func TestDockerCommandOutput(t *testing.T) {
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "alpine",
Image: common.TestAlpineImage,
PullPolicy: common.PullPolicyIfNotPresent,
},
},
......@@ -363,7 +366,7 @@ func TestDockerPrivilegedServiceAccessingBuildsFolder(t *testing.T) {
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "alpine",
Image: common.TestAlpineImage,
PullPolicy: common.PullPolicyIfNotPresent,
Privileged: true,
},
......@@ -378,10 +381,10 @@ func TestDockerPrivilegedServiceAccessingBuildsFolder(t *testing.T) {
AllowFailure: false,
},
}
build.Image.Name = "docker:git"
build.Image.Name = common.TestDockerGitImage
build.Services = common.Services{
common.Image{
Name: "docker:dind",
Name: common.TestDockerDindImage,
},
}
build.Variables = append(build.Variables, common.JobVariable{
......@@ -407,7 +410,7 @@ func getTestDockerJob(t *testing.T) *common.Build {
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "alpine",
Image: common.TestAlpineImage,
PullPolicy: common.PullPolicyIfNotPresent,
Privileged: true,
},
......@@ -451,8 +454,8 @@ func TestDockerExtendedConfigurationFromJob(t *testing.T) {
},
variables: common.JobVariables{
{Key: "DOCKER_HOST", Value: "tcp://my-docker-service:2375"},
{Key: "IMAGE_NAME", Value: "docker:git"},
{Key: "SERVICE_NAME", Value: "docker:dind"},
{Key: "IMAGE_NAME", Value: common.TestDockerGitImage},
{Key: "SERVICE_NAME", Value: common.TestDockerDindImage},
},
},
{
......@@ -466,8 +469,8 @@ func TestDockerExtendedConfigurationFromJob(t *testing.T) {
},
variables: common.JobVariables{
{Key: "DOCKER_HOST", Value: "tcp://docker:2375"},
{Key: "IMAGE_NAME", Value: "docker:git"},
{Key: "SERVICE_NAME", Value: "docker:dind"},
{Key: "IMAGE_NAME", Value: common.TestDockerGitImage},
{Key: "SERVICE_NAME", Value: common.TestDockerDindImage},
},
},
}
......@@ -524,7 +527,7 @@ func TestCacheInContainer(t *testing.T) {
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "alpine",
Image: common.TestAlpineImage,
PullPolicy: common.PullPolicyIfNotPresent,
Volumes: []string{"/cache"},
},
......@@ -565,7 +568,7 @@ func TestDockerImageNameFromVariable(t *testing.T) {
successfulBuild, err := common.GetRemoteSuccessfulBuild()
successfulBuild.Variables = append(successfulBuild.Variables, common.JobVariable{
Key: "CI_REGISTRY_IMAGE",
Value: "alpine",
Value: common.TestAlpineImage,
})
successfulBuild.Image = common.Image{
Name: "$CI_REGISTRY_IMAGE",
......@@ -577,9 +580,9 @@ func TestDockerImageNameFromVariable(t *testing.T) {
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "alpine",
Image: common.TestAlpineImage,
PullPolicy: common.PullPolicyIfNotPresent,
AllowedServices: []string{"alpine"},
AllowedServices: []string{common.TestAlpineImage},
},
},
},
......@@ -599,7 +602,7 @@ func TestDockerServiceNameFromVariable(t *testing.T) {
successfulBuild, err := common.GetRemoteSuccessfulBuild()
successfulBuild.Variables = append(successfulBuild.Variables, common.JobVariable{
Key: "CI_REGISTRY_IMAGE",
Value: "alpine",
Value: common.TestAlpineImage,
})
successfulBuild.Services = append(successfulBuild.Services, common.Image{
Name: "$CI_REGISTRY_IMAGE",
......@@ -611,9 +614,9 @@ func TestDockerServiceNameFromVariable(t *testing.T) {
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "alpine",
Image: common.TestAlpineImage,
PullPolicy: common.PullPolicyIfNotPresent,
AllowedServices: []string{"alpine"},
AllowedServices: []string{common.TestAlpineImage},
},
},
},
......@@ -707,7 +710,7 @@ func testDockerVersion(t *testing.T, version string) {
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "alpine",
Image: common.TestAlpineImage,
PullPolicy: common.PullPolicyIfNotPresent,
DockerCredentials: credentials,
CPUS: "0.1",
......@@ -808,7 +811,7 @@ func TestDockerCommandWithBrokenGitSSLCAInfo(t *testing.T) {
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "alpine",
Image: common.TestAlpineImage,
PullPolicy: common.PullPolicyIfNotPresent,
},
},
......@@ -840,7 +843,7 @@ func TestDockerCommandWithGitSSLCAInfo(t *testing.T) {
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "alpine",
Image: common.TestAlpineImage,
PullPolicy: common.PullPolicyIfNotPresent,
},
},
......@@ -871,8 +874,9 @@ func TestDockerCommandWithHelperImageConfig(t *testing.T) {
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "alpine",
Image: common.TestAlpineImage,
HelperImage: helperImageConfig,
PullPolicy: common.PullPolicyIfNotPresent,
},
},
},
......@@ -882,7 +886,6 @@ func TestDockerCommandWithHelperImageConfig(t *testing.T) {
err = build.Run(&common.Config{}, &common.Trace{Writer: &buffer})
assert.NoError(t, err)
out := buffer.String()
assert.Contains(t, out, "Pulling docker image "+helperImageConfig)
assert.Contains(t, out, "Using docker image sha256:bbd86c6ba107ae2feb8dbf9024df4b48597c44e1b584a3d901bba91f7fc500e3 for gitlab/gitlab-runner-helper:x86_64-64eea86c ...")
}
......@@ -912,7 +915,7 @@ func TestDockerCommandWithDoingPruneAndAfterScript(t *testing.T) {
RunnerSettings: common.RunnerSettings{
Executor: "docker",
Docker: &common.DockerConfig{
Image: "docker:git",
Image: common.TestDockerGitImage,
PullPolicy: common.PullPolicyIfNotPresent,
Volumes: []string{
"/var/run/docker.sock:/var/run/docker.sock",
......
......@@ -848,15 +848,16 @@ func TestDockerWatchOn_1_12_4(t *testing.T) {
e.Config = common.RunnerConfig{}
e.Config.Docker = &common.DockerConfig{
PullPolicy: common.PullPolicyAlways,
PullPolicy: common.PullPolicyIfNotPresent,
}
e.Trace = &common.Trace{Writer: os.Stdout}
output := bytes.NewBufferString("")
e.Trace = &common.Trace{Writer: output}
err := e.connectDocker()
assert.NoError(t, err)
container, err := e.createContainer("build", common.Image{Name: "alpine"}, []string{"/bin/sh"}, []string{})
container, err := e.createContainer("build", common.Image{Name: common.TestAlpineImage}, []string{"/bin/sh"}, []string{})
assert.NoError(t, err)
assert.NotNil(t, container)
......@@ -868,13 +869,13 @@ func TestDockerWatchOn_1_12_4(t *testing.T) {
go func() {
err = e.watchContainer(e.Context, container.ID, input)
assert.NoError(t, err)
t.Log(err)
finished <- true
wg.Done()
}()
select {
case <-finished:
assert.Equal(t, "script\n", output.String())
case <-time.After(15 * time.Second):
t.Error("Container script not finished")
}
......
......@@ -1256,13 +1256,15 @@ func TestKubernetesSuccessRun(t *testing.T) {
successfulBuild, err := common.GetRemoteSuccessfulBuild()
assert.NoError(t, err)
successfulBuild.Image.Name = "docker:git"
successfulBuild.Image.Name = common.TestDockerGitImage
build := &common.Build{
JobResponse: successfulBuild,
Runner: &common.RunnerConfig{
RunnerSettings: common.RunnerSettings{
Executor: "kubernetes",
Kubernetes: &common.KubernetesConfig{},
Executor: "kubernetes",
Kubernetes: &common.KubernetesConfig{
PullPolicy: common.PullPolicyIfNotPresent,
},
},
},
}
......@@ -1279,13 +1281,15 @@ func TestKubernetesNoRootImage(t *testing.T) {
successfulBuild, err := common.GetRemoteSuccessfulBuildWithDumpedVariables()
assert.NoError(t, err)
successfulBuild.Image.Name = "registry.gitlab.com/gitlab-org/gitlab-runner/alpine-no-root"
successfulBuild.Image.Name = common.TestAlpineNoRootImage
build := &common.Build{
JobResponse: successfulBuild,
Runner: &common.RunnerConfig{
RunnerSettings: common.RunnerSettings{
Executor: "kubernetes",
Kubernetes: &common.KubernetesConfig{},
Executor: "kubernetes",
Kubernetes: &common.KubernetesConfig{
PullPolicy: common.PullPolicyIfNotPresent,
},
},
},
}
......@@ -1305,12 +1309,14 @@ func TestKubernetesBuildFail(t *testing.T) {
JobResponse: failedBuild,
Runner: &common.RunnerConfig{
RunnerSettings: common.RunnerSettings{
Executor: "kubernetes",
Kubernetes: &common.KubernetesConfig{},
Executor: "kubernetes",
Kubernetes: &common.KubernetesConfig{
PullPolicy: common.PullPolicyIfNotPresent,
},
},
},
}
build.Image.Name = "docker:git"
build.Image.Name = common.TestDockerGitImage
err = build.Run(&common.Config{}, &common.Trace{Writer: os.Stdout})
require.Error(t, err, "error")
......@@ -1377,13 +1383,15 @@ func TestKubernetesBuildAbort(t *testing.T) {
JobResponse: failedBuild,
Runner: &common.RunnerConfig{
RunnerSettings: common.RunnerSettings{
Executor: "kubernetes",
Kubernetes: &common.KubernetesConfig{},
Executor: "kubernetes",
Kubernetes: &common.KubernetesConfig{
PullPolicy: common.PullPolicyIfNotPresent,
},
},
},
SystemInterrupt: make(chan os.Signal, 1),
}
build.Image.Name = "docker:git"
build.Image.Name = common.TestDockerGitImage
abortTimer := time.AfterFunc(time.Second, func() {
t.Log("Interrupt")
......@@ -1412,13 +1420,15 @@ func TestKubernetesBuildCancel(t *testing.T) {
JobResponse: failedBuild,
Runner: &common.RunnerConfig{
RunnerSettings: common.RunnerSettings{
Executor: "kubernetes",
Kubernetes: &common.KubernetesConfig{},
Executor: "kubernetes",
Kubernetes: &common.KubernetesConfig{
PullPolicy: common.PullPolicyIfNotPresent,
},
},
},
SystemInterrupt: make(chan os.Signal, 1),
}
build.Image.Name = "docker:git"
build.Image.Name = common.TestDockerGitImage
trace := &common.Trace{Writer: os.Stdout}
......@@ -1461,12 +1471,13 @@ func TestOverwriteNamespaceNotMatch(t *testing.T) {
Executor: "kubernetes",
Kubernetes: &common.KubernetesConfig{
NamespaceOverwriteAllowed: "^not_a_match$",
PullPolicy: common.PullPolicyIfNotPresent,
},
},
},
SystemInterrupt: make(chan os.Signal, 1),
}
build.Image.Name = "docker:git"
build.Image.Name = common.TestDockerGitImage
err := build.Run(&common.Config{}, &common.Trace{Writer: os.Stdout})
require.Error(t, err)
......@@ -1495,12 +1506,13 @@ func TestOverwriteServiceAccountNotMatch(t *testing.T) {
Executor: "kubernetes",
Kubernetes: &common.KubernetesConfig{
ServiceAccountOverwriteAllowed: "^not_a_match$",
PullPolicy: common.PullPolicyIfNotPresent,
},
},
},
SystemInterrupt: make(chan os.Signal, 1),
}
build.Image.Name = "docker:git"
build.Image.Name = common.TestDockerGitImage
err := build.Run(&common.Config{}, &common.Trace{Writer: os.Stdout})
require.Error(t, err)
......
......@@ -5,15 +5,18 @@
# fix existing race conditions
max=33
tmpfile=$(mktemp)
CGO_ENABLED=1 TESTFLAGS="-race" make test 2>&1 | tee -a "$tmpfile"
tmpFile=$(mktemp)
cnt=$(grep -c -e "^WARNING: DATA RACE$" "$tmpfile")
find .testoutput/
grep -E "^WARNING: DATA RACE$" .testoutput/*.race.output.txt > ${tmpFile}
cnt=$(cat ${tmpFile} | wc -l)
echo "Found ${cnt} race conditions. Maximum allowed value is ${max}"
rm "$tmpfile" 2>/dev/null || true
rm "$tmpFile" 2>/dev/null || true
if [ "$cnt" -gt "$max" ]; then
if [ "${cnt}" -gt "${max}" ]; then
echo "Race conditions count increased"
exit 1
fi
#!/usr/bin/env bash
set -eo pipefail
testsDefinitions="testsdefinitions.txt"
TESTFLAGS=${TESTFLAGS:-"-cover"}
PARALLEL_TESTS_LIMIT=${PARALLEL_TESTS_LIMIT:-10}
SUITE_TOTAL=${SUITE_TOTAL:-1}
SUITE_INDEX=${SUITE_INDEX:-0}
output="regular"
coverMode="count"
if [[ ${TESTFLAGS} = *"-race"* ]]; then
output="race"
coverMode="atomic"
fi
printMessage() {
echo -e "\\033[1m${*}\\033[0m"
}
joinBy() {
local IFS="${1}"
shift
echo "${*}"
}
prepareTestCommands() {
local definitions
[[ ! -f ${testsDefinitions} ]] || rm ${testsDefinitions}
for pkg in ${OUR_PACKAGES}; do
local testIndex=0
local runTests=()
local tests
tests=$(go test -list "Test.*" "${pkg}" | grep "^Test" || echo "")
if [[ -z "${tests}" ]]; then
continue
fi
local counter=0
for test in ${tests}; do
counter=$((counter+1))
runTests+=("${test}")
if [[ ${counter} -ge ${PARALLEL_TESTS_LIMIT} ]]; then
if [[ ${#runTests[@]} -gt 0 ]]; then
definitions=$(joinBy "|" "${runTests[@]}")
echo "${pkg} ${testIndex} ${definitions}" | tee -a ${testsDefinitions}
fi
counter=0