fix TestNsenterAlivePid
unblock the nsenter-exec test process to let it finish succesfully Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com>
This commit is contained in:
parent
f5dfd9a702
commit
5a87153824
|
@ -12,15 +12,29 @@ import (
|
||||||
|
|
||||||
func TestNsenterAlivePid(t *testing.T) {
|
func TestNsenterAlivePid(t *testing.T) {
|
||||||
args := []string{"nsenter-exec", "--nspid", fmt.Sprintf("%d", os.Getpid())}
|
args := []string{"nsenter-exec", "--nspid", fmt.Sprintf("%d", os.Getpid())}
|
||||||
|
r, w, err := os.Pipe()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("failed to create pipe %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
cmd := &exec.Cmd{
|
cmd := &exec.Cmd{
|
||||||
Path: os.Args[0],
|
Path: os.Args[0],
|
||||||
Args: args,
|
Args: args,
|
||||||
|
ExtraFiles: []*os.File{r},
|
||||||
}
|
}
|
||||||
|
|
||||||
err := cmd.Run()
|
if err := cmd.Start(); err != nil {
|
||||||
if err != nil {
|
t.Fatalf("nsenter failed to start %v", err)
|
||||||
t.Fatal("nsenter exits with a non-zero exit status")
|
}
|
||||||
|
r.Close()
|
||||||
|
|
||||||
|
// unblock the child process
|
||||||
|
if _, err := w.WriteString("1"); err != nil {
|
||||||
|
t.Fatalf("parent failed to write synchronization data %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := cmd.Wait(); err != nil {
|
||||||
|
t.Fatalf("nsenter exits with a non-zero exit status")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue