mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Engine: slightly more stress-testing of Receiver/Sender to reproduce the hang problem
Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
dfdc03b061
commit
bf25951837
1 changed files with 42 additions and 22 deletions
|
@ -1,6 +1,7 @@
|
||||||
package engine
|
package engine
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/pkg/beam"
|
"github.com/dotcloud/docker/pkg/beam"
|
||||||
|
@ -10,32 +11,51 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHelloWorld(t *testing.T) {
|
func TestHelloWorld(t *testing.T) {
|
||||||
testRemote(t,
|
for i := 0; i < 10; i++ {
|
||||||
|
testRemote(t,
|
||||||
|
|
||||||
// Sender side
|
// Sender side
|
||||||
func(eng *Engine) {
|
func(eng *Engine) {
|
||||||
job := eng.Job("echo", "hello", "world")
|
job := eng.Job("echo", "hello", "world")
|
||||||
out := &bytes.Buffer{}
|
out := &bytes.Buffer{}
|
||||||
job.Stdout.Add(out)
|
job.Stdout.Add(out)
|
||||||
job.Run()
|
job.Run()
|
||||||
if job.status != StatusOK {
|
if job.status != StatusOK {
|
||||||
t.Fatalf("#%v", job.StatusCode())
|
t.Fatalf("#%v", job.StatusCode())
|
||||||
}
|
}
|
||||||
if out.String() != "hello world\n" {
|
lines := bufio.NewScanner(out)
|
||||||
t.Fatalf("%#v", out.String())
|
var i int
|
||||||
}
|
for lines.Scan() {
|
||||||
},
|
if lines.Text() != "hello world" {
|
||||||
|
t.Fatalf("%#v", lines.Text())
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
if i != 1000 {
|
||||||
|
t.Fatalf("%#v", i)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// Receiver side
|
// Receiver side
|
||||||
func(eng *Engine) {
|
func(eng *Engine) {
|
||||||
eng.Register("echo", func(job *Job) Status {
|
eng.Register("echo", func(job *Job) Status {
|
||||||
fmt.Fprintf(job.Stdout, "%s\n", strings.Join(job.Args, " "))
|
// Simulate more output with a delay in the middle
|
||||||
return StatusOK
|
for i := 0; i < 500; i++ {
|
||||||
})
|
fmt.Fprintf(job.Stdout, "%s\n", strings.Join(job.Args, " "))
|
||||||
},
|
}
|
||||||
)
|
time.Sleep(5 * time.Millisecond)
|
||||||
|
for i := 0; i < 500; i++ {
|
||||||
|
fmt.Fprintf(job.Stdout, "%s\n", strings.Join(job.Args, " "))
|
||||||
|
}
|
||||||
|
return StatusOK
|
||||||
|
})
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Helpers
|
||||||
|
|
||||||
func testRemote(t *testing.T, senderSide, receiverSide func(*Engine)) {
|
func testRemote(t *testing.T, senderSide, receiverSide func(*Engine)) {
|
||||||
sndConn, rcvConn, err := beam.USocketPair()
|
sndConn, rcvConn, err := beam.USocketPair()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue