feat: import Sea vHost single-server testing release

This commit is contained in:
canglan committed 2026-10-30 08:39:10 +08:00
commit 248badd33e
441 files changed
+63221

No files matched your search

@@ -0,0 +1,70 @@
//go:build linux
package isolation
import (
"os"
"os/exec"
"path/filepath"
"testing"
)
func TestPythonInstallLockExcludesConcurrentRequests(t *testing.T) {
root := t.TempDir()
release, err := acquirePythonInstallLock(root, "3.12.15")
if err != nil {
t.Fatal(err)
}
t.Cleanup(release)
if second, err := acquirePythonInstallLock(root, "3.12.15"); err == nil {
second()
t.Fatal("a concurrent installation acquired the same version lock")
}
release()
second, err := acquirePythonInstallLock(root, "3.12.15")
if err != nil {
t.Fatalf("released lock could not be reacquired: %v", err)
}
defer second()
}
func TestPythonInstallLockReleasedAfterProcessExit(t *testing.T) {
if root := os.Getenv("SEA_PYTHON_LOCK_TEST_ROOT"); root != "" {
_, err := acquirePythonInstallLock(root, "3.12.15")
if err != nil {
os.Exit(2)
}
// Deliberately skip cleanup to simulate an agent crash.
os.Exit(0)
}
root := t.TempDir()
child := exec.Command(os.Args[0], "-test.run=^TestPythonInstallLockReleasedAfterProcessExit$")
child.Env = append(os.Environ(), "SEA_PYTHON_LOCK_TEST_ROOT="+root)
if output, err := child.CombinedOutput(); err != nil {
t.Fatalf("lock owner failed: %v: %s", err, output)
}
release, err := acquirePythonInstallLock(root, "3.12.15")
if err != nil {
t.Fatalf("exited process left a stale lock: %v", err)
}
defer release()
}
func TestPythonInstallLockRejectsSymlink(t *testing.T) {
root := t.TempDir()
target := filepath.Join(root, "unrelated")
if err := os.WriteFile(target, []byte("untouched"), 0600); err != nil {
t.Fatal(err)
}
if err := os.Symlink(target, filepath.Join(root, ".install-3.12.15.flock")); err != nil {
t.Fatal(err)
}
if release, err := acquirePythonInstallLock(root, "3.12.15"); err == nil {
release()
t.Fatal("symbolic link was accepted as a lock file")
}
data, err := os.ReadFile(target)
if err != nil || string(data) != "untouched" {
t.Fatal("lock acquisition modified the symlink target")
}
}