Test both resource and file backends to piece storage
This commit is contained in:
parent
52e285ea86
commit
9b5d3cac03
|
@ -239,9 +239,18 @@ func TestAddDropManyTorrents(t *testing.T) {
|
||||||
func TestClientTransferDefault(t *testing.T) {
|
func TestClientTransferDefault(t *testing.T) {
|
||||||
testClientTransfer(t, testClientTransferParams{
|
testClientTransfer(t, testClientTransferParams{
|
||||||
ExportClientStatus: true,
|
ExportClientStatus: true,
|
||||||
|
LeecherFileCachePieceStorageFactory: fileCachePieceResourceStorage,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fileCachePieceResourceStorage(fc *filecache.Cache) storage.I {
|
||||||
|
return storage.NewPiecePerResource(fc.AsResourceProvider())
|
||||||
|
}
|
||||||
|
|
||||||
|
func fileCachePieceFileStorage(fc *filecache.Cache) storage.I {
|
||||||
|
return storage.NewPieceFileStorage(fc.AsFileStore())
|
||||||
|
}
|
||||||
|
|
||||||
func TestClientTransferSmallCache(t *testing.T) {
|
func TestClientTransferSmallCache(t *testing.T) {
|
||||||
testClientTransfer(t, testClientTransferParams{
|
testClientTransfer(t, testClientTransferParams{
|
||||||
SetLeecherStorageCapacity: true,
|
SetLeecherStorageCapacity: true,
|
||||||
|
@ -253,10 +262,15 @@ func TestClientTransferSmallCache(t *testing.T) {
|
||||||
// thought we had.
|
// thought we had.
|
||||||
Readahead: 0,
|
Readahead: 0,
|
||||||
ExportClientStatus: true,
|
ExportClientStatus: true,
|
||||||
|
LeecherFileCachePieceStorageFactory: fileCachePieceResourceStorage,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestClientTransferVarious(t *testing.T) {
|
func TestClientTransferVarious(t *testing.T) {
|
||||||
|
for _, lsf := range []func(*filecache.Cache) storage.I{
|
||||||
|
fileCachePieceFileStorage,
|
||||||
|
fileCachePieceResourceStorage,
|
||||||
|
} {
|
||||||
for _, ss := range []func(string) storage.I{
|
for _, ss := range []func(string) storage.I{
|
||||||
storage.NewFile,
|
storage.NewFile,
|
||||||
storage.NewMMap,
|
storage.NewMMap,
|
||||||
|
@ -265,6 +279,7 @@ func TestClientTransferVarious(t *testing.T) {
|
||||||
testClientTransfer(t, testClientTransferParams{
|
testClientTransfer(t, testClientTransferParams{
|
||||||
Responsive: responsive,
|
Responsive: responsive,
|
||||||
SeederStorage: ss,
|
SeederStorage: ss,
|
||||||
|
LeecherFileCachePieceStorageFactory: 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{
|
||||||
|
@ -272,10 +287,12 @@ func TestClientTransferVarious(t *testing.T) {
|
||||||
Responsive: responsive,
|
Responsive: responsive,
|
||||||
SetReadahead: true,
|
SetReadahead: true,
|
||||||
Readahead: readahead,
|
Readahead: readahead,
|
||||||
|
LeecherFileCachePieceStorageFactory: lsf,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type testClientTransferParams struct {
|
type testClientTransferParams struct {
|
||||||
|
@ -285,6 +302,7 @@ type testClientTransferParams struct {
|
||||||
ExportClientStatus bool
|
ExportClientStatus bool
|
||||||
SetLeecherStorageCapacity bool
|
SetLeecherStorageCapacity bool
|
||||||
LeecherStorageCapacity int64
|
LeecherStorageCapacity int64
|
||||||
|
LeecherFileCachePieceStorageFactory func(*filecache.Cache) storage.I
|
||||||
SeederStorage func(string) storage.I
|
SeederStorage func(string) storage.I
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -315,7 +333,7 @@ func testClientTransfer(t *testing.T, ps testClientTransferParams) {
|
||||||
if ps.SetLeecherStorageCapacity {
|
if ps.SetLeecherStorageCapacity {
|
||||||
fc.SetCapacity(ps.LeecherStorageCapacity)
|
fc.SetCapacity(ps.LeecherStorageCapacity)
|
||||||
}
|
}
|
||||||
cfg.DefaultStorage = storage.NewPieceFileStorage(fc.AsFileStore())
|
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()
|
||||||
|
@ -678,7 +696,7 @@ func writeTorrentData(ts storage.Torrent, info *metainfo.InfoEx, b []byte) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testAddTorrentPriorPieceCompletion(t *testing.T, alreadyCompleted bool) {
|
func testAddTorrentPriorPieceCompletion(t *testing.T, alreadyCompleted bool, csf func(*filecache.Cache) storage.I) {
|
||||||
fileCacheDir, err := ioutil.TempDir("", "")
|
fileCacheDir, err := ioutil.TempDir("", "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer os.RemoveAll(fileCacheDir)
|
defer os.RemoveAll(fileCacheDir)
|
||||||
|
@ -686,7 +704,7 @@ func testAddTorrentPriorPieceCompletion(t *testing.T, alreadyCompleted bool) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
greetingDataTempDir, greetingMetainfo := testutil.GreetingTestTorrent()
|
greetingDataTempDir, greetingMetainfo := testutil.GreetingTestTorrent()
|
||||||
defer os.RemoveAll(greetingDataTempDir)
|
defer os.RemoveAll(greetingDataTempDir)
|
||||||
filePieceStore := storage.NewPieceFileStorage(fileCache.AsFileStore())
|
filePieceStore := csf(fileCache)
|
||||||
greetingData, err := filePieceStore.OpenTorrent(&greetingMetainfo.Info)
|
greetingData, err := filePieceStore.OpenTorrent(&greetingMetainfo.Info)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
writeTorrentData(greetingData, &greetingMetainfo.Info, []byte(testutil.GreetingFileContents))
|
writeTorrentData(greetingData, &greetingMetainfo.Info, []byte(testutil.GreetingFileContents))
|
||||||
|
@ -722,11 +740,13 @@ func testAddTorrentPriorPieceCompletion(t *testing.T, alreadyCompleted bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddTorrentPiecesAlreadyCompleted(t *testing.T) {
|
func TestAddTorrentPiecesAlreadyCompleted(t *testing.T) {
|
||||||
testAddTorrentPriorPieceCompletion(t, true)
|
testAddTorrentPriorPieceCompletion(t, true, fileCachePieceFileStorage)
|
||||||
|
testAddTorrentPriorPieceCompletion(t, true, fileCachePieceResourceStorage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddTorrentPiecesNotAlreadyCompleted(t *testing.T) {
|
func TestAddTorrentPiecesNotAlreadyCompleted(t *testing.T) {
|
||||||
testAddTorrentPriorPieceCompletion(t, false)
|
testAddTorrentPriorPieceCompletion(t, false, fileCachePieceFileStorage)
|
||||||
|
testAddTorrentPriorPieceCompletion(t, false, fileCachePieceResourceStorage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddMetainfoWithNodes(t *testing.T) {
|
func TestAddMetainfoWithNodes(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue