backport changes from fix-erasure-tests (#618)
This commit is contained in:
parent
a1725594a8
commit
06bb21bfc7
|
@ -1,4 +1,5 @@
|
|||
import std/sequtils
|
||||
import std/sugar
|
||||
|
||||
import pkg/asynctest
|
||||
import pkg/chronos
|
||||
|
@ -10,6 +11,7 @@ import pkg/codex/manifest
|
|||
import pkg/codex/stores
|
||||
import pkg/codex/blocktype as bt
|
||||
import pkg/codex/rng
|
||||
import pkg/codex/utils
|
||||
|
||||
import ./helpers
|
||||
|
||||
|
@ -42,7 +44,7 @@ asyncchecksuite "Erasure encode/decode":
|
|||
|
||||
check:
|
||||
encoded.blocksCount mod (buffers + parity) == 0
|
||||
encoded.rounded == (manifest.blocksCount + (buffers - (manifest.blocksCount mod buffers)))
|
||||
encoded.rounded == roundUp(manifest.blocksCount, buffers)
|
||||
encoded.steps == encoded.rounded div buffers
|
||||
|
||||
return encoded
|
||||
|
@ -55,14 +57,14 @@ asyncchecksuite "Erasure encode/decode":
|
|||
let encoded = await encode(buffers, parity)
|
||||
|
||||
var
|
||||
column = rng.rand((encoded.blocksCount - 1) div encoded.steps) # random column
|
||||
column = rng.rand((encoded.blocksCount div encoded.steps) - 1) # random column
|
||||
dropped: seq[int]
|
||||
|
||||
for _ in 0..<encoded.ecM:
|
||||
dropped.add(column)
|
||||
(await store.delBlock(encoded.treeCid, column)).tryGet()
|
||||
(await store.delBlock(manifest.treeCid, column)).tryGet()
|
||||
column.inc(encoded.steps - 1)
|
||||
column = (column + encoded.steps) mod encoded.blocksCount # wrap around
|
||||
|
||||
var
|
||||
decoded = (await erasure.decode(encoded)).tryGet()
|
||||
|
@ -73,8 +75,9 @@ asyncchecksuite "Erasure encode/decode":
|
|||
decoded.blocksCount == encoded.originalBlocksCount
|
||||
|
||||
for d in dropped:
|
||||
let present = await store.hasBlock(manifest.treeCid, d)
|
||||
check present.tryGet()
|
||||
if d < manifest.blocksCount: # we don't support returning parity blocks yet
|
||||
let present = await store.hasBlock(manifest.treeCid, d)
|
||||
check present.tryGet()
|
||||
|
||||
test "Should not tolerate losing more than M data blocks in a single random column":
|
||||
const
|
||||
|
@ -84,14 +87,14 @@ asyncchecksuite "Erasure encode/decode":
|
|||
let encoded = await encode(buffers, parity)
|
||||
|
||||
var
|
||||
column = rng.rand((encoded.blocksCount - 1) div encoded.steps) # random column
|
||||
column = rng.rand((encoded.blocksCount div encoded.steps) - 1) # random column
|
||||
dropped: seq[int]
|
||||
|
||||
for _ in 0..<encoded.ecM + 1:
|
||||
dropped.add(column)
|
||||
(await store.delBlock(encoded.treeCid, column)).tryGet()
|
||||
(await store.delBlock(manifest.treeCid, column)).tryGet()
|
||||
column.inc(encoded.steps)
|
||||
column = (column + encoded.steps) mod encoded.blocksCount # wrap around
|
||||
|
||||
var
|
||||
decoded: Manifest
|
||||
|
@ -144,7 +147,7 @@ asyncchecksuite "Erasure encode/decode":
|
|||
blocks: seq[int]
|
||||
offset = 0
|
||||
|
||||
while offset < encoded.steps - 1:
|
||||
while offset < encoded.steps:
|
||||
let
|
||||
blockIdx = toSeq(countup(offset, encoded.blocksCount - 1, encoded.steps))
|
||||
|
||||
|
@ -177,7 +180,8 @@ asyncchecksuite "Erasure encode/decode":
|
|||
|
||||
let encoded = await encode(buffers, parity)
|
||||
|
||||
for b in 0..<encoded.steps * encoded.ecM:
|
||||
# loose M original (systematic) symbols/blocks
|
||||
for b in 0..<(encoded.steps * encoded.ecM):
|
||||
(await store.delBlock(encoded.treeCid, b)).tryGet()
|
||||
(await store.delBlock(manifest.treeCid, b)).tryGet()
|
||||
|
||||
|
@ -192,9 +196,14 @@ asyncchecksuite "Erasure encode/decode":
|
|||
buffers = 20
|
||||
parity = 10
|
||||
|
||||
let encoded = await encode(buffers, parity)
|
||||
let
|
||||
encoded = await encode(buffers, parity)
|
||||
blocks = collect:
|
||||
for i in 0..encoded.blocksCount:
|
||||
i
|
||||
|
||||
for b in (encoded.blocksCount - encoded.steps * encoded.ecM)..<encoded.blocksCount:
|
||||
# loose M parity (all!) symbols/blocks from the dataset
|
||||
for b in blocks[^(encoded.steps * encoded.ecM)..^1]:
|
||||
(await store.delBlock(encoded.treeCid, b)).tryGet()
|
||||
(await store.delBlock(manifest.treeCid, b)).tryGet()
|
||||
|
||||
|
|
Loading…
Reference in New Issue