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{
|
||||||
|
SetCapacity: true,
|
||||||
// Going below the piece length means it can't complete a piece so
|
// Going below the piece length means it can't complete a piece so
|
||||||
// that it can be hashed.
|
// that it can be hashed.
|
||||||
LeecherStorageCapacity: 5,
|
Capacity: 5,
|
||||||
|
Wrapper: fileCachePieceResourceStorage,
|
||||||
|
}),
|
||||||
SetReadahead: true,
|
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,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +306,9 @@ func TestClientTransferVarious(t *testing.T) {
|
||||||
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{
|
||||||
|
@ -289,7 +316,9 @@ func TestClientTransferVarious(t *testing.T) {
|
||||||
Responsive: responsive,
|
Responsive: responsive,
|
||||||
SetReadahead: true,
|
SetReadahead: true,
|
||||||
Readahead: readahead,
|
Readahead: readahead,
|
||||||
LeecherFileCachePieceStorageFactory: lsf,
|
LeecherStorage: NewFileCacheClientStorageFactory(FileCacheClientStorageFactoryParams{
|
||||||
|
Wrapper: lsf,
|
||||||
|
}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -302,9 +331,7 @@ type testClientTransferParams struct {
|
||||||
Readahead int64
|
Readahead int64
|
||||||
SetReadahead bool
|
SetReadahead bool
|
||||||
ExportClientStatus bool
|
ExportClientStatus bool
|
||||||
SetLeecherStorageCapacity bool
|
LeecherStorage func(string) storage.Client
|
||||||
LeecherStorageCapacity int64
|
|
||||||
LeecherFileCachePieceStorageFactory func(*filecache.Cache) storage.Client
|
|
||||||
SeederStorage func(string) storage.Client
|
SeederStorage func(string) storage.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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