daemon: seed repo volume via CopyToContainer (host-path bind bug → empty workspace); web: spawn poll reads fresh session list
This commit is contained in:
+21
-10
@@ -13,6 +13,7 @@ import (
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -89,16 +90,20 @@ func TestSpawnerStartHappyPath(t *testing.T) {
|
||||
t.Fatalf("network = %q", c.HostConfig.NetworkMode)
|
||||
}
|
||||
|
||||
// fresh repo volume seeded from the clone via a one-shot container
|
||||
// fresh repo volume seeded from the clone via CopyToContainer (tar)
|
||||
seed := f.createsByName("lvmh-seed-")
|
||||
if len(seed) != 1 {
|
||||
t.Fatalf("seed containers = %+v", seed)
|
||||
}
|
||||
if seed[0].Image != imageRefWorker || len(seed[0].Cmd) == 0 || !strings.Contains(seed[0].Cmd[len(seed[0].Cmd)-1], workspaceMount) {
|
||||
if seed[0].Image != imageRefWorker {
|
||||
t.Fatalf("seed create = %+v", seed[0])
|
||||
}
|
||||
if !strings.HasPrefix(seed[0].HostConfig.Binds[1], sp.reposDir) {
|
||||
t.Fatalf("seed binds = %v, want clone dir mounted at /src", seed[0].HostConfig.Binds)
|
||||
wantSeedBinds := []string{"lvmh-repo-group-project:" + workspaceMount}
|
||||
if !reflect.DeepEqual(seed[0].HostConfig.Binds, wantSeedBinds) {
|
||||
t.Fatalf("seed binds = %v, want %v (no host-path binds)", seed[0].HostConfig.Binds, wantSeedBinds)
|
||||
}
|
||||
if len(f.archives) != 1 || f.archives[0] == 0 {
|
||||
t.Fatalf("CopyToContainer archives = %v, want one non-empty tar", f.archives)
|
||||
}
|
||||
|
||||
// no build expected (fake daemon already has the image)
|
||||
@@ -204,11 +209,11 @@ func TestSpawnerRunJobErrorStates(t *testing.T) {
|
||||
wantMsg: "volume create failed",
|
||||
},
|
||||
{
|
||||
name: "seed-wait-fails",
|
||||
name: "seed-copy-fails",
|
||||
setup: func(t *testing.T, f *fakeDocker) {
|
||||
f.failWait = true
|
||||
f.failArchive = true
|
||||
},
|
||||
wantMsg: "wait failed",
|
||||
wantMsg: "copy into volume",
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
@@ -315,17 +320,23 @@ func TestSpawnerRemoveSession(t *testing.T) {
|
||||
f.assertNoUnknown(t)
|
||||
}
|
||||
|
||||
func TestSpawnerSeedVolumeWaitContextCancel(t *testing.T) {
|
||||
func TestSpawnerSeedVolumeCancel(t *testing.T) {
|
||||
useFakeGit(t, fakeGitModeOK)
|
||||
f := newFakeDocker()
|
||||
f.waitHang = true // server never answers wait
|
||||
f.archiveHang = true // server never answers the archive PUT
|
||||
sp, _ := newTestSpawner(t, f)
|
||||
if err := os.MkdirAll(filepath.Join(sp.reposDir, "group-project"), 0o755); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.WriteFile(filepath.Join(sp.reposDir, "group-project", "README.md"), []byte("x"), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
done := make(chan error, 1)
|
||||
go func() { done <- sp.seedVolume(ctx, "group-project", "lvmh-repo-group-project") }()
|
||||
waitFor(t, 5*time.Second, func() bool { return f.hasCallSuffix(http.MethodPost, "/wait") })
|
||||
waitFor(t, 5*time.Second, func() bool { return f.hasCallSuffix(http.MethodPut, "/archive") })
|
||||
cancel()
|
||||
select {
|
||||
case err := <-done:
|
||||
|
||||
Reference in New Issue
Block a user