mirror of
				https://github.com/go-gitea/gitea
				synced 2025-10-31 19:38:23 +00:00 
			
		
		
		
	Reduce integration test overhead (#32475)
In profiling integration tests, I found a couple places where per-test overhead could be reduced: * Avoiding disk IO by synchronizing instead of deleting & copying test Git repository data. This saves ~100ms per test on my machine * When flushing queues in `PrintCurrentTest`, invoke `FlushWithContext` in a parallel. --------- Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
		| @@ -8,7 +8,6 @@ import ( | ||||
| 	"context" | ||||
| 	"fmt" | ||||
| 	"os" | ||||
| 	"path" | ||||
| 	"path/filepath" | ||||
| 	"runtime" | ||||
| 	"testing" | ||||
| @@ -35,27 +34,7 @@ func PrepareTestEnv(t *testing.T, skip int, syncModels ...any) (*xorm.Engine, fu | ||||
| 	ourSkip := 2 | ||||
| 	ourSkip += skip | ||||
| 	deferFn := testlogger.PrintCurrentTest(t, ourSkip) | ||||
| 	assert.NoError(t, os.RemoveAll(setting.RepoRootPath)) | ||||
| 	assert.NoError(t, unittest.CopyDir(path.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath)) | ||||
| 	ownerDirs, err := os.ReadDir(setting.RepoRootPath) | ||||
| 	if err != nil { | ||||
| 		assert.NoError(t, err, "unable to read the new repo root: %v\n", err) | ||||
| 	} | ||||
| 	for _, ownerDir := range ownerDirs { | ||||
| 		if !ownerDir.Type().IsDir() { | ||||
| 			continue | ||||
| 		} | ||||
| 		repoDirs, err := os.ReadDir(filepath.Join(setting.RepoRootPath, ownerDir.Name())) | ||||
| 		if err != nil { | ||||
| 			assert.NoError(t, err, "unable to read the new repo root: %v\n", err) | ||||
| 		} | ||||
| 		for _, repoDir := range repoDirs { | ||||
| 			_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "pack"), 0o755) | ||||
| 			_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "objects", "info"), 0o755) | ||||
| 			_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "heads"), 0o755) | ||||
| 			_ = os.MkdirAll(filepath.Join(setting.RepoRootPath, ownerDir.Name(), repoDir.Name(), "refs", "tag"), 0o755) | ||||
| 		} | ||||
| 	} | ||||
| 	assert.NoError(t, unittest.SyncDirs(filepath.Join(filepath.Dir(setting.AppPath), "tests/gitea-repositories-meta"), setting.RepoRootPath)) | ||||
|  | ||||
| 	if err := deleteDB(); err != nil { | ||||
| 		t.Errorf("unable to reset database: %v", err) | ||||
| @@ -123,7 +102,7 @@ func MainTest(m *testing.M) { | ||||
| 	if runtime.GOOS == "windows" { | ||||
| 		giteaBinary += ".exe" | ||||
| 	} | ||||
| 	setting.AppPath = path.Join(giteaRoot, giteaBinary) | ||||
| 	setting.AppPath = filepath.Join(giteaRoot, giteaBinary) | ||||
| 	if _, err := os.Stat(setting.AppPath); err != nil { | ||||
| 		fmt.Printf("Could not find gitea binary at %s\n", setting.AppPath) | ||||
| 		os.Exit(1) | ||||
| @@ -131,12 +110,12 @@ func MainTest(m *testing.M) { | ||||
|  | ||||
| 	giteaConf := os.Getenv("GITEA_CONF") | ||||
| 	if giteaConf == "" { | ||||
| 		giteaConf = path.Join(filepath.Dir(setting.AppPath), "tests/sqlite.ini") | ||||
| 		giteaConf = filepath.Join(filepath.Dir(setting.AppPath), "tests/sqlite.ini") | ||||
| 		fmt.Printf("Environment variable $GITEA_CONF not set - defaulting to %s\n", giteaConf) | ||||
| 	} | ||||
|  | ||||
| 	if !path.IsAbs(giteaConf) { | ||||
| 		setting.CustomConf = path.Join(giteaRoot, giteaConf) | ||||
| 	if !filepath.IsAbs(giteaConf) { | ||||
| 		setting.CustomConf = filepath.Join(giteaRoot, giteaConf) | ||||
| 	} else { | ||||
| 		setting.CustomConf = giteaConf | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user