mirror of
https://github.com/golang/go
synced 2024-11-16 22:24:47 -07:00
net/http/fcgi: Add test demonstrating race condition
This commit is contained in:
parent
7214ac877c
commit
b3976111ae
@ -11,6 +11,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var sizeTests = []struct {
|
var sizeTests = []struct {
|
||||||
@ -395,3 +396,55 @@ func TestResponseWriterSniffsContentType(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type signallingNopCloser struct {
|
||||||
|
io.Reader
|
||||||
|
closed chan bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*signallingNopCloser) Write(buf []byte) (int, error) {
|
||||||
|
return len(buf), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rc *signallingNopCloser) Close() error {
|
||||||
|
close(rc.closed)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test whether server properly closes connection when processing slow
|
||||||
|
// requests
|
||||||
|
func TestSlowRequest(t *testing.T) {
|
||||||
|
pr, pw := io.Pipe()
|
||||||
|
go func(w io.Writer) {
|
||||||
|
for _, buf := range [][]byte{
|
||||||
|
streamBeginTypeStdin,
|
||||||
|
makeRecord(typeStdin, 1, nil),
|
||||||
|
} {
|
||||||
|
pw.Write(buf)
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}(pw)
|
||||||
|
|
||||||
|
rc := &signallingNopCloser{pr, make(chan bool)}
|
||||||
|
handlerDone := make(chan bool)
|
||||||
|
|
||||||
|
c := newChild(rc, http.HandlerFunc(func(
|
||||||
|
w http.ResponseWriter,
|
||||||
|
r *http.Request,
|
||||||
|
) {
|
||||||
|
w.WriteHeader(200)
|
||||||
|
close(handlerDone)
|
||||||
|
}))
|
||||||
|
go c.serve()
|
||||||
|
defer c.cleanUp()
|
||||||
|
|
||||||
|
timeout := time.After(2 * time.Second)
|
||||||
|
|
||||||
|
<-handlerDone
|
||||||
|
select {
|
||||||
|
case <-rc.closed:
|
||||||
|
t.Log("FastCGI child closed connection")
|
||||||
|
case <-timeout:
|
||||||
|
t.Error("FastCGI child did not close socket after handling request")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user