Make it easier to set and unset testing and default timeouts

This commit is contained in:
Matt Joiner
2016-04-21 22:38:16 +10:00
parent 719fbbd05e
commit c452c69132
2 changed files with 22 additions and 5 deletions
+20 -3
View File
@@ -57,12 +57,29 @@ var (
// than the latency we expect on most connections to prevent excessive
// resending to peers that take a long time to respond, before we've got a
// better idea of their actual latency.
initialLatency = 400 * time.Millisecond
initialLatency time.Duration
// If a write isn't acked within this period, destroy the connection.
writeTimeout = 15 * time.Second
packetReadTimeout = 2 * time.Minute
writeTimeout time.Duration
// Assume the connection has been closed by the peer getting no packets of
// any kind for this time.
packetReadTimeout time.Duration
)
func setDefaultDurations() {
// An approximate upper bound for most connections across the world.
initialLatency = 400 * time.Millisecond
// Getting no reply for this period for a packet, we can probably rule out
// latency and client lag.
writeTimeout = 15 * time.Second
// Somewhere longer than the BitTorrent grace period (90-120s), and less
// than default TCP reset (4min).
packetReadTimeout = 2 * time.Minute
}
func init() {
setDefaultDurations()
}
// Strongly-type guarantee of resolved network address.
type resolvedAddrStr string
+2 -2
View File
@@ -21,8 +21,7 @@ import (
"github.com/stretchr/testify/require"
)
func init() {
log.SetFlags(log.Flags() | log.Lshortfile)
func setDefaultTestingDurations() {
writeTimeout = 1 * time.Second
initialLatency = 10 * time.Millisecond
packetReadTimeout = 2 * time.Second
@@ -491,6 +490,7 @@ func TestMain(m *testing.M) {
})
listenPacket = inproc.ListenPacket
resolveAddr = inproc.ResolveAddr
setDefaultTestingDurations()
code := m.Run()
WriteStatus(os.Stderr)
mu.Lock()