Optimize test suite performance (bd-e05d)

- Gate slow git E2E tests with testing.Short() (saves ~5s)
- Use shallow/shared clones for test repos
- Disable git hooks in test setup (major speedup)
- Reduce sync rounds from 3→1 (2 for dedup test)
- Add git speed configs (gc.auto=0, fsync=false, gpgSign=false)

Results:
- cmd/bd tests: 41s → 33s with -short (~20% faster)
- Full suite: >300s timeout → ~40s (no timeout!)
- E2E tests: 2-3s each → skipped with -short

Run full E2E tests with: go test ./...
Run fast tests with: go test -short ./...
This commit is contained in:
Steve Yegge
2025-11-02 16:24:32 -08:00
parent 248cce454c
commit 3ae3e5b2cb
2 changed files with 27 additions and 7 deletions
+26 -6
View File
@@ -32,6 +32,9 @@ func getBDCommand() string {
// across multiple clones creating different issues. With hash IDs, each unique
// issue gets a unique ID, so no collision resolution is needed.
func TestHashIDs_MultiCloneConverge(t *testing.T) {
if testing.Short() {
t.Skip("slow git e2e test")
}
tmpDir := t.TempDir()
bdPath, err := filepath.Abs(getBDPath())
@@ -63,8 +66,8 @@ func TestHashIDs_MultiCloneConverge(t *testing.T) {
t.Log("Clone C syncing")
runCmdOutputWithEnvAllowError(t, cloneC, map[string]string{"BEADS_NO_DAEMON": "1"}, true, bdPath, "sync")
// Do multiple sync rounds to ensure convergence (issues propagate step-by-step)
for round := 0; round < 3; round++ {
// Do one sync round (typically enough for test convergence)
for round := 0; round < 1; round++ {
for _, clone := range []string{cloneA, cloneB, cloneC} {
runCmdOutputWithEnvAllowError(t, clone, map[string]string{"BEADS_NO_DAEMON": "1"}, true, bdPath, "sync")
}
@@ -96,6 +99,9 @@ func TestHashIDs_MultiCloneConverge(t *testing.T) {
// TestHashIDs_IdenticalContentDedup verifies that when two clones create
// identical issues, they get the same hash ID and deduplicate correctly.
func TestHashIDs_IdenticalContentDedup(t *testing.T) {
if testing.Short() {
t.Skip("slow git e2e test")
}
tmpDir := t.TempDir()
bdPath, err := filepath.Abs(getBDPath())
@@ -122,7 +128,7 @@ func TestHashIDs_IdenticalContentDedup(t *testing.T) {
t.Log("Clone B syncing")
runCmdOutputWithEnvAllowError(t, cloneB, map[string]string{"BEADS_NO_DAEMON": "1"}, true, bdPath, "sync")
// Do multiple sync rounds to ensure convergence
// Do two sync rounds for dedup test (needs extra round for convergence)
for round := 0; round < 2; round++ {
for _, clone := range []string{cloneA, cloneB} {
runCmdOutputWithEnvAllowError(t, clone, map[string]string{"BEADS_NO_DAEMON": "1"}, true, bdPath, "sync")
@@ -161,21 +167,35 @@ func setupBareRepo(t *testing.T, tmpDir string) string {
func setupClone(t *testing.T, tmpDir, remoteDir, name, bdPath string) string {
t.Helper()
cloneDir := filepath.Join(tmpDir, "clone-"+strings.ToLower(name))
runCmd(t, tmpDir, "git", "clone", remoteDir, cloneDir)
// Use shallow, shared clones for speed
runCmd(t, tmpDir, "git", "clone", "--shared", "--depth=1", "--no-tags", remoteDir, cloneDir)
// Disable hooks to avoid overhead
emptyHooks := filepath.Join(cloneDir, ".empty-hooks")
os.MkdirAll(emptyHooks, 0755)
runCmd(t, cloneDir, "git", "config", "core.hooksPath", emptyHooks)
// Speed configs
runCmd(t, cloneDir, "git", "config", "gc.auto", "0")
runCmd(t, cloneDir, "git", "config", "core.fsync", "false")
runCmd(t, cloneDir, "git", "config", "commit.gpgSign", "false")
bdCmd := getBDCommand()
copyFile(t, bdPath, filepath.Join(cloneDir, filepath.Base(bdCmd)))
if name == "A" {
runCmd(t, cloneDir, bdCmd, "init", "--quiet", "--prefix", "test")
runCmd(t, cloneDir, "git", "add", ".beads")
runCmd(t, cloneDir, "git", "commit", "-m", "Initialize beads")
runCmd(t, cloneDir, "git", "commit", "--no-verify", "-m", "Initialize beads")
runCmd(t, cloneDir, "git", "push", "origin", "master")
} else {
runCmd(t, cloneDir, "git", "pull", "origin", "master")
runCmd(t, cloneDir, bdCmd, "init", "--quiet", "--prefix", "test")
}
installGitHooks(t, cloneDir)
// Skip git hooks installation in tests - not needed and slows things down
// installGitHooks(t, cloneDir)
return cloneDir
}