Signed-off-by: Antonio Murdaca <me@runcom.ninja>
| ... | ... |
@@ -40,24 +40,38 @@ func (s *DockerSuite) TestGetContainersAttachWebsocket(c *check.C) {
|
| 40 | 40 |
|
| 41 | 41 |
expected := []byte("hello")
|
| 42 | 42 |
actual := make([]byte, len(expected)) |
| 43 |
- outChan := make(chan string) |
|
| 43 |
+ |
|
| 44 |
+ outChan := make(chan error) |
|
| 44 | 45 |
go func() {
|
| 45 |
- if _, err := ws.Read(actual); err != nil {
|
|
| 46 |
- c.Fatal(err) |
|
| 47 |
- } |
|
| 48 |
- outChan <- "done" |
|
| 46 |
+ _, err := ws.Read(actual) |
|
| 47 |
+ outChan <- err |
|
| 48 |
+ close(outChan) |
|
| 49 | 49 |
}() |
| 50 | 50 |
|
| 51 |
- inChan := make(chan string) |
|
| 51 |
+ inChan := make(chan error) |
|
| 52 | 52 |
go func() {
|
| 53 |
- if _, err := ws.Write(expected); err != nil {
|
|
| 53 |
+ _, err := ws.Write(expected) |
|
| 54 |
+ inChan <- err |
|
| 55 |
+ close(inChan) |
|
| 56 |
+ }() |
|
| 57 |
+ |
|
| 58 |
+ select {
|
|
| 59 |
+ case err := <-inChan: |
|
| 60 |
+ if err != nil {
|
|
| 54 | 61 |
c.Fatal(err) |
| 55 | 62 |
} |
| 56 |
- inChan <- "done" |
|
| 57 |
- }() |
|
| 63 |
+ case <-time.After(5 * time.Second): |
|
| 64 |
+ c.Fatal("Timeout writing to ws")
|
|
| 65 |
+ } |
|
| 58 | 66 |
|
| 59 |
- <-inChan |
|
| 60 |
- <-outChan |
|
| 67 |
+ select {
|
|
| 68 |
+ case err := <-outChan: |
|
| 69 |
+ if err != nil {
|
|
| 70 |
+ c.Fatal(err) |
|
| 71 |
+ } |
|
| 72 |
+ case <-time.After(5 * time.Second): |
|
| 73 |
+ c.Fatal("Timeout reading from ws")
|
|
| 74 |
+ } |
|
| 61 | 75 |
|
| 62 | 76 |
if !bytes.Equal(expected, actual) {
|
| 63 | 77 |
c.Fatal("Expected output on websocket to match input")
|