Skip to content

Commit e8b6d28

Browse files
lunnyGiteaBot
andauthored
Fix bug hidden on CI and make ci failed if tests failure (#29254) (#29662)
Backport #29254 The tests on migration tests failed but CI reports successfully https://github.com/go-gitea/gitea/actions/runs/7364373807/job/20044685969#step:8:141 This PR will fix the bug on migrations and also the CI hidden behaviour. The reason is on the Makefile `GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' $(MIGRATE_TEST_PACKAGES)` will return the error exit code. But `for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \ GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \ done` will not work. --------- Co-authored-by: Giteabot <[email protected]>
1 parent 346b662 commit e8b6d28

File tree

8 files changed

+60
-28
lines changed

8 files changed

+60
-28
lines changed

.github/workflows/pull-db-tests.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ jobs:
4949
- run: make backend
5050
env:
5151
TAGS: bindata
52-
- run: make test-pgsql-migration test-pgsql
52+
- name: run migration tests
53+
run: make test-pgsql-migration
54+
- name: run tests
55+
run: make test-pgsql
5356
timeout-minutes: 50
5457
env:
5558
TAGS: bindata gogit
@@ -72,7 +75,10 @@ jobs:
7275
- run: make backend
7376
env:
7477
TAGS: bindata gogit sqlite sqlite_unlock_notify
75-
- run: make test-sqlite-migration test-sqlite
78+
- name: run migration tests
79+
run: make test-sqlite-migration
80+
- name: run tests
81+
run: make test-sqlite
7682
timeout-minutes: 50
7783
env:
7884
TAGS: bindata gogit sqlite sqlite_unlock_notify
@@ -189,8 +195,10 @@ jobs:
189195
- run: make backend
190196
env:
191197
TAGS: bindata
198+
- name: run migration tests
199+
run: make test-mysql-migration
192200
- name: run tests
193-
run: make test-mysql-migration integration-test-coverage
201+
run: make integration-test-coverage
194202
env:
195203
TAGS: bindata
196204
RACE_ENABLED: true
@@ -252,7 +260,9 @@ jobs:
252260
- run: make backend
253261
env:
254262
TAGS: bindata
255-
- run: make test-mssql-migration test-mssql
263+
- run: make test-mssql-migration
264+
- name: run tests
265+
run: make test-mssql
256266
timeout-minutes: 50
257267
env:
258268
TAGS: bindata

Makefile

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ LINUX_ARCHS ?= linux/amd64,linux/386,linux/arm-5,linux/arm-6,linux/arm64
111111

112112
GO_PACKAGES ?= $(filter-out code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/))
113113
GO_TEST_PACKAGES ?= $(filter-out $(shell $(GO) list code.gitea.io/gitea/models/migrations/...) code.gitea.io/gitea/tests/integration/migration-test code.gitea.io/gitea/tests code.gitea.io/gitea/tests/integration code.gitea.io/gitea/tests/e2e,$(shell $(GO) list ./... | grep -v /vendor/))
114+
MIGRATE_TEST_PACKAGES ?= $(shell $(GO) list code.gitea.io/gitea/models/migrations/...)
114115

115116
FOMANTIC_WORK_DIR := web_src/fomantic
116117

@@ -748,9 +749,7 @@ migrations.sqlite.test: $(GO_SOURCES) generate-ini-sqlite
748749

749750
.PHONY: migrations.individual.mysql.test
750751
migrations.individual.mysql.test: $(GO_SOURCES)
751-
for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
752-
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \
753-
done
752+
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mysql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
754753

755754
.PHONY: migrations.individual.mysql8.test
756755
migrations.individual.mysql8.test: $(GO_SOURCES)
@@ -764,30 +763,23 @@ migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite
764763

765764
.PHONY: migrations.individual.pgsql.test
766765
migrations.individual.pgsql.test: $(GO_SOURCES)
767-
for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
768-
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \
769-
done
766+
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
770767

771768
.PHONY: migrations.individual.pgsql.test\#%
772769
migrations.individual.pgsql.test\#%: $(GO_SOURCES) generate-ini-pgsql
773770
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/pgsql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
774771

775-
776772
.PHONY: migrations.individual.mssql.test
777773
migrations.individual.mssql.test: $(GO_SOURCES) generate-ini-mssql
778-
for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
779-
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg -test.failfast; \
780-
done
774+
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
781775

782776
.PHONY: migrations.individual.mssql.test\#%
783777
migrations.individual.mssql.test\#%: $(GO_SOURCES) generate-ini-mssql
784778
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/mssql.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' code.gitea.io/gitea/models/migrations/$*
785779

