mirror of
https://github.com/logos-storage/logos-storage-nim.git
synced 2026-01-19 05:43:12 +00:00
adds more tests to torrentdownloader
This commit is contained in:
parent
6c32f6b835
commit
f9d2b21609
@ -14,6 +14,7 @@ import pkg/codex/bittorrent/manifest
|
||||
import pkg/codex/bittorrent/torrentdownloader
|
||||
|
||||
import pkg/codex/utils/iter
|
||||
import pkg/codex/utils/safeasynciter
|
||||
import pkg/codex/logutils
|
||||
|
||||
import ../../asynctest
|
||||
@ -208,6 +209,47 @@ asyncchecksuite "Torrent Downloader":
|
||||
check blockIter.finished
|
||||
await torrentDownloader.stop()
|
||||
|
||||
test "get downloaded blocks using async iter":
|
||||
torrentDownloader.start()
|
||||
|
||||
let blockIter = Iter.new(0 ..< codexManifest.blocksCount)
|
||||
|
||||
for dataFut in torrentDownloader.getAsyncBlockIterator():
|
||||
let status = await dataFut.withTimeout(1.seconds)
|
||||
assert status == true
|
||||
let (blockIndex, data) = (await dataFut).tryGet()
|
||||
trace "got data", blockIndex, len = data.len
|
||||
let expectedBlockIndex = blockIter.next()
|
||||
check blockIndex == expectedBlockIndex
|
||||
let treeCid = codexManifest.treeCid
|
||||
let address = BlockAddress.init(treeCid, expectedBlockIndex)
|
||||
let blk = (await localStore.getBlock(address)).tryGet()
|
||||
check blk.data == data
|
||||
|
||||
check blockIter.finished
|
||||
await torrentDownloader.stop()
|
||||
|
||||
test "get downloaded blocks using async pairs iter":
|
||||
torrentDownloader.start()
|
||||
|
||||
let blockIter = Iter.new(0 ..< codexManifest.blocksCount)
|
||||
|
||||
for i, dataFut in torrentDownloader.getAsyncBlockIterator():
|
||||
let status = await dataFut.withTimeout(1.seconds)
|
||||
assert status == true
|
||||
let (blockIndex, data) = (await dataFut).tryGet()
|
||||
trace "got data", blockIndex, len = data.len
|
||||
let expectedBlockIndex = blockIter.next()
|
||||
check i == expectedBlockIndex
|
||||
check blockIndex == expectedBlockIndex
|
||||
let treeCid = codexManifest.treeCid
|
||||
let address = BlockAddress.init(treeCid, expectedBlockIndex)
|
||||
let blk = (await localStore.getBlock(address)).tryGet()
|
||||
check blk.data == data
|
||||
|
||||
check blockIter.finished
|
||||
await torrentDownloader.stop()
|
||||
|
||||
test "canceling download":
|
||||
torrentDownloader.start()
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user