update asynctest package, async signatures, add back toSeq from botched merge
This commit is contained in:
parent
809132353c
commit
b26386f631
|
@ -91,13 +91,13 @@ func indexToPos(steps, idx, step: int): int {.inline.} =
|
||||||
proc getPendingBlocks(
|
proc getPendingBlocks(
|
||||||
self: Erasure,
|
self: Erasure,
|
||||||
manifest: Manifest,
|
manifest: Manifest,
|
||||||
indicies: seq[int]): AsyncIter[(?!bt.Block, int)] =
|
indices: seq[int]): AsyncIter[(?!bt.Block, int)] =
|
||||||
## Get pending blocks iterator
|
## Get pending blocks iterator
|
||||||
##
|
##
|
||||||
|
|
||||||
var
|
var
|
||||||
# request blocks from the store
|
# request blocks from the store
|
||||||
pendingBlocks = indicies.map( (i: int) =>
|
pendingBlocks = indices.map( (i: int) =>
|
||||||
self.store.getBlock(
|
self.store.getBlock(
|
||||||
BlockAddress.init(manifest.treeCid, i)
|
BlockAddress.init(manifest.treeCid, i)
|
||||||
).map((r: ?!bt.Block) => (r, i)) # Get the data blocks (first K)
|
).map((r: ?!bt.Block) => (r, i)) # Get the data blocks (first K)
|
||||||
|
@ -135,8 +135,8 @@ proc prepareEncodingData(
|
||||||
lastIndex = params.rounded - 1,
|
lastIndex = params.rounded - 1,
|
||||||
numberOfIterations = params.steps
|
numberOfIterations = params.steps
|
||||||
)
|
)
|
||||||
indicies = strategy.getIndices(step)
|
indices = toSeq(strategy.getIndices(step))
|
||||||
pendingBlocksIter = self.getPendingBlocks(manifest, indicies.filterIt(it < manifest.blocksCount))
|
pendingBlocksIter = self.getPendingBlocks(manifest, indices.filterIt(it < manifest.blocksCount))
|
||||||
|
|
||||||
var resolved = 0
|
var resolved = 0
|
||||||
for fut in pendingBlocksIter:
|
for fut in pendingBlocksIter:
|
||||||
|
@ -151,7 +151,7 @@ proc prepareEncodingData(
|
||||||
|
|
||||||
resolved.inc()
|
resolved.inc()
|
||||||
|
|
||||||
for idx in indicies.filterIt(it >= manifest.blocksCount):
|
for idx in indices.filterIt(it >= manifest.blocksCount):
|
||||||
let pos = indexToPos(params.steps, idx, step)
|
let pos = indexToPos(params.steps, idx, step)
|
||||||
trace "Padding with empty block", idx
|
trace "Padding with empty block", idx
|
||||||
shallowCopy(data[pos], emptyBlock)
|
shallowCopy(data[pos], emptyBlock)
|
||||||
|
@ -184,8 +184,8 @@ proc prepareDecodingData(
|
||||||
lastIndex = encoded.blocksCount - 1,
|
lastIndex = encoded.blocksCount - 1,
|
||||||
numberOfIterations = encoded.steps
|
numberOfIterations = encoded.steps
|
||||||
)
|
)
|
||||||
indicies = strategy.getIndices(step)
|
indices = toSeq(strategy.getIndices(step))
|
||||||
pendingBlocksIter = self.getPendingBlocks(encoded, indicies)
|
pendingBlocksIter = self.getPendingBlocks(encoded, indices)
|
||||||
|
|
||||||
var
|
var
|
||||||
dataPieces = 0
|
dataPieces = 0
|
||||||
|
|
|
@ -63,7 +63,7 @@ proc getIter(first, last, step: int): Iter[int] =
|
||||||
|
|
||||||
Iter.new(get, isFinished)
|
Iter.new(get, isFinished)
|
||||||
|
|
||||||
method getIndicies*(
|
method getIndices*(
|
||||||
self: LinearIndexingStrategy,
|
self: LinearIndexingStrategy,
|
||||||
iteration: int): Iter[int] {.raises: [IndexingError].} =
|
iteration: int): Iter[int] {.raises: [IndexingError].} =
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ method getIndicies*(
|
||||||
|
|
||||||
getIter(first, last, 1)
|
getIter(first, last, 1)
|
||||||
|
|
||||||
method getIndicies*(
|
method getIndices*(
|
||||||
self: SteppedIndexingStrategy,
|
self: SteppedIndexingStrategy,
|
||||||
iteration: int): Iter[int] {.raises: [IndexingError].} =
|
iteration: int): Iter[int] {.raises: [IndexingError].} =
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import std/times
|
||||||
|
|
||||||
import pkg/libp2p
|
import pkg/libp2p
|
||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
import pkg/asynctest
|
import pkg/asynctest/chronos/unittest
|
||||||
|
|
||||||
import pkg/codex/codextypes
|
import pkg/codex/codextypes
|
||||||
import pkg/codex/chunker
|
import pkg/codex/chunker
|
||||||
|
@ -13,7 +13,7 @@ proc toTimesDuration*(d: chronos.Duration): times.Duration =
|
||||||
|
|
||||||
proc drain*(
|
proc drain*(
|
||||||
stream: LPStream | Result[lpstream.LPStream, ref CatchableError]):
|
stream: LPStream | Result[lpstream.LPStream, ref CatchableError]):
|
||||||
Future[seq[byte]] {.async.} =
|
Future[seq[byte]] {.async: (handleException: true, raises: [AsyncExceptionError]).} =
|
||||||
|
|
||||||
let
|
let
|
||||||
stream =
|
stream =
|
||||||
|
@ -36,7 +36,10 @@ proc drain*(
|
||||||
|
|
||||||
data
|
data
|
||||||
|
|
||||||
proc pipeChunker*(stream: BufferStream, chunker: Chunker) {.async.} =
|
proc pipeChunker*(
|
||||||
|
stream: BufferStream,
|
||||||
|
chunker: Chunker
|
||||||
|
) {.async: (handleException: true, raises: [AsyncExceptionError]).} =
|
||||||
try:
|
try:
|
||||||
while (
|
while (
|
||||||
let chunk = await chunker.getBytes();
|
let chunk = await chunker.getBytes();
|
||||||
|
|
|
@ -5,7 +5,7 @@ import std/times
|
||||||
import std/sequtils
|
import std/sequtils
|
||||||
import std/importutils
|
import std/importutils
|
||||||
|
|
||||||
import pkg/asynctest
|
import pkg/asynctest/chronos/unittest
|
||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
import pkg/stew/byteutils
|
import pkg/stew/byteutils
|
||||||
import pkg/datastore
|
import pkg/datastore
|
||||||
|
@ -129,7 +129,7 @@ asyncchecksuite "Test Node - Host contracts":
|
||||||
(await onStore(request, 1.u256, onBlocks)).tryGet()
|
(await onStore(request, 1.u256, onBlocks)).tryGet()
|
||||||
check fetchedBytes == 786432
|
check fetchedBytes == 786432
|
||||||
|
|
||||||
for index in builder.slotIndicies(1):
|
for index in !builder.slotIndices(1):
|
||||||
let
|
let
|
||||||
blk = (await localStore.getBlock(verifiable.treeCid, index)).tryGet
|
blk = (await localStore.getBlock(verifiable.treeCid, index)).tryGet
|
||||||
expiryKey = (createBlockExpirationMetadataKey(blk.cid)).tryGet
|
expiryKey = (createBlockExpirationMetadataKey(blk.cid)).tryGet
|
||||||
|
|
|
@ -5,7 +5,7 @@ import std/times
|
||||||
import std/sequtils
|
import std/sequtils
|
||||||
import std/importutils
|
import std/importutils
|
||||||
|
|
||||||
import pkg/asynctest
|
import pkg/asynctest/chronos/unittest
|
||||||
import pkg/chronos
|
import pkg/chronos
|
||||||
import pkg/stew/byteutils
|
import pkg/stew/byteutils
|
||||||
import pkg/datastore
|
import pkg/datastore
|
||||||
|
@ -69,7 +69,7 @@ asyncchecksuite "Test Node - Basic":
|
||||||
(await node.fetchBatched(
|
(await node.fetchBatched(
|
||||||
manifest,
|
manifest,
|
||||||
batchSize = batchSize,
|
batchSize = batchSize,
|
||||||
proc(blocks: seq[bt.Block]): Future[?!void] {.gcsafe, async.} =
|
proc(blocks: seq[bt.Block]): Future[?!void] {.gcsafe, async: (handleException: true).} =
|
||||||
check blocks.len > 0 and blocks.len <= batchSize
|
check blocks.len > 0 and blocks.len <= batchSize
|
||||||
return success()
|
return success()
|
||||||
)).tryGet()
|
)).tryGet()
|
||||||
|
|
|
@ -19,15 +19,15 @@ for offset in @[0, 1, 2, 100]:
|
||||||
|
|
||||||
test "linear":
|
test "linear":
|
||||||
check:
|
check:
|
||||||
linear.getIndices(0) == @[0, 1, 2, 3, 4].mapIt(it + offset)
|
toSeq(linear.getIndices(0)) == @[0, 1, 2, 3, 4].mapIt(it + offset)
|
||||||
linear.getIndices(1) == @[5, 6, 7, 8, 9].mapIt(it + offset)
|
toSeq(linear.getIndices(1)) == @[5, 6, 7, 8, 9].mapIt(it + offset)
|
||||||
linear.getIndices(2) == @[10, 11, 12].mapIt(it + offset)
|
toSeq(linear.getIndices(2)) == @[10, 11, 12].mapIt(it + offset)
|
||||||
|
|
||||||
test "stepped":
|
test "stepped":
|
||||||
check:
|
check:
|
||||||
stepped.getIndices(0) == @[0, 3, 6, 9, 12].mapIt(it + offset)
|
toSeq(stepped.getIndices(0)) == @[0, 3, 6, 9, 12].mapIt(it + offset)
|
||||||
stepped.getIndices(1) == @[1, 4, 7, 10].mapIt(it + offset)
|
toSeq(stepped.getIndices(1)) == @[1, 4, 7, 10].mapIt(it + offset)
|
||||||
stepped.getIndices(2) == @[2, 5, 8, 11].mapIt(it + offset)
|
toSeq(stepped.getIndices(2)) == @[2, 5, 8, 11].mapIt(it + offset)
|
||||||
|
|
||||||
suite "Indexing strategies":
|
suite "Indexing strategies":
|
||||||
let
|
let
|
||||||
|
@ -39,16 +39,16 @@ suite "Indexing strategies":
|
||||||
l = LinearIndexingStrategy.new(0, 0, 1)
|
l = LinearIndexingStrategy.new(0, 0, 1)
|
||||||
s = SteppedIndexingStrategy.new(0, 0, 1)
|
s = SteppedIndexingStrategy.new(0, 0, 1)
|
||||||
check:
|
check:
|
||||||
l.getIndices(0) == @[0]
|
toSeq(l.getIndices(0)) == @[0]
|
||||||
s.getIndices(0) == @[0]
|
toSeq(s.getIndices(0)) == @[0]
|
||||||
|
|
||||||
test "smallest range 1":
|
test "smallest range 1":
|
||||||
let
|
let
|
||||||
l = LinearIndexingStrategy.new(0, 1, 1)
|
l = LinearIndexingStrategy.new(0, 1, 1)
|
||||||
s = SteppedIndexingStrategy.new(0, 1, 1)
|
s = SteppedIndexingStrategy.new(0, 1, 1)
|
||||||
check:
|
check:
|
||||||
l.getIndices(0) == @[0, 1]
|
toSeq(l.getIndices(0)) == @[0, 1]
|
||||||
s.getIndices(0) == @[0, 1]
|
toSeq(s.getIndices(0)) == @[0, 1]
|
||||||
|
|
||||||
test "first index must be smaller than last index":
|
test "first index must be smaller than last index":
|
||||||
expect IndexingWrongIndexError:
|
expect IndexingWrongIndexError:
|
||||||
|
|
Loading…
Reference in New Issue