786780
.PHONY: migrations.individual.sqlite.test
787781
migrations.individual.sqlite.test: $(GO_SOURCES) generate-ini-sqlite
788-
for pkg in $(shell $(GO) list code.gitea.io/gitea/models/migrations/...); do \
789-
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags '$(TEST_TAGS)' $$pkg; \
790-
done
782+
GITEA_ROOT="$(CURDIR)" GITEA_CONF=tests/sqlite.ini $(GO) test $(GOTESTFLAGS) -tags='$(TEST_TAGS)' -p 1 $(MIGRATE_TEST_PACKAGES)
791783

792784
.PHONY: migrations.individual.sqlite.test\#%
793785
migrations.individual.sqlite.test\#%: $(GO_SOURCES) generate-ini-sqlite

models/migrations/base/db_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ func Test_DropTableColumns(t *testing.T) {
3636
"updated_unix",
3737
}
3838

39+
x.SetMapper(names.GonicMapper{})
40+
3941
for i := range columns {
40-
x.SetMapper(names.GonicMapper{})
4142
if err := x.Sync(new(DropTest)); err != nil {
4243
t.Errorf("unable to create DropTest table: %v", err)
4344
return
4445
}
46+
4547
sess := x.NewSession()
4648
if err := sess.Begin(); err != nil {
4749
sess.Close()
@@ -64,7 +66,6 @@ func Test_DropTableColumns(t *testing.T) {
6466
return
6567
}
6668
for j := range columns[i+1:] {
67-
x.SetMapper(names.GonicMapper{})
6869
if err := x.Sync(new(DropTest)); err != nil {
6970
t.Errorf("unable to create DropTest table: %v", err)
7071
return
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-
2+
id: 1
3+
repo_id: 1
4+
index: 1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
-
2+
id: 1
3+
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11
4+
issue_id: 1
5+
release_id: 0
6+
7+
-
8+
id: 2
9+
uuid: a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a12
10+
issue_id: 0
11+
release_id: 1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-
2+
id: 1
3+
repo_id: 1
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-
2+
id: 1
3+
repo_id: 1

models/migrations/v1_16/v193_test.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ func Test_AddRepoIDForAttachment(t *testing.T) {
1515
type Attachment struct {
1616
ID int64 `xorm:"pk autoincr"`
1717
UUID string `xorm:"uuid UNIQUE"`
18-
RepoID int64 `xorm:"INDEX"` // this should not be zero
1918
IssueID int64 `xorm:"INDEX"` // maybe zero when creating
2019
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
2120
UploaderID int64 `xorm:"INDEX DEFAULT 0"`
@@ -44,25 +43,34 @@ func Test_AddRepoIDForAttachment(t *testing.T) {
4443
return
4544
}
4645

47-
var issueAttachments []*Attachment
48-
err := x.Where("issue_id > 0").Find(&issueAttachments)
46+
type NewAttachment struct {
47+
ID int64 `xorm:"pk autoincr"`
48+
UUID string `xorm:"uuid UNIQUE"`
49+
RepoID int64 `xorm:"INDEX"` // this should not be zero
50+
IssueID int64 `xorm:"INDEX"` // maybe zero when creating
51+
ReleaseID int64 `xorm:"INDEX"` // maybe zero when creating
52+
UploaderID int64 `xorm:"INDEX DEFAULT 0"`
53+
}
54+
55+
var issueAttachments []*NewAttachment
56+
err := x.Table("attachment").Where("issue_id > 0").Find(&issueAttachments)
4957
assert.NoError(t, err)
5058
for _, attach := range issueAttachments {
51-
assert.Greater(t, attach.RepoID, 0)
52-
assert.Greater(t, attach.IssueID, 0)
59+
assert.Greater(t, attach.RepoID, int64(0))
60+
assert.Greater(t, attach.IssueID, int64(0))
5361
var issue Issue
5462
has, err := x.ID(attach.IssueID).Get(&issue)
5563
assert.NoError(t, err)
5664
assert.True(t, has)
5765
assert.EqualValues(t, attach.RepoID, issue.RepoID)
5866
}
5967

60-
var releaseAttachments []*Attachment
61-
err = x.Where("release_id > 0").Find(&releaseAttachments)
68+
var releaseAttachments []*NewAttachment
69+
err = x.Table("attachment").Where("release_id > 0").Find(&releaseAttachments)
6270
assert.NoError(t, err)
6371
for _, attach := range releaseAttachments {
64-
assert.Greater(t, attach.RepoID, 0)
65-
assert.Greater(t, attach.IssueID, 0)
72+
assert.Greater(t, attach.RepoID, int64(0))
73+
assert.Greater(t, attach.ReleaseID, int64(0))
6674
var release Release
6775
has, err := x.ID(attach.ReleaseID).Get(&release)
6876
assert.NoError(t, err)

0 commit comments

Comments
 (0)