move the assertions outside of the goroutine
Signed-off-by: Shijiang Wei <mountkin@gmail.com>
This commit is contained in:
parent
dff25c9e46
commit
bb161b7789
|
@ -7,6 +7,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/go-check/check"
|
"github.com/go-check/check"
|
||||||
)
|
)
|
||||||
|
@ -28,53 +29,75 @@ func (s *DockerSuite) TestExecResizeImmediatelyAfterExecStart(c *check.C) {
|
||||||
name := "exec_resize_test"
|
name := "exec_resize_test"
|
||||||
dockerCmd(c, "run", "-d", "-i", "-t", "--name", name, "--restart", "always", "busybox", "/bin/sh")
|
dockerCmd(c, "run", "-d", "-i", "-t", "--name", name, "--restart", "always", "busybox", "/bin/sh")
|
||||||
|
|
||||||
// The panic happens when daemon.ContainerExecStart is called but the
|
testExecResize := func() error {
|
||||||
// container.Exec is not called.
|
|
||||||
// Because the panic is not 100% reproducible, we send the requests concurrently
|
|
||||||
// to increase the probability that the problem is triggered.
|
|
||||||
n := 10
|
|
||||||
ch := make(chan struct{})
|
|
||||||
for i := 0; i < n; i++ {
|
|
||||||
go func() {
|
|
||||||
defer func() {
|
|
||||||
ch <- struct{}{}
|
|
||||||
}()
|
|
||||||
|
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"AttachStdin": true,
|
"AttachStdin": true,
|
||||||
"Cmd": []string{"/bin/sh"},
|
"Cmd": []string{"/bin/sh"},
|
||||||
}
|
}
|
||||||
status, body, err := sockRequest("POST", fmt.Sprintf("/containers/%s/exec", name), data)
|
uri := fmt.Sprintf("/containers/%s/exec", name)
|
||||||
c.Assert(err, check.IsNil)
|
status, body, err := sockRequest("POST", uri, data)
|
||||||
c.Assert(status, check.Equals, http.StatusCreated)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if status != http.StatusCreated {
|
||||||
|
return fmt.Errorf("POST %s is expected to return %d, got %d", uri, http.StatusCreated, status)
|
||||||
|
}
|
||||||
|
|
||||||
out := map[string]string{}
|
out := map[string]string{}
|
||||||
err = json.Unmarshal(body, &out)
|
err = json.Unmarshal(body, &out)
|
||||||
c.Assert(err, check.IsNil)
|
if err != nil {
|
||||||
|
return fmt.Errorf("ExecCreate returned invalid json. Error: %q", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
execID := out["Id"]
|
execID := out["Id"]
|
||||||
if len(execID) < 1 {
|
if len(execID) < 1 {
|
||||||
c.Fatal("ExecCreate got invalid execID")
|
return fmt.Errorf("ExecCreate got invalid execID")
|
||||||
}
|
}
|
||||||
|
|
||||||
payload := bytes.NewBufferString(`{"Tty":true}`)
|
payload := bytes.NewBufferString(`{"Tty":true}`)
|
||||||
conn, _, err := sockRequestHijack("POST", fmt.Sprintf("/exec/%s/start", execID), payload, "application/json")
|
conn, _, err := sockRequestHijack("POST", fmt.Sprintf("/exec/%s/start", execID), payload, "application/json")
|
||||||
c.Assert(err, check.IsNil)
|
if err != nil {
|
||||||
|
return fmt.Errorf("Failed to start the exec: %q", err.Error())
|
||||||
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
_, rc, err := sockRequestRaw("POST", fmt.Sprintf("/exec/%s/resize?h=24&w=80", execID), nil, "text/plain")
|
_, rc, err := sockRequestRaw("POST", fmt.Sprintf("/exec/%s/resize?h=24&w=80", execID), nil, "text/plain")
|
||||||
// It's probably a panic of the daemon if io.ErrUnexpectedEOF is returned.
|
// It's probably a panic of the daemon if io.ErrUnexpectedEOF is returned.
|
||||||
if err == io.ErrUnexpectedEOF {
|
if err == io.ErrUnexpectedEOF {
|
||||||
c.Fatal("The daemon might have crashed.")
|
return fmt.Errorf("The daemon might have crashed.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
rc.Close()
|
rc.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// We only interested in the io.ErrUnexpectedEOF error, so we return nil otherwise.
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// The panic happens when daemon.ContainerExecStart is called but the
|
||||||
|
// container.Exec is not called.
|
||||||
|
// Because the panic is not 100% reproducible, we send the requests concurrently
|
||||||
|
// to increase the probability that the problem is triggered.
|
||||||
|
var (
|
||||||
|
n = 10
|
||||||
|
ch = make(chan error, n)
|
||||||
|
wg sync.WaitGroup
|
||||||
|
)
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
if err := testExecResize(); err != nil {
|
||||||
|
ch <- err
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < n; i++ {
|
wg.Wait()
|
||||||
<-ch
|
select {
|
||||||
|
case err := <-ch:
|
||||||
|
c.Fatal(err.Error())
|
||||||
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue