mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Fix TestDuplicateEnvVariable flakyness
Updates #5226 PiperOrigin-RevId: 353262133
This commit is contained in:
committed by
gVisor bot
parent
010cadd3b8
commit
f14f3ba3ef
@@ -52,7 +52,7 @@ func waitForProcessList(cont *Container, want []*control.Process) error {
|
||||
cb := func() error {
|
||||
got, err := cont.Processes()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error getting process data from container: %v", err)
|
||||
err = fmt.Errorf("error getting process data from container: %w", err)
|
||||
return &backoff.PermanentError{Err: err}
|
||||
}
|
||||
if !procListsEqual(got, want) {
|
||||
@@ -64,11 +64,30 @@ func waitForProcessList(cont *Container, want []*control.Process) error {
|
||||
return testutil.Poll(cb, 30*time.Second)
|
||||
}
|
||||
|
||||
// waitForProcess waits for the given process to show up in the container.
|
||||
func waitForProcess(cont *Container, want *control.Process) error {
|
||||
cb := func() error {
|
||||
gots, err := cont.Processes()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error getting process data from container: %w", err)
|
||||
return &backoff.PermanentError{Err: err}
|
||||
}
|
||||
for _, got := range gots {
|
||||
if procEqual(got, want) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("container got process list: %s, want: %+v", procListToString(gots), want)
|
||||
}
|
||||
// Gives plenty of time as tests can run slow under --race.
|
||||
return testutil.Poll(cb, 30*time.Second)
|
||||
}
|
||||
|
||||
func waitForProcessCount(cont *Container, want int) error {
|
||||
cb := func() error {
|
||||
pss, err := cont.Processes()
|
||||
if err != nil {
|
||||
err = fmt.Errorf("error getting process data from container: %v", err)
|
||||
err = fmt.Errorf("error getting process data from container: %w", err)
|
||||
return &backoff.PermanentError{Err: err}
|
||||
}
|
||||
if got := len(pss); got != want {
|
||||
@@ -101,24 +120,28 @@ func procListsEqual(gots, wants []*control.Process) bool {
|
||||
return false
|
||||
}
|
||||
for i := range gots {
|
||||
got := gots[i]
|
||||
want := wants[i]
|
||||
if !procEqual(gots[i], wants[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
if want.UID != math.MaxUint32 && want.UID != got.UID {
|
||||
return false
|
||||
}
|
||||
if want.PID != -1 && want.PID != got.PID {
|
||||
return false
|
||||
}
|
||||
if want.PPID != -1 && want.PPID != got.PPID {
|
||||
return false
|
||||
}
|
||||
if len(want.TTY) != 0 && want.TTY != got.TTY {
|
||||
return false
|
||||
}
|
||||
if len(want.Cmd) != 0 && want.Cmd != got.Cmd {
|
||||
return false
|
||||
}
|
||||
func procEqual(got, want *control.Process) bool {
|
||||
if want.UID != math.MaxUint32 && want.UID != got.UID {
|
||||
return false
|
||||
}
|
||||
if want.PID != -1 && want.PID != got.PID {
|
||||
return false
|
||||
}
|
||||
if want.PPID != -1 && want.PPID != got.PPID {
|
||||
return false
|
||||
}
|
||||
if len(want.TTY) != 0 && want.TTY != got.TTY {
|
||||
return false
|
||||
}
|
||||
if len(want.Cmd) != 0 && want.Cmd != got.Cmd {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -1708,12 +1708,9 @@ func TestMultiContainerHomeEnvDir(t *testing.T) {
|
||||
t.Errorf("wait on child container: %v", err)
|
||||
}
|
||||
|
||||
// Wait for the root container to run.
|
||||
expectedPL := []*control.Process{
|
||||
newProcessBuilder().Cmd("sh").Process(),
|
||||
newProcessBuilder().Cmd("sleep").Process(),
|
||||
}
|
||||
if err := waitForProcessList(containers[0], expectedPL); err != nil {
|
||||
// Wait until after `env` has executed.
|
||||
expectedProc := newProcessBuilder().Cmd("sleep").Process()
|
||||
if err := waitForProcess(containers[0], expectedProc); err != nil {
|
||||
t.Errorf("failed to wait for sleep to start: %v", err)
|
||||
}
|
||||
|
||||
@@ -1831,7 +1828,7 @@ func TestDuplicateEnvVariable(t *testing.T) {
|
||||
cmd1 := fmt.Sprintf("env > %q; sleep 1000", files[0].Name())
|
||||
cmd2 := fmt.Sprintf("env > %q", files[1].Name())
|
||||
cmdExec := fmt.Sprintf("env > %q", files[2].Name())
|
||||
testSpecs, ids := createSpecs([]string{"/bin/bash", "-c", cmd1}, []string{"/bin/bash", "-c", cmd2})
|
||||
testSpecs, ids := createSpecs([]string{"/bin/sh", "-c", cmd1}, []string{"/bin/sh", "-c", cmd2})
|
||||
testSpecs[0].Process.Env = append(testSpecs[0].Process.Env, "VAR=foo", "VAR=bar")
|
||||
testSpecs[1].Process.Env = append(testSpecs[1].Process.Env, "VAR=foo", "VAR=bar")
|
||||
|
||||
@@ -1841,12 +1838,9 @@ func TestDuplicateEnvVariable(t *testing.T) {
|
||||
}
|
||||
defer cleanup()
|
||||
|
||||
// Wait for the `env` from the root container to finish.
|
||||
expectedPL := []*control.Process{
|
||||
newProcessBuilder().Cmd("bash").Process(),
|
||||
newProcessBuilder().Cmd("sleep").Process(),
|
||||
}
|
||||
if err := waitForProcessList(containers[0], expectedPL); err != nil {
|
||||
// Wait until after `env` has executed.
|
||||
expectedProc := newProcessBuilder().Cmd("sleep").Process()
|
||||
if err := waitForProcess(containers[0], expectedProc); err != nil {
|
||||
t.Errorf("failed to wait for sleep to start: %v", err)
|
||||
}
|
||||
if ws, err := containers[1].Wait(); err != nil {
|
||||
@@ -1856,8 +1850,8 @@ func TestDuplicateEnvVariable(t *testing.T) {
|
||||
}
|
||||
|
||||
execArgs := &control.ExecArgs{
|
||||
Filename: "/bin/bash",
|
||||
Argv: []string{"/bin/bash", "-c", cmdExec},
|
||||
Filename: "/bin/sh",
|
||||
Argv: []string{"/bin/sh", "-c", cmdExec},
|
||||
Envv: []string{"VAR=foo", "VAR=bar"},
|
||||
}
|
||||
if ws, err := containers[0].executeSync(execArgs); err != nil || ws.ExitStatus() != 0 {
|
||||
|
||||
Reference in New Issue
Block a user