Use different keep alive timeout in tests

Exposes bug found in email discussions resulting from https://github.com/anacrolix/torrent/discussions/547.
This commit is contained in:
Matt Joiner 2021-08-18 11:27:21 +10:00
parent 16176b762e
commit dcb2e5b53b
3 changed files with 7 additions and 1 deletions

View File

@ -118,6 +118,9 @@ type ClientConfig struct {
// impact of a few bad apples. 4s loses 1% of successful handshakes that
// are obtained with 60s timeout, and 5% of unsuccessful handshakes.
HandshakesTimeout time.Duration
// How long between writes before sending a keep alive message on a peer connection that we want
// to maintain.
KeepAliveTimeout time.Duration
// The IP addresses as our peers should see them. May differ from the
// local interfaces due to NAT or other network configurations.
@ -170,6 +173,7 @@ func NewDefaultClientConfig() *ClientConfig {
TorrentPeersHighWater: 500,
TorrentPeersLowWater: 50,
HandshakesTimeout: 4 * time.Second,
KeepAliveTimeout: time.Minute,
DhtStartingNodes: func(network string) dht.StartingNodesGetter {
return func() ([]dht.Addr, error) { return dht.GlobalBootstrapAddrs(network) }
},

View File

@ -37,7 +37,7 @@ func (pc *PeerConn) startWriter() {
defer pc.locker().Unlock()
defer pc.close()
defer pc.locker().Lock()
pc.messageWriter.run(time.Minute)
pc.messageWriter.run(pc.t.cl.config.KeepAliveTimeout)
}()
}

View File

@ -2,6 +2,7 @@ package torrent
import (
"testing"
"time"
)
func TestingConfig(t testing.TB) *ClientConfig {
@ -13,6 +14,7 @@ func TestingConfig(t testing.TB) *ClientConfig {
cfg.NoDefaultPortForwarding = true
cfg.DisableAcceptRateLimiting = true
cfg.ListenPort = 0
cfg.KeepAliveTimeout = time.Microsecond
//cfg.Debug = true
//cfg.Logger = cfg.Logger.WithText(func(m log.Msg) string {
// t := m.Text()