Skip to content

Commit 9e138c7

Browse files
committed
Enable race detector for CI
1 parent 735b12e commit 9e138c7

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

.drone.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ pipeline:
123123
group: test
124124
environment:
125125
TAGS: bindata
126+
EXTRA_GOFLAGS: -race
126127
commands:
127128
- curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
128129
- apt-get install -y git-lfs
@@ -153,6 +154,7 @@ pipeline:
153154
environment:
154155
TAGS: bindata
155156
TEST_LDAP: "1"
157+
EXTRA_GOFLAGS: -race
156158
commands:
157159
- curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
158160
- apt-get install -y git-lfs
@@ -168,6 +170,7 @@ pipeline:
168170
environment:
169171
TAGS: bindata
170172
TEST_LDAP: "1"
173+
EXTRA_GOFLAGS: -race
171174
commands:
172175
- curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
173176
- apt-get install -y git-lfs

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,13 @@ integration-test-coverage: integrations.cover.test generate-ini
231231
GITEA_ROOT=${CURDIR} GITEA_CONF=integrations/mysql.ini ./integrations.cover.test -test.coverprofile=integration.coverage.out
232232

233233
integrations.test: $(SOURCES)
234-
$(GO) test -c code.gitea.io/gitea/integrations -o integrations.test
234+
$(GO) test -c code.gitea.io/gitea/integrations ${EXTRA_GOFLAGS} -o integrations.test
235235

236236
integrations.sqlite.test: $(SOURCES)
237-
$(GO) test -c code.gitea.io/gitea/integrations -o integrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
237+
$(GO) test -c code.gitea.io/gitea/integrations ${EXTRA_GOFLAGS} -o integrations.sqlite.test -tags 'sqlite sqlite_unlock_notify'
238238

239239
integrations.cover.test: $(SOURCES)
240-
$(GO) test -c code.gitea.io/gitea/integrations -coverpkg $(shell echo $(PACKAGES) | tr ' ' ',') -o integrations.cover.test
240+
$(GO) test -c code.gitea.io/gitea/integrations ${EXTRA_GOFLAGS} -coverpkg $(shell echo $(PACKAGES) | tr ' ' ',') -o integrations.cover.test
241241

242242
.PHONY: check
243243
check: test

integrations/integration_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"testing"
2323

2424
"code.gitea.io/gitea/models"
25+
"code.gitea.io/gitea/modules/racedetector"
2526
"code.gitea.io/gitea/modules/setting"
2627
"code.gitea.io/gitea/routers"
2728
"code.gitea.io/gitea/routers/routes"
@@ -80,6 +81,9 @@ func initIntegrationTest() {
8081
fmt.Println("Environment variable $GITEA_ROOT not set")
8182
os.Exit(1)
8283
}
84+
if racedetector.Enabled {
85+
setting.AppBuiltWith = " (race detector enabled)"
86+
}
8387
setting.AppPath = path.Join(giteaRoot, "gitea")
8488
if _, err := os.Stat(setting.AppPath); err != nil {
8589
fmt.Printf("Could not find gitea binary at %s\n", setting.AppPath)

main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
"code.gitea.io/gitea/cmd"
1414
"code.gitea.io/gitea/modules/log"
15+
"code.gitea.io/gitea/modules/racedetector"
1516
"code.gitea.io/gitea/modules/setting"
1617
// register supported doc types
1718
_ "code.gitea.io/gitea/modules/markup/csv"
@@ -61,5 +62,9 @@ func formatBuiltWith(Tags string) string {
6162
return ""
6263
}
6364

64-
return " built with: " + strings.Replace(Tags, " ", ", ", -1)
65+
s := " built with: " + strings.Replace(Tags, " ", ", ", -1)
66+
if racedetector.Enabled {
67+
s += " (race detector enabled)"
68+
}
69+
return s
6570
}

modules/racedetector/race_disabled.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2018 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build !race
6+
7+
package racedetector
8+
9+
// Enabled is true if race detector is enabled.
10+
var Enabled = false

modules/racedetector/race_enabled.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2018 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
// +build race
6+
7+
package racedetector
8+
9+
// Enabled is true if race detector is enabled.
10+
var Enabled = true

0 commit comments

Comments
 (0)