2
0
mirror of synced 2025-02-23 14:18:13 +00:00
This commit is contained in:
Matt Joiner 2020-05-19 14:59:45 +10:00
parent 26d7034d72
commit f6c757ca65

View File

@ -30,6 +30,8 @@ type testClientTransferParams struct {
LeecherDownloadRateLimiter *rate.Limiter LeecherDownloadRateLimiter *rate.Limiter
ConfigureSeeder ConfigureClient ConfigureSeeder ConfigureClient
ConfigureLeecher ConfigureClient ConfigureLeecher ConfigureClient
LeecherStartsWithoutMetadata bool
} }
func assertReadAllGreeting(t *testing.T, r io.ReadSeeker) { func assertReadAllGreeting(t *testing.T, r io.ReadSeeker) {
@ -108,6 +110,9 @@ func testClientTransfer(t *testing.T, ps testClientTransferParams) {
leecherTorrent, new, err := leecher.AddTorrentSpec(func() (ret *torrent.TorrentSpec) { leecherTorrent, new, err := leecher.AddTorrentSpec(func() (ret *torrent.TorrentSpec) {
ret = torrent.TorrentSpecFromMetaInfo(mi) ret = torrent.TorrentSpecFromMetaInfo(mi)
ret.ChunkSize = 2 ret.ChunkSize = 2
if ps.LeecherStartsWithoutMetadata {
ret.InfoBytes = nil
}
return return
}()) }())
require.NoError(t, err) require.NoError(t, err)
@ -118,12 +123,18 @@ func testClientTransfer(t *testing.T, ps testClientTransferParams) {
// Now do some things with leecher and seeder. // Now do some things with leecher and seeder.
added := leecherTorrent.AddClientPeer(seeder) added := leecherTorrent.AddClientPeer(seeder)
// The Torrent should not be interested in obtaining peers, so the one we
// just added should be the only one.
assert.False(t, leecherTorrent.Seeding()) assert.False(t, leecherTorrent.Seeding())
assert.EqualValues(t, added, leecherTorrent.Stats().PendingPeers) // The leecher will use peers immediately if it doesn't have the metadata. Otherwise, they
// should be sitting idle until we demand data.
if !ps.LeecherStartsWithoutMetadata {
assert.EqualValues(t, added, leecherTorrent.Stats().PendingPeers)
}
if ps.LeecherStartsWithoutMetadata {
<-leecherTorrent.GotInfo()
}
r := leecherTorrent.NewReader() r := leecherTorrent.NewReader()
defer r.Close() defer r.Close()
go leecherTorrent.SetInfoBytes(mi.InfoBytes)
if ps.Responsive { if ps.Responsive {
r.SetResponsive() r.SetResponsive()
} }
@ -189,6 +200,16 @@ func TestClientTransferDefault(t *testing.T) {
}) })
} }
func TestClientTransferDefaultNoMetadata(t *testing.T) {
testClientTransfer(t, testClientTransferParams{
ExportClientStatus: true,
LeecherStorage: newFileCacheClientStorageFactory(fileCacheClientStorageFactoryParams{
Wrapper: fileCachePieceResourceStorage,
}),
LeecherStartsWithoutMetadata: true,
})
}
func TestClientTransferRateLimitedUpload(t *testing.T) { func TestClientTransferRateLimitedUpload(t *testing.T) {
started := time.Now() started := time.Now()
testClientTransfer(t, testClientTransferParams{ testClientTransfer(t, testClientTransferParams{