testing.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package torrent
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/anacrolix/log"
  6. pp "github.com/anacrolix/torrent/peer_protocol"
  7. )
  8. func TestingConfig(t testing.TB) *ClientConfig {
  9. cfg := NewDefaultClientConfig()
  10. cfg.ListenHost = LoopbackListenHost
  11. cfg.NoDHT = true
  12. cfg.DataDir = t.TempDir()
  13. cfg.DisableTrackers = true
  14. cfg.NoDefaultPortForwarding = true
  15. cfg.DisableAcceptRateLimiting = true
  16. cfg.ListenPort = 0
  17. cfg.KeepAliveTimeout = time.Millisecond
  18. cfg.MinPeerExtensions.SetBit(pp.ExtensionBitFast, true)
  19. cfg.Logger = log.Default.WithNames(t.Name())
  20. // 2 would suffice for the greeting test, but 5 is needed for a few other tests. This should be
  21. // something slightly higher than the usual chunk size, so it gets tickled in some tests.
  22. cfg.MaxAllocPeerRequestDataPerConn = 5
  23. //cfg.Debug = true
  24. //cfg.Logger = cfg.Logger.WithText(func(m log.Msg) string {
  25. // t := m.Text()
  26. // m.Values(func(i interface{}) bool {
  27. // t += fmt.Sprintf("\n%[1]T: %[1]v", i)
  28. // return true
  29. // })
  30. // return t
  31. //})
  32. return cfg
  33. }