mirror of https://github.com/docker/docs.git
Merge pull request #467 from dotcloud/improve_localhost_port_test
* tests: Improve unit test to avoid unnecessary warnigns
This commit is contained in:
commit
636c7835d3
|
@ -394,4 +394,5 @@ func TestAttachDisconnect(t *testing.T) {
|
||||||
// Try to avoid the timeoout in destroy. Best effort, don't check error
|
// Try to avoid the timeoout in destroy. Best effort, don't check error
|
||||||
cStdin, _ := container.StdinPipe()
|
cStdin, _ := container.StdinPipe()
|
||||||
cStdin.Close()
|
cStdin.Close()
|
||||||
|
container.Wait()
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@ func TestIdFormat(t *testing.T) {
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).Id,
|
||||||
Cmd: []string{"/bin/sh", "-c", "echo hello world"},
|
Cmd: []string{"/bin/sh", "-c", "echo hello world"},
|
||||||
Memory: 33554432,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -50,7 +49,6 @@ func TestMultipleAttachRestart(t *testing.T) {
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).Id,
|
||||||
Cmd: []string{"/bin/sh", "-c",
|
Cmd: []string{"/bin/sh", "-c",
|
||||||
"i=1; while [ $i -le 5 ]; do i=`expr $i + 1`; echo hello; done"},
|
"i=1; while [ $i -le 5 ]; do i=`expr $i + 1`; echo hello; done"},
|
||||||
Memory: 33554432,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -116,8 +114,8 @@ func TestMultipleAttachRestart(t *testing.T) {
|
||||||
if err := container.Start(); err != nil {
|
if err := container.Start(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
timeout := make(chan bool)
|
|
||||||
go func() {
|
setTimeout(t, "Timeout reading from the process", 3*time.Second, func() {
|
||||||
l1, err = bufio.NewReader(stdout1).ReadString('\n')
|
l1, err = bufio.NewReader(stdout1).ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -139,15 +137,8 @@ func TestMultipleAttachRestart(t *testing.T) {
|
||||||
if strings.Trim(l3, " \r\n") != "hello" {
|
if strings.Trim(l3, " \r\n") != "hello" {
|
||||||
t.Fatalf("Unexpected output. Expected [%s], received [%s]", "hello", l3)
|
t.Fatalf("Unexpected output. Expected [%s], received [%s]", "hello", l3)
|
||||||
}
|
}
|
||||||
timeout <- false
|
})
|
||||||
}()
|
container.Wait()
|
||||||
go func() {
|
|
||||||
time.Sleep(3 * time.Second)
|
|
||||||
timeout <- true
|
|
||||||
}()
|
|
||||||
if <-timeout {
|
|
||||||
t.Fatalf("Timeout reading from the process")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDiff(t *testing.T) {
|
func TestDiff(t *testing.T) {
|
||||||
|
@ -236,7 +227,6 @@ func TestCommitRun(t *testing.T) {
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).Id,
|
||||||
Cmd: []string{"/bin/sh", "-c", "echo hello > /world"},
|
Cmd: []string{"/bin/sh", "-c", "echo hello > /world"},
|
||||||
Memory: 33554432,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -268,7 +258,6 @@ func TestCommitRun(t *testing.T) {
|
||||||
container2, err := runtime.Create(
|
container2, err := runtime.Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: img.Id,
|
Image: img.Id,
|
||||||
Memory: 33554432,
|
|
||||||
Cmd: []string{"cat", "/world"},
|
Cmd: []string{"cat", "/world"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -355,7 +344,6 @@ func TestRun(t *testing.T) {
|
||||||
container, err := runtime.Create(
|
container, err := runtime.Create(
|
||||||
&Config{
|
&Config{
|
||||||
Image: GetTestImage(runtime).Id,
|
Image: GetTestImage(runtime).Id,
|
||||||
Memory: 33554432,
|
|
||||||
Cmd: []string{"ls", "-al"},
|
Cmd: []string{"ls", "-al"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -275,7 +275,16 @@ func TestAllocatePortLocalhost(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer container.Kill()
|
defer container.Kill()
|
||||||
time.Sleep(600 * time.Millisecond) // Wait for the container to run
|
|
||||||
|
setTimeout(t, "Waiting for the container to be started timed out", 2*time.Second, func() {
|
||||||
|
for {
|
||||||
|
if container.State.Running {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
conn, err := net.Dial("tcp",
|
conn, err := net.Dial("tcp",
|
||||||
fmt.Sprintf(
|
fmt.Sprintf(
|
||||||
"localhost:%s", container.NetworkSettings.PortMapping["5555"],
|
"localhost:%s", container.NetworkSettings.PortMapping["5555"],
|
||||||
|
@ -295,6 +304,7 @@ func TestAllocatePortLocalhost(t *testing.T) {
|
||||||
string(output),
|
string(output),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
container.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRestore(t *testing.T) {
|
func TestRestore(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue