X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=client_test.go;h=d2a88e9e7a769abcd1871092c006e37b33573a51;hb=HEAD;hp=c86243956ab5e8a9b93184c5561490c890b7a52f;hpb=599846546ec6e34036de889a4f41ea3f579153a3;p=btrtrc.git diff --git a/client_test.go b/client_test.go index c8624395..d2a88e9e 100644 --- a/client_test.go +++ b/client_test.go @@ -13,15 +13,14 @@ import ( "testing/iotest" "time" - "github.com/frankban/quicktest" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "github.com/anacrolix/log" - "github.com/anacrolix/dht/v2" + "github.com/anacrolix/log" "github.com/anacrolix/missinggo/v2" "github.com/anacrolix/missinggo/v2/filecache" + "github.com/frankban/quicktest" + qt "github.com/frankban/quicktest" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "github.com/anacrolix/torrent/bencode" "github.com/anacrolix/torrent/internal/testutil" @@ -593,6 +592,7 @@ func TestPieceCompletedInStorageButNotClient(t *testing.T) { cfg.DataDir = greetingTempDir seeder, err := NewClient(TestingConfig(t)) require.NoError(t, err) + defer seeder.Close() seeder.AddTorrentSpec(&TorrentSpec{ InfoBytes: greetingMetainfo.InfoBytes, }) @@ -788,13 +788,16 @@ func TestObfuscatedHeaderFallbackSeederRequiresLeecherPrefersNot(t *testing.T) { } func TestClientAddressInUse(t *testing.T) { - s, _ := NewUtpSocket("udp", ":50007", nil, log.Default) + s, _ := NewUtpSocket("udp", "localhost:50007", nil, log.Default) if s != nil { defer s.Close() } - cfg := TestingConfig(t).SetListenAddr(":50007") + cfg := TestingConfig(t).SetListenAddr("localhost:50007") cfg.DisableUTP = false cl, err := NewClient(cfg) + if err == nil { + assert.Nil(t, cl.Close()) + } require.Error(t, err) require.Nil(t, cl) } @@ -891,3 +894,16 @@ func TestBadPeerIpPort(t *testing.T) { }) } } + +// https://github.com/anacrolix/torrent/issues/837 +func TestClientConfigSetHandlerNotIgnored(t *testing.T) { + cfg := TestingConfig(t) + cfg.Logger.SetHandlers(log.DiscardHandler) + c := qt.New(t) + cl, err := NewClient(cfg) + c.Assert(err, qt.IsNil) + defer cl.Close() + c.Assert(cl.logger.Handlers, qt.HasLen, 1) + h := cl.logger.Handlers[0].(log.StreamHandler) + c.Check(h.W, qt.Equals, io.Discard) +}