Skip to content

Commit

Permalink
Fix race condition in nsfix test
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Shvedunov committed Jun 21, 2018
1 parent 5ce81f4 commit 2d1c810
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions pkg/nsfix/nsfix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

"github.com/golang/glog"

"github.com/Mirantis/virtlet/pkg/utils"
testutils "github.com/Mirantis/virtlet/pkg/utils/testing"
)

Expand Down Expand Up @@ -125,17 +126,36 @@ func verifyNsFix(t *testing.T, toRun func(tmpDir string, dirs map[string]string,
}
}

doneFiles := []string{
filepath.Join(tmpDir, "done1"),
filepath.Join(tmpDir, "done2"),
}
var pids []int
for _, cmd := range []string{
fmt.Sprintf("mount --bind %q %q && sleep 10000", dirs["a"], dirs["b"]),
fmt.Sprintf("mount --bind %q %q && sleep 10000", dirs["d"], dirs["b"]),
fmt.Sprintf("mount --bind %q %q && touch %q && sleep 10000", dirs["a"], dirs["b"], doneFiles[0]),
fmt.Sprintf("mount --bind %q %q && touch %q && sleep 10000", dirs["d"], dirs["b"], doneFiles[1]),
} {
tc := testutils.RunProcess(t, "unshare", []string{
"-m", "/bin/bash", "-c", cmd,
}, nil)
defer tc.Stop()
pids = append(pids, tc.Pid())
}
if err := utils.WaitLoop(func() (bool, error) {
for _, fileName := range doneFiles {
switch _, err := os.Stat(fileName); {
case err == nil:
// ok
case os.IsNotExist(err):
return false, nil
default:
return false, err
}
}
return true, nil
}, 50*time.Millisecond, 10*time.Second, nil); err != nil {
t.Fatal(err)
}

toRun(tmpDir, dirs, pids)
}
Expand Down

0 comments on commit 2d1c810

Please sign in to comment.