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
e63fcd61
Commit
e63fcd61
authored
Oct 10, 2011
by
Brad Fitzpatrick
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http: cancel test timers; don't t.Fatalf in other goroutines
R=rsc CC=golang-dev
https://golang.org/cl/5228041
parent
cab53c89
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
38 deletions
+55
-38
serve_test.go
src/pkg/http/serve_test.go
+55
-38
No files found.
src/pkg/http/serve_test.go
View file @
e63fcd61
...
...
@@ -356,18 +356,17 @@ func TestIdentityResponse(t *testing.T) {
if
err
!=
nil
{
t
.
Fatalf
(
"error writing: %v"
,
err
)
}
// The next ReadAll will hang for a failing test, so use a Timer instead
// to fail more traditionally
timer
:=
time
.
AfterFunc
(
2e9
,
func
()
{
t
.
Fatalf
(
"Timeout expired in ReadAll."
)
// The ReadAll will hang for a failing test, so use a Timer to
// fail explicitly.
goTimeout
(
t
,
2e9
,
func
()
{
got
,
_
:=
ioutil
.
ReadAll
(
conn
)
expectedSuffix
:=
"
\r\n\r\n
too short"
if
!
strings
.
HasSuffix
(
string
(
got
),
expectedSuffix
)
{
t
.
Errorf
(
"Expected output to end with %q; got response body %q"
,
expectedSuffix
,
string
(
got
))
}
})
defer
timer
.
Stop
()
got
,
_
:=
ioutil
.
ReadAll
(
conn
)
expectedSuffix
:=
"
\r\n\r\n
too short"
if
!
strings
.
HasSuffix
(
string
(
got
),
expectedSuffix
)
{
t
.
Fatalf
(
"Expected output to end with %q; got response body %q"
,
expectedSuffix
,
string
(
got
))
}
}
func
testTcpConnectionCloses
(
t
*
testing
.
T
,
req
string
,
h
Handler
)
{
...
...
@@ -549,14 +548,13 @@ func TestTLSHandshakeTimeout(t *testing.T) {
t
.
Fatalf
(
"Dial: %v"
,
err
)
}
defer
conn
.
Close
()
timer
:=
time
.
AfterFunc
(
10e9
,
func
()
{
t
.
Fatalf
(
"Timeout"
)
})
defer
timer
.
Stop
()
var
buf
[
1
]
byte
n
,
err
:=
conn
.
Read
(
buf
[
:
])
if
err
==
nil
||
n
!=
0
{
t
.
Errorf
(
"Read = %d, %v; want an error and no bytes"
,
n
,
err
)
}
goTimeout
(
t
,
10e9
,
func
()
{
var
buf
[
1
]
byte
n
,
err
:=
conn
.
Read
(
buf
[
:
])
if
err
==
nil
||
n
!=
0
{
t
.
Errorf
(
"Read = %d, %v; want an error and no bytes"
,
n
,
err
)
}
})
}
func
TestTLSServer
(
t
*
testing
.
T
)
{
...
...
@@ -580,25 +578,29 @@ func TestTLSServer(t *testing.T) {
t
.
Fatalf
(
"Dial: %v"
,
err
)
}
defer
idleConn
.
Close
()
time
.
AfterFunc
(
10e9
,
func
()
{
t
.
Fatalf
(
"Timeout"
)
})
if
!
strings
.
HasPrefix
(
ts
.
URL
,
"https://"
)
{
t
.
Fatalf
(
"expected test TLS server to start with https://, got %q"
,
ts
.
URL
)
}
res
,
err
:=
Get
(
ts
.
URL
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
res
==
nil
{
t
.
Fatalf
(
"got nil Response"
)
}
defer
res
.
Body
.
Close
()
if
res
.
Header
.
Get
(
"X-TLS-Set"
)
!=
"true"
{
t
.
Errorf
(
"expected X-TLS-Set response header"
)
}
if
res
.
Header
.
Get
(
"X-TLS-HandshakeComplete"
)
!=
"true"
{
t
.
Errorf
(
"expected X-TLS-HandshakeComplete header"
)
}
goTimeout
(
t
,
10e9
,
func
()
{
if
!
strings
.
HasPrefix
(
ts
.
URL
,
"https://"
)
{
t
.
Errorf
(
"expected test TLS server to start with https://, got %q"
,
ts
.
URL
)
return
}
res
,
err
:=
Get
(
ts
.
URL
)
if
err
!=
nil
{
t
.
Error
(
err
)
return
}
if
res
==
nil
{
t
.
Errorf
(
"got nil Response"
)
return
}
defer
res
.
Body
.
Close
()
if
res
.
Header
.
Get
(
"X-TLS-Set"
)
!=
"true"
{
t
.
Errorf
(
"expected X-TLS-Set response header"
)
return
}
if
res
.
Header
.
Get
(
"X-TLS-HandshakeComplete"
)
!=
"true"
{
t
.
Errorf
(
"expected X-TLS-HandshakeComplete header"
)
}
})
}
type
serverExpectTest
struct
{
...
...
@@ -1019,6 +1021,21 @@ func TestClientWriteShutdown(t *testing.T) {
}
}
// goTimeout runs f, failing t if f takes more than ns to complete.
func
goTimeout
(
t
*
testing
.
T
,
ns
int64
,
f
func
())
{
ch
:=
make
(
chan
bool
,
2
)
timer
:=
time
.
AfterFunc
(
ns
,
func
()
{
t
.
Errorf
(
"Timeout expired after %d ns"
,
ns
)
ch
<-
true
})
defer
timer
.
Stop
()
go
func
()
{
defer
func
()
{
ch
<-
true
}()
f
()
}()
<-
ch
}
type
errorListener
struct
{
errs
[]
os
.
Error
}
...
...
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