mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-24 07:40:00 +00:00
test: speed up tests, fix transaction bug (#39030)
Speed up tests: `make test-backend` 103s to 37s, `make test-integration` 908s to 852s. Most of it is a detached system notice insert blocking on the SQLite write lock until the busy timeout expired, and `ExternalServiceHTTP` re-probing on every call with an untimed `http.Get`. - fixed one correctness bug with nested transactions: files were deleted while the outer transaction was open, so a later failure could roll the database back with the files gone - git push branch counts were far above the hook batch size - Fix makefile dependencies so running tests and lint work in fresh worktrees. --------- Co-authored-by: Giteabot <teabot@gitea.io> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@ package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
actions_model "gitea.dev/models/actions"
|
||||
@@ -48,9 +49,11 @@ func deleteDBRepository(ctx context.Context, repoID int64) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteRepository deletes a repository for a user or organization.
|
||||
// make sure if you call this func to close open sessions (sqlite will otherwise get a deadlock)
|
||||
// DeleteRepositoryDirectly deletes a repository for a user or organization.
|
||||
func DeleteRepositoryDirectly(ctx context.Context, repoID int64, ignoreOrgTeams ...bool) error {
|
||||
if db.InTransaction(ctx) {
|
||||
return errors.New("DeleteRepositoryDirectly must not be called within a transaction, it deletes storage once its own transaction commits")
|
||||
}
|
||||
ctx, committer, err := db.TxContext(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package repository_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
actions_model "gitea.dev/models/actions"
|
||||
@@ -54,6 +55,16 @@ func TestDeleteOwnerRepositoriesDirectly(t *testing.T) {
|
||||
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
|
||||
|
||||
assert.NoError(t, repo_service.DeleteOwnerRepositoriesDirectly(t.Context(), user))
|
||||
|
||||
t.Run("RejectedInTransaction", func(t *testing.T) {
|
||||
unittest.PrepareTestEnv(t)
|
||||
|
||||
err := db.WithTx(t.Context(), func(ctx context.Context) error {
|
||||
return repo_service.DeleteRepositoryDirectly(ctx, 1)
|
||||
})
|
||||
assert.ErrorContains(t, err, "must not be called within a transaction")
|
||||
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
})
|
||||
}
|
||||
|
||||
func TestDeleteRepositoryDirectlyPurgesRepoScopedRows(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user