-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from euank/join-halfclose
Propagate half-closes correctly in forward
- Loading branch information
Showing
2 changed files
with
58 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package ngrok | ||
|
||
import ( | ||
"errors" | ||
"io" | ||
"net" | ||
"testing" | ||
|
||
"github.com/inconshreveable/log15/v3" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestHalfCloseJoin(t *testing.T) { | ||
srv, err := net.Listen("tcp", "127.0.0.1:0") | ||
require.NoError(t, err) | ||
|
||
waitSrvConn := make(chan net.Conn) | ||
go func() { | ||
srvConn, err := srv.Accept() | ||
if err != nil { | ||
panic(err) | ||
} | ||
waitSrvConn <- srvConn | ||
}() | ||
|
||
browser, ngrokEndpoint := net.Pipe() | ||
agent, userService := net.Pipe() | ||
|
||
waitJoinDone := make(chan struct{}) | ||
go func() { | ||
defer close(waitJoinDone) | ||
join(log15.New(), ngrokEndpoint, agent) | ||
}() | ||
|
||
_, err = browser.Write([]byte("hello world")) | ||
require.NoError(t, err) | ||
var b [len("hello world")]byte | ||
_, err = userService.Read(b[:]) | ||
require.NoError(t, err) | ||
require.Equal(t, []byte("hello world"), b[:]) | ||
browser.Close() | ||
_, err = userService.Read(b[:]) | ||
require.Truef(t, errors.Is(err, io.EOF), "io.EOF expected, got %v", err) | ||
|
||
<-waitJoinDone | ||
} |