mirror of
https://github.com/golang/go
synced 2024-11-25 10:07:56 -07:00
various: a grab-bag of time.Duration cleanups.
R=adg, r, rsc CC=golang-dev https://golang.org/cl/5475069
This commit is contained in:
parent
fc7b9fc269
commit
3dbecd592b
@ -53,6 +53,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -767,7 +768,7 @@ func canonical(w string) string { return strings.ToLower(w) }
|
|||||||
//
|
//
|
||||||
func NewIndex(dirnames <-chan string, fulltextIndex bool, throttle float64) *Index {
|
func NewIndex(dirnames <-chan string, fulltextIndex bool, throttle float64) *Index {
|
||||||
var x Indexer
|
var x Indexer
|
||||||
th := NewThrottle(throttle, 0.1e9) // run at least 0.1s at a time
|
th := NewThrottle(throttle, 100*time.Millisecond) // run at least 0.1s at a time
|
||||||
|
|
||||||
// initialize Indexer
|
// initialize Indexer
|
||||||
// (use some reasonably sized maps to start)
|
// (use some reasonably sized maps to start)
|
||||||
|
@ -57,7 +57,7 @@ func TestInotifyEvents(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We expect this event to be received almost immediately, but let's wait 1 s to be sure
|
// We expect this event to be received almost immediately, but let's wait 1 s to be sure
|
||||||
time.Sleep(1000e6) // 1000 ms
|
time.Sleep(1 * time.Second)
|
||||||
if eventsReceived == 0 {
|
if eventsReceived == 0 {
|
||||||
t.Fatal("inotify event hasn't been received after 1 second")
|
t.Fatal("inotify event hasn't been received after 1 second")
|
||||||
}
|
}
|
||||||
@ -69,7 +69,7 @@ func TestInotifyEvents(t *testing.T) {
|
|||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
t.Log("event channel closed")
|
t.Log("event channel closed")
|
||||||
case <-time.After(1e9):
|
case <-time.After(1 * time.Second):
|
||||||
t.Fatal("event stream was not closed after 1 second")
|
t.Fatal("event stream was not closed after 1 second")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ func TestInotifyClose(t *testing.T) {
|
|||||||
done = true
|
done = true
|
||||||
}()
|
}()
|
||||||
|
|
||||||
time.Sleep(50e6) // 50 ms
|
time.Sleep(50 * time.Millisecond)
|
||||||
if !done {
|
if !done {
|
||||||
t.Fatal("double Close() test failed: second Close() call didn't return")
|
t.Fatal("double Close() test failed: second Close() call didn't return")
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,7 @@ func PerformanceTest() {
|
|||||||
norm.NFC.Append(nil, buf...)
|
norm.NFC.Append(nil, buf...)
|
||||||
success <- true
|
success <- true
|
||||||
}()
|
}()
|
||||||
timeout := time.After(1e9)
|
timeout := time.After(1 * time.Second)
|
||||||
select {
|
select {
|
||||||
case <-success:
|
case <-success:
|
||||||
// test completed before the timeout
|
// test completed before the timeout
|
||||||
|
@ -21,7 +21,7 @@ func expect(t *testing.T, eventstream <-chan *Event, name string, mask uint32) {
|
|||||||
if event.Name != name || event.Mask != mask {
|
if event.Name != name || event.Mask != mask {
|
||||||
t.Fatal("did not receive expected event")
|
t.Fatal("did not receive expected event")
|
||||||
}
|
}
|
||||||
case <-time.After(1e9):
|
case <-time.After(1 * time.Second):
|
||||||
t.Fatal("timed out waiting for event")
|
t.Fatal("timed out waiting for event")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ func TestNotifyClose(t *testing.T) {
|
|||||||
done = true
|
done = true
|
||||||
}()
|
}()
|
||||||
|
|
||||||
time.Sleep(50e6) // 50 ms
|
time.Sleep(50 * time.Millisecond)
|
||||||
if !done {
|
if !done {
|
||||||
t.Fatal("double Close() test failed: second Close() call didn't return")
|
t.Fatal("double Close() test failed: second Close() call didn't return")
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ func check(t *testing.T, source, golden string, mode checkMode) {
|
|||||||
// start a timer to produce a time-out signal
|
// start a timer to produce a time-out signal
|
||||||
tc := make(chan int)
|
tc := make(chan int)
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(10e9) // plenty of a safety margin, even for very slow machines
|
time.Sleep(10 * time.Second) // plenty of a safety margin, even for very slow machines
|
||||||
tc <- 0
|
tc <- 0
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ var pipeTests = []pipeTest{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func delayClose(t *testing.T, cl closer, ch chan int, tt pipeTest) {
|
func delayClose(t *testing.T, cl closer, ch chan int, tt pipeTest) {
|
||||||
time.Sleep(1e6) // 1 ms
|
time.Sleep(1 * time.Millisecond)
|
||||||
var err error
|
var err error
|
||||||
if tt.closeWithError {
|
if tt.closeWithError {
|
||||||
err = cl.CloseWithError(tt.err)
|
err = cl.CloseWithError(tt.err)
|
||||||
|
@ -70,8 +70,8 @@ custom Server:
|
|||||||
s := &http.Server{
|
s := &http.Server{
|
||||||
Addr: ":8080",
|
Addr: ":8080",
|
||||||
Handler: myHandler,
|
Handler: myHandler,
|
||||||
ReadTimeout: 10e9,
|
ReadTimeout: 10 * time.Second,
|
||||||
WriteTimeout: 10e9,
|
WriteTimeout: 10 * time.Second,
|
||||||
MaxHeaderBytes: 1 << 20,
|
MaxHeaderBytes: 1 << 20,
|
||||||
}
|
}
|
||||||
log.Fatal(s.ListenAndServe())
|
log.Fatal(s.ListenAndServe())
|
||||||
|
@ -538,7 +538,7 @@ func TestHeadResponses(t *testing.T) {
|
|||||||
|
|
||||||
func TestTLSHandshakeTimeout(t *testing.T) {
|
func TestTLSHandshakeTimeout(t *testing.T) {
|
||||||
ts := httptest.NewUnstartedServer(HandlerFunc(func(w ResponseWriter, r *Request) {}))
|
ts := httptest.NewUnstartedServer(HandlerFunc(func(w ResponseWriter, r *Request) {}))
|
||||||
ts.Config.ReadTimeout = 250e6
|
ts.Config.ReadTimeout = 250 * time.Millisecond
|
||||||
ts.StartTLS()
|
ts.StartTLS()
|
||||||
defer ts.Close()
|
defer ts.Close()
|
||||||
conn, err := net.Dial("tcp", ts.Listener.Addr().String())
|
conn, err := net.Dial("tcp", ts.Listener.Addr().String())
|
||||||
|
@ -952,11 +952,11 @@ func Serve(l net.Listener, handler Handler) error {
|
|||||||
|
|
||||||
// A Server defines parameters for running an HTTP server.
|
// A Server defines parameters for running an HTTP server.
|
||||||
type Server struct {
|
type Server struct {
|
||||||
Addr string // TCP address to listen on, ":http" if empty
|
Addr string // TCP address to listen on, ":http" if empty
|
||||||
Handler Handler // handler to invoke, http.DefaultServeMux if nil
|
Handler Handler // handler to invoke, http.DefaultServeMux if nil
|
||||||
ReadTimeout int64 // the net.Conn.SetReadTimeout value for new connections
|
ReadTimeout time.Duration // the net.Conn.SetReadTimeout value for new connections
|
||||||
WriteTimeout int64 // the net.Conn.SetWriteTimeout value for new connections
|
WriteTimeout time.Duration // the net.Conn.SetWriteTimeout value for new connections
|
||||||
MaxHeaderBytes int // maximum size of request headers, DefaultMaxHeaderBytes if 0
|
MaxHeaderBytes int // maximum size of request headers, DefaultMaxHeaderBytes if 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListenAndServe listens on the TCP network address srv.Addr and then
|
// ListenAndServe listens on the TCP network address srv.Addr and then
|
||||||
@ -989,10 +989,10 @@ func (srv *Server) Serve(l net.Listener) error {
|
|||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
if srv.ReadTimeout != 0 {
|
if srv.ReadTimeout != 0 {
|
||||||
rw.SetReadTimeout(srv.ReadTimeout)
|
rw.SetReadTimeout(srv.ReadTimeout.Nanoseconds())
|
||||||
}
|
}
|
||||||
if srv.WriteTimeout != 0 {
|
if srv.WriteTimeout != 0 {
|
||||||
rw.SetWriteTimeout(srv.WriteTimeout)
|
rw.SetWriteTimeout(srv.WriteTimeout.Nanoseconds())
|
||||||
}
|
}
|
||||||
c, err := srv.newConn(rw)
|
c, err := srv.newConn(rw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -292,7 +292,7 @@ func TestTransportServerClosingUnexpectedly(t *testing.T) {
|
|||||||
// it on most fast machines, causing the next fetch() call to
|
// it on most fast machines, causing the next fetch() call to
|
||||||
// succeed quickly. But if we do get errors, fetch() will retry 5
|
// succeed quickly. But if we do get errors, fetch() will retry 5
|
||||||
// times with some delays between.
|
// times with some delays between.
|
||||||
time.Sleep(25e6)
|
time.Sleep(25 * time.Millisecond)
|
||||||
|
|
||||||
body3 := fetch(3, 5)
|
body3 := fetch(3, 5)
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
second = 1e9
|
|
||||||
newHttpPath = "/foo"
|
newHttpPath = "/foo"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -388,12 +387,12 @@ func (WriteFailCodec) WriteRequest(*Request, interface{}) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (WriteFailCodec) ReadResponseHeader(*Response) error {
|
func (WriteFailCodec) ReadResponseHeader(*Response) error {
|
||||||
time.Sleep(120e9)
|
time.Sleep(120 * time.Second)
|
||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (WriteFailCodec) ReadResponseBody(interface{}) error {
|
func (WriteFailCodec) ReadResponseBody(interface{}) error {
|
||||||
time.Sleep(120e9)
|
time.Sleep(120 * time.Second)
|
||||||
panic("unreachable")
|
panic("unreachable")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,7 +412,7 @@ func TestSendDeadlock(t *testing.T) {
|
|||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
return
|
return
|
||||||
case <-time.After(5e9):
|
case <-time.After(5 * time.Second):
|
||||||
t.Fatal("deadlock")
|
t.Fatal("deadlock")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ func (cs *clientSet) drain(timeout time.Duration) error {
|
|||||||
if timeout > 0 && time.Now().After(deadline) {
|
if timeout > 0 && time.Now().After(deadline) {
|
||||||
return errors.New("timeout")
|
return errors.New("timeout")
|
||||||
}
|
}
|
||||||
time.Sleep(100 * 1e6) // 100 milliseconds
|
time.Sleep(100 * time.Millisecond)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -188,7 +188,7 @@ func (cs *clientSet) sync(timeout time.Duration) error {
|
|||||||
if timeout > 0 && time.Now().After(deadline) {
|
if timeout > 0 && time.Now().After(deadline) {
|
||||||
return errors.New("timeout")
|
return errors.New("timeout")
|
||||||
}
|
}
|
||||||
time.Sleep(100 * 1e6) // 100 milliseconds
|
time.Sleep(100 * time.Millisecond)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -281,7 +281,7 @@ func (imp *Importer) Drain(timeout int64) error {
|
|||||||
if timeout > 0 && time.Now().After(deadline) {
|
if timeout > 0 && time.Now().After(deadline) {
|
||||||
return errors.New("timeout")
|
return errors.New("timeout")
|
||||||
}
|
}
|
||||||
time.Sleep(100 * 1e6)
|
time.Sleep(100 * time.Millisecond)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ func TestErrorForIllegalChannel(t *testing.T) {
|
|||||||
// Expect an error now. Start a timeout.
|
// Expect an error now. Start a timeout.
|
||||||
timeout := make(chan bool, 1) // buffered so closure will not hang around.
|
timeout := make(chan bool, 1) // buffered so closure will not hang around.
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(10e9) // very long, to give even really slow machines a chance.
|
time.Sleep(10 * time.Second) // very long, to give even really slow machines a chance.
|
||||||
timeout <- true
|
timeout <- true
|
||||||
}()
|
}()
|
||||||
select {
|
select {
|
||||||
@ -300,7 +300,7 @@ func TestIndependentSends(t *testing.T) {
|
|||||||
go importReceive(imp, t, done)
|
go importReceive(imp, t, done)
|
||||||
|
|
||||||
// wait for export side to try to deliver some values.
|
// wait for export side to try to deliver some values.
|
||||||
time.Sleep(0.25e9)
|
time.Sleep(250 * time.Millisecond)
|
||||||
|
|
||||||
ctlch := make(chan int)
|
ctlch := make(chan int)
|
||||||
if err := imp.ImportNValues("exportedCtl", ctlch, Send, 1, 1); err != nil {
|
if err := imp.ImportNValues("exportedCtl", ctlch, Send, 1, 1); err != nil {
|
||||||
@ -409,7 +409,7 @@ func TestImportFlowControl(t *testing.T) {
|
|||||||
|
|
||||||
func testFlow(sendDone chan bool, ch <-chan int, N int, t *testing.T) {
|
func testFlow(sendDone chan bool, ch <-chan int, N int, t *testing.T) {
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(0.5e9)
|
time.Sleep(500 * time.Millisecond)
|
||||||
sendDone <- false
|
sendDone <- false
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user