Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 9532b18

Browse files
committed
Rename spdy.Pipe for unit tests
Only use spdy.Pipe for unit tests and rename as testPipe. The test pipe requires using a default stream provider and codec which should not be imported by the top level package. Signed-off-by: Derek McGowan <[email protected]> (github: dmcgowan)
1 parent f6cb985 commit 9532b18

File tree

4 files changed

+46
-56
lines changed

4 files changed

+46
-56
lines changed

spdy/bench_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ import (
1010
"github.com/docker/libchan"
1111
)
1212

13-
var (
14-
testPipe = Pipe
15-
)
16-
1713
type SimpleStruct struct {
1814
Value int
1915
}

spdy/pipe.go

Lines changed: 0 additions & 49 deletions
This file was deleted.

spdy/pipe_test.go

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,51 @@ import (
99
"time"
1010

1111
"github.com/docker/libchan"
12+
"github.com/docker/libchan/encoding/msgpack"
1213
)
1314

15+
// testPipe creates a top-level channel pipe using an in memory
16+
// transport using spdy and msgpack
17+
func testPipe() (libchan.Receiver, libchan.Sender, error) {
18+
c1, c2 := net.Pipe()
19+
20+
s1, err := NewSpdyStreamProvider(c1, false)
21+
if err != nil {
22+
return nil, nil, err
23+
}
24+
t1 := NewTransport(s1, &msgpack.Codec{})
25+
26+
s2, err := NewSpdyStreamProvider(c2, true)
27+
if err != nil {
28+
return nil, nil, err
29+
}
30+
t2 := NewTransport(s2, &msgpack.Codec{})
31+
32+
var recv libchan.Receiver
33+
waitError := make(chan error)
34+
35+
go func() {
36+
var err error
37+
recv, err = t2.WaitReceiveChannel()
38+
waitError <- err
39+
}()
40+
41+
send, senderErr := t1.NewSendChannel()
42+
if senderErr != nil {
43+
c1.Close()
44+
c2.Close()
45+
return nil, nil, senderErr
46+
}
47+
48+
receiveErr := <-waitError
49+
if receiveErr != nil {
50+
c1.Close()
51+
c2.Close()
52+
return nil, nil, receiveErr
53+
}
54+
return recv, send, nil
55+
}
56+
1457
type PipeMessage struct {
1558
Message string
1659
Stream io.ReadWriteCloser
@@ -107,7 +150,7 @@ func SpawnPipeTest(t *testing.T, client PipeSenderRoutine, server PipeReceiverRo
107150
endClient := make(chan bool)
108151
endServer := make(chan bool)
109152

110-
receiver, sender, err := Pipe()
153+
receiver, sender, err := testPipe()
111154
if err != nil {
112155
t.Fatalf("Error creating pipe: %s", err)
113156
}

spdy/proxy_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ func SpawnProxyTest(t *testing.T, client PipeSenderRoutine, server PipeReceiverR
136136
endServer := make(chan bool)
137137
endProxy := make(chan bool)
138138

139-
receiver1, sender1, err := Pipe()
140-
receiver2, sender2, err := Pipe()
139+
receiver1, sender1, err := testPipe()
140+
receiver2, sender2, err := testPipe()
141141

142142
if err != nil {
143143
t.Fatalf("Error creating pipe: %s", err)

0 commit comments

Comments
 (0)