Rework the client transfer test to allow non-piece-based leecher storage
In preparation for tests for data going missing for the file-based storages. Issue #96
This commit is contained in:
parent
c6db777ed4
commit
40aa30d984
|
@ -238,10 +238,33 @@ func TestAddDropManyTorrents(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FileCacheClientStorageFactoryParams struct {
|
||||||
|
Capacity int64
|
||||||
|
SetCapacity bool
|
||||||
|
Wrapper func(*filecache.Cache) storage.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFileCacheClientStorageFactory(ps FileCacheClientStorageFactoryParams) storageFactory {
|
||||||
|
return func(dataDir string) storage.Client {
|
||||||
|
fc, err := filecache.NewCache(dataDir)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if ps.SetCapacity {
|
||||||
|
fc.SetCapacity(ps.Capacity)
|
||||||
|
}
|
||||||
|
return ps.Wrapper(fc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type storageFactory func(string) storage.Client
|
||||||
|
|
||||||
func TestClientTransferDefault(t *testing.T) {
|
func TestClientTransferDefault(t *testing.T) {
|
||||||
testClientTransfer(t, testClientTransferParams{
|
testClientTransfer(t, testClientTransferParams{
|
||||||
ExportClientStatus: true,
|
ExportClientStatus: true,
|
||||||
LeecherFileCachePieceStorageFactory: fileCachePieceResourceStorage,
|
LeecherStorage: NewFileCacheClientStorageFactory(FileCacheClientStorageFactoryParams{
|
||||||
|
Wrapper: fileCachePieceResourceStorage,
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,16 +278,18 @@ func fileCachePieceFileStorage(fc *filecache.Cache) storage.Client {
|
||||||
|
|
||||||
func TestClientTransferSmallCache(t *testing.T) {
|
func TestClientTransferSmallCache(t *testing.T) {
|
||||||
testClientTransfer(t, testClientTransferParams{
|
testClientTransfer(t, testClientTransferParams{
|
||||||
SetLeecherStorageCapacity: true,
|
LeecherStorage: NewFileCacheClientStorageFactory(FileCacheClientStorageFactoryParams{
|
||||||
// Going below the piece length means it can't complete a piece so
|
SetCapacity: true,
|
||||||
// that it can be hashed.
|
// Going below the piece length means it can't complete a piece so
|
||||||
LeecherStorageCapacity: 5,
|
// that it can be hashed.
|
||||||
SetReadahead: true,
|
Capacity: 5,
|
||||||
|
Wrapper: fileCachePieceResourceStorage,
|
||||||
|
}),
|
||||||
|
SetReadahead: true,
|
||||||
// Can't readahead too far or the cache will thrash and drop data we
|
// Can't readahead too far or the cache will thrash and drop data we
|
||||||
// thought we had.
|
// thought we had.
|
||||||
Readahead: 0,
|
Readahead: 0,
|
||||||
ExportClientStatus: true,
|
ExportClientStatus: true,
|
||||||
LeecherFileCachePieceStorageFactory: fileCachePieceResourceStorage,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,17 +304,21 @@ func TestClientTransferVarious(t *testing.T) {
|
||||||
} {
|
} {
|
||||||
for _, responsive := range []bool{false, true} {
|
for _, responsive := range []bool{false, true} {
|
||||||
testClientTransfer(t, testClientTransferParams{
|
testClientTransfer(t, testClientTransferParams{
|
||||||
Responsive: responsive,
|
Responsive: responsive,
|
||||||
SeederStorage: ss,
|
SeederStorage: ss,
|
||||||
LeecherFileCachePieceStorageFactory: lsf,
|
LeecherStorage: NewFileCacheClientStorageFactory(FileCacheClientStorageFactoryParams{
|
||||||
|
Wrapper: lsf,
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
for _, readahead := range []int64{-1, 0, 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 14, 15, 20} {
|
for _, readahead := range []int64{-1, 0, 1, 2, 3, 4, 5, 6, 9, 10, 11, 12, 13, 14, 15, 20} {
|
||||||
testClientTransfer(t, testClientTransferParams{
|
testClientTransfer(t, testClientTransferParams{
|
||||||
SeederStorage: ss,
|
SeederStorage: ss,
|
||||||
Responsive: responsive,
|
Responsive: responsive,
|
||||||
SetReadahead: true,
|
SetReadahead: true,
|
||||||
Readahead: readahead,
|
Readahead: readahead,
|
||||||
LeecherFileCachePieceStorageFactory: lsf,
|
LeecherStorage: NewFileCacheClientStorageFactory(FileCacheClientStorageFactoryParams{
|
||||||
|
Wrapper: lsf,
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,14 +327,12 @@ func TestClientTransferVarious(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
type testClientTransferParams struct {
|
type testClientTransferParams struct {
|
||||||
Responsive bool
|
Responsive bool
|
||||||
Readahead int64
|
Readahead int64
|
||||||
SetReadahead bool
|
SetReadahead bool
|
||||||
ExportClientStatus bool
|
ExportClientStatus bool
|
||||||
SetLeecherStorageCapacity bool
|
LeecherStorage func(string) storage.Client
|
||||||
LeecherStorageCapacity int64
|
SeederStorage func(string) storage.Client
|
||||||
LeecherFileCachePieceStorageFactory func(*filecache.Cache) storage.Client
|
|
||||||
SeederStorage func(string) storage.Client
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a seeder and a leecher, and ensures the data transfers when a read
|
// Creates a seeder and a leecher, and ensures the data transfers when a read
|
||||||
|
@ -332,12 +359,7 @@ func testClientTransfer(t *testing.T, ps testClientTransferParams) {
|
||||||
leecherDataDir, err := ioutil.TempDir("", "")
|
leecherDataDir, err := ioutil.TempDir("", "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer os.RemoveAll(leecherDataDir)
|
defer os.RemoveAll(leecherDataDir)
|
||||||
fc, err := filecache.NewCache(leecherDataDir)
|
cfg.DefaultStorage = ps.LeecherStorage(leecherDataDir)
|
||||||
require.NoError(t, err)
|
|
||||||
if ps.SetLeecherStorageCapacity {
|
|
||||||
fc.SetCapacity(ps.LeecherStorageCapacity)
|
|
||||||
}
|
|
||||||
cfg.DefaultStorage = ps.LeecherFileCachePieceStorageFactory(fc)
|
|
||||||
leecher, err := NewClient(&cfg)
|
leecher, err := NewClient(&cfg)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer leecher.Close()
|
defer leecher.Close()
|
||||||
|
|
Loading…
Reference in New Issue