Refactor integration tests infrastructure#37462
Conversation
Replace `go test -c -o foo.test; ./foo.test` with direct `go test` invocation so Go's testcache works for integration and migration tests (the pre-built-binary pattern bypasses the cache entirely). Collapse 28 near-identical per-DB targets (test-X, test-X#%, test-X-migration, bench-X, migrations.X.test, migrations.individual.X.test and its #% variant) into a `define` macro called once per DB. As a drive-by, the macro generates `migrations.individual.mysql.test#%` which the original Makefile was missing for mysql only. Also drop the now-redundant `\$(GO_SOURCES)` prereq from the migrations.individual targets — `go test` does its own staleness check, the prereq just stat'd thousands of files for nothing. Closes go-gitea#37434 Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Several test files use repo-relative paths (tests/integration/avatar.png, tests/integration/migration-test/, etc.) that worked when the pre-built test binary ran from repo root but break under direct `go test` (cwd = package dir). Anchor cwd in the test setup to keep both invocation styles working. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Predates the per-DB test binary split; no longer produced. The broad `*.test` entry on line 40 covers any stray Go test binary. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Enables Go test result caching for integration/migration tests by switching Makefile targets from precompiled go test -c binaries to direct go test execution, and updates test environment setup so repo-relative fixture paths remain stable.
Changes:
- Replace integration/benchmark/migration Makefile targets to run
go testdirectly (cacheable) and factor per-DB targets into adefinemacro. - Update
SetupGiteaTestEnvtochdirto the repo root so repo-relative test files work whengo testruns withcwd= package directory. - Clean up generated artifacts handling (
make cleanremoves oldmigrations*.test; remove redundant.gitignoreentry).
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
modules/setting/testenv.go |
Anchors test process working directory to the source root for consistent repo-relative fixture access under go test. |
Makefile |
Reworks DB integration/benchmark/migration targets to use go test directly and consolidates duplicated targets via a macro. |
.gitignore |
Removes an obsolete ignore entry for a no-longer-generated test binary name. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Putting the chdir in SetupGiteaTestEnv broke unit tests that legitimately rely on cwd = package dir (services/attachment opens ./attachment_test.go, etc). Move the chdir to tests.InitTest (covers integration tests) and initMigrationTest (covers migration tests) instead — both are entry points only used by tests that historically ran from repo root. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Replaces os.Chdir+require.NoError with t.Chdir, which auto-restores the cwd at test cleanup and satisfies the usetesting lint. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
|
This should improve local integration test re-runs considerably. If we want CI to benefit fully from this caching we need to enable |
`go test` runs each package with cwd set to its directory. Reference the avatar/README/key fixtures and migration dumps relative to the package dir instead of the repo root, dropping the chdir hacks in InitTest and initMigrationTest. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
The integration test cwd is now the package dir (`tests/integration/`), not the repo root, so `tools/test-echo.go` no longer resolves. Use `../../tools/test-echo.go` so the markup-renderer subprocess can find it. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
|
The "paths" should be joint with |
|
Integration benchmark tests can be removed. They are useless after Add integration test for repository migration (#1983) |
Reviewer feedback: derive paths from setting.GetGiteaTestSourceRoot()
instead of relying on cwd, so the fixtures resolve under both `go test`
(cwd = package dir) and the prebuilt binary style.
Switch the avatar/README/key fixtures and migration SQL dumps to
`filepath.Join(setting.GetGiteaTestSourceRoot(), …)`. For the markup
test render command in sqlite.ini.tmpl, add a `{{REPO_ROOT}}` token
substituted to `\$(CURDIR)` by `generate-ini-sqlite`.
Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
Reviewer feedback: the per-DB `bench-*` Make targets and the two `BenchmarkAPICreateFile*` integration cases are superseded by the package-level benchmarks added in go-gitea#3161 — drop them. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
|
REPO_ROOT addition may need review. |
This comment was marked as resolved.
This comment was marked as resolved.
Per review feedback: align with the existing GITEA_TEST_ROOT env var that setting.GetGiteaTestSourceRoot() already honors. Falls back to $(CURDIR) when unset. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
|
In case you question this fallback:
|
No, actually I don't have such question, I know that "GITEA_TEST_ROOT" is never set. It is just a legacy env var from very old code base. Since it is used, keep using the same var name is more consistent, easy to grep, and it's easier to reuse it correctly in the future. |
You can still separate the steps. However, it should share the same build output with "bindata". E2e should use the "real distribution binary" to test, it shouldn't use a specially built binary.
It's up to you |
Run `make backend` as its own step before `make test-e2e`. The backend dep on test-e2e becomes a no-op, so the build (~2 min) and the e2e run (~45 s) appear in separate CI step rows instead of one combined ~3 min step. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
|
Added separate step, decided against removing |
- Test_DropTableColumns logged "is skipped" but never called t.Skip(), so the test reported PASS without running. Replace with t.Skip() and move defer deferable() above the guard so it still runs after Goexit. - The TODO on test-integration cited a 10-min sqlite deadlock that was actually a missing -timeout in the workflow's GOTEST_FLAGS (already fixed in 845f7de). Rewrite the comment to state the real reasons the binary path is kept: testlogger forwards to t.Log so `go test -v` floods output, and testcache can't help these tests anyway because they mutate the work directory. Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
a1012112796
left a comment
There was a problem hiding this comment.
Thank you very much. This PR only moved some parts of the README. IMHO the "Actions" related readme is not really related to this one. And there are many suggested changes, so it's better to propose a new and complete improvement PR after this PR, what do you think?
Highly likely unrelated. |
@silverwind to help you understand more about why the logs are useful, you can try to debug this problem. The logs give you an overview of the context, when the case is executed. Maybe you can spend some time on studying the data race problems too.
|
wxiaoguang
left a comment
There was a problem hiding this comment.
Nothing worse, no blocker problems. Data race is highly likely unrelated.
66b68a3 to
addb9c0
Compare
|
Made a new change to try to reduce CI time.
Feel free to reset/revert if this change is not wanted. |
addb9c0 to
2b22e24
Compare
|
Should be good enough now (container build dryrun time: 1h40m -> ~ 50m) TODOs for following up PRs:
|
-> Refactor CI workflows #37487 |
👍 to gotestsum And #37434 will be the true big win when we achieve cacheable integration tests, it should be possible. |
* origin/main: Refactor CI workflows (go-gitea#37487) Allow multiple projects per issue and pull requests (go-gitea#36784) [skip ci] Updated translations via Crowdin Refactor compare diff/pull page (1) (go-gitea#37481) Fix review submission from single-commit PR view (go-gitea#37475) Refactor integration tests infrastructure (go-gitea#37462) Fix allow maintainer edit permission check (go-gitea#37479) Serve OpenAPI 3.0 spec at /openapi.v1.json (go-gitea#37038) Batch-load related data in actions run, job, and task API endpoints (go-gitea#37032) Add DEFAULT_TITLE_SOURCE setting for pull request title default behavior (go-gitea#37465) Fix compare dropdown for branches without common history (go-gitea#37470) FIX: URL sanitization to handle schemeless credentials (go-gitea#37440) Refactor pull request view (4) (go-gitea#37451) # Conflicts: # modules/indexer/issues/elasticsearch/elasticsearch.go



Related to #37434 but does not solve it.
This PR was written with the help of Claude Opus 4.7