Merge pull request #4645 from masters-of-cats/master
Check if a process exists before returning it
This commit is contained in:
commit
656b487d33
@ -1008,6 +1008,73 @@ func TestContainerAttachProcess(t *testing.T) {
|
|||||||
<-status
|
<-status
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestContainerLoadUnexistingProcess(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
// On windows, closing the write side of the pipe closes the read
|
||||||
|
// side, sending an EOF to it and preventing reopening it.
|
||||||
|
// Hence this test will always fails on windows
|
||||||
|
t.Skip("invalid logic on windows")
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := newClient(t, address)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer client.Close()
|
||||||
|
|
||||||
|
var (
|
||||||
|
image Image
|
||||||
|
ctx, cancel = testContext(t)
|
||||||
|
id = t.Name()
|
||||||
|
)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
image, err = client.GetImage(ctx, testImage)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
container, err := client.NewContainer(ctx, id, WithNewSnapshot(id, image), WithNewSpec(oci.WithImageConfig(image), withProcessArgs("sleep", "100")))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer container.Delete(ctx, WithSnapshotCleanup)
|
||||||
|
|
||||||
|
// creating IO early for easy resource cleanup
|
||||||
|
direct, err := newDirectIO(ctx, false)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer direct.Delete()
|
||||||
|
|
||||||
|
task, err := container.NewTask(ctx, empty())
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer task.Delete(ctx)
|
||||||
|
|
||||||
|
status, err := task.Wait(ctx)
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := task.Start(ctx); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = task.LoadProcess(ctx, "this-process-does-not-exist", direct.IOAttach); err == nil {
|
||||||
|
t.Fatal("an error should have occurred when loading a process that does not exist")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := task.Kill(ctx, syscall.SIGKILL); err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
<-status
|
||||||
|
}
|
||||||
|
|
||||||
func TestContainerUserID(t *testing.T) {
|
func TestContainerUserID(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
@ -441,10 +441,14 @@ func (s *shim) Stats(ctx context.Context) (*ptypes.Any, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *shim) Process(ctx context.Context, id string) (runtime.Process, error) {
|
func (s *shim) Process(ctx context.Context, id string) (runtime.Process, error) {
|
||||||
return &process{
|
p := &process{
|
||||||
id: id,
|
id: id,
|
||||||
shim: s,
|
shim: s,
|
||||||
}, nil
|
}
|
||||||
|
if _, err := p.State(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *shim) State(ctx context.Context) (runtime.State, error) {
|
func (s *shim) State(ctx context.Context) (runtime.State, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user