Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
e0533b04
Commit
e0533b04
authored
Apr 14, 2011
by
Brad Fitzpatrick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http: fix race in transport_test
R=rsc CC=golang-dev
https://golang.org/cl/4414044
parent
3441bda9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
8 deletions
+20
-8
transport_test.go
src/pkg/http/transport_test.go
+20
-8
No files found.
src/pkg/http/transport_test.go
View file @
e0533b04
...
...
@@ -179,35 +179,47 @@ func TestTransportIdleCacheKeys(t *testing.T) {
}
func
TestTransportMaxPerHostIdleConns
(
t
*
testing
.
T
)
{
ch
:=
make
(
chan
string
)
resch
:=
make
(
chan
string
)
gotReq
:=
make
(
chan
bool
)
ts
:=
httptest
.
NewServer
(
HandlerFunc
(
func
(
w
ResponseWriter
,
r
*
Request
)
{
w
.
Write
([]
byte
(
<-
ch
))
gotReq
<-
true
msg
:=
<-
resch
_
,
err
:=
w
.
Write
([]
byte
(
msg
))
if
err
!=
nil
{
t
.
Fatalf
(
"Write: %v"
,
err
)
}
}))
defer
ts
.
Close
()
maxIdleConns
:=
2
tr
:=
&
Transport
{
DisableKeepAlives
:
false
,
MaxIdleConnsPerHost
:
maxIdleConns
}
c
:=
&
Client
{
Transport
:
tr
}
// Start 3 outstanding requests
(will hang until we write to
//
ch)
// Start 3 outstanding requests
and wait for the server to get them.
//
Their responses will hang until we we write to resch, though.
donech
:=
make
(
chan
bool
)
doReq
:=
func
()
{
resp
,
_
,
err
:=
c
.
Get
(
ts
.
URL
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
ioutil
.
ReadAll
(
resp
.
Body
)
_
,
err
=
ioutil
.
ReadAll
(
resp
.
Body
)
if
err
!=
nil
{
t
.
Fatalf
(
"ReadAll: %v"
,
err
)
}
donech
<-
true
}
go
doReq
()
<-
gotReq
go
doReq
()
<-
gotReq
go
doReq
()
<-
gotReq
if
e
,
g
:=
0
,
len
(
tr
.
IdleConnKeysForTesting
());
e
!=
g
{
t
.
Fatalf
(
"Before writes, expected %d idle conn cache keys; got %d"
,
e
,
g
)
}
ch
<-
"res1"
res
ch
<-
"res1"
<-
donech
keys
:=
tr
.
IdleConnKeysForTesting
()
if
e
,
g
:=
1
,
len
(
keys
);
e
!=
g
{
...
...
@@ -221,13 +233,13 @@ func TestTransportMaxPerHostIdleConns(t *testing.T) {
t
.
Errorf
(
"after first response, expected %d idle conns; got %d"
,
e
,
g
)
}
ch
<-
"res2"
res
ch
<-
"res2"
<-
donech
if
e
,
g
:=
2
,
tr
.
IdleConnCountForTesting
(
cacheKey
);
e
!=
g
{
t
.
Errorf
(
"after second response, expected %d idle conns; got %d"
,
e
,
g
)
}
ch
<-
"res3"
res
ch
<-
"res3"
<-
donech
if
e
,
g
:=
maxIdleConns
,
tr
.
IdleConnCountForTesting
(
cacheKey
);
e
!=
g
{
t
.
Errorf
(
"after third response, still expected %d idle conns; got %d"
,
e
,
g
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment