Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: modify network test #2312

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions test/cli_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,7 @@ func (suite *PouchNetworkSuite) TestNetworkCreateDup(c *check.C) {
}

func (suite *PouchNetworkSuite) TestNetworkPortMapping(c *check.C) {
pc, _, _, _ := runtime.Caller(0)
tmpname := strings.Split(runtime.FuncForPC(pc).Name(), ".")
var funcname string
for i := range tmpname {
funcname = tmpname[i]
}
cname := "TestNetworkPortMapping"

ret := icmd.RunCommand("which", "curl")
if ret.ExitCode != 0 {
Expand All @@ -342,15 +337,22 @@ func (suite *PouchNetworkSuite) TestNetworkPortMapping(c *check.C) {

command.PouchRun("pull", image).Assert(c, icmd.Success)
command.PouchRun("run", "-d",
"--name", funcname,
"--name", cname,
"-p", "9999:80",
image).Assert(c, icmd.Success)
defer DelContainerForceMultyTime(c, cname)

time.Sleep(10 * time.Second)
err := icmd.RunCommand("timeout", "5", "curl", "localhost:9999").Compare(expct)
c.Assert(err, check.IsNil)
success := false
for i := 0; i < 60; i++ {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will try 60 times?
Will it be so long?
Just double check. @zhuangqh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Often, this command would success in several tries. Try many times to make sure the network port mapping is fail....longest timeout is 6 minutes.

err := icmd.RunCommand("timeout", "5", "curl", "localhost:9999").Compare(expct)
if err == nil {
success = true
break
}
time.Sleep(1 * time.Second)
}

command.PouchRun("rm", "-f", funcname)
c.Assert(success, check.Equals, true)
}

func createBridge(bridgeName string) (netlink.Link, error) {
Expand Down
2 changes: 1 addition & 1 deletion test/cli_run_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (suite *PouchRunNetworkSuite) TestRunWithPing(c *check.C) {
name := "TestRunWithPing"

res := command.PouchRun("run", "--name", name,
busyboxImage, "ping", "-c", "10", "www.taobao.com")
busyboxImage, "ping", "-c", "3", "www.taobao.com")
defer DelContainerForceMultyTime(c, name)
res.Assert(c, icmd.Success)
}