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:
Daniel, Dao Quang Minh 2015-01-16 05:13:19 -05:00
parent f5dfd9a702
commit 5a87153824
1 changed files with 21 additions and 7 deletions

View File

@ -12,15 +12,29 @@ import (
func TestNsenterAlivePid(t *testing.T) {
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{
Path: os.Args[0],
Args: args,
ExtraFiles: []*os.File{r},
}
err := cmd.Run()
if err != nil {
t.Fatal("nsenter exits with a non-zero exit status")
if err := cmd.Start(); err != nil {
t.Fatalf("nsenter failed to start %v", err)
}
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")
}
}