mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 04:36:42 +00:00
simplify random data tests for chunker
This commit is contained in:
parent
fdbf3ed379
commit
a3feff4274
1 changed files with 11 additions and 26 deletions
|
|
@ -130,17 +130,14 @@ func (self *chunkerTester) Join(t *testing.T, chunker *TreeChunker, key Key) (da
|
||||||
|
|
||||||
case chunk, ok := <-chunkC:
|
case chunk, ok := <-chunkC:
|
||||||
if chunk != nil {
|
if chunk != nil {
|
||||||
t.Logf("got request %v", chunk)
|
|
||||||
// this just mocks the behaviour of a chunk store retrieval
|
// this just mocks the behaviour of a chunk store retrieval
|
||||||
var found bool
|
var found bool
|
||||||
for _, ch := range self.chunks {
|
for _, ch := range self.chunks {
|
||||||
if bytes.Compare(chunk.Key, ch.Key) == 0 {
|
if bytes.Compare(chunk.Key, ch.Key) == 0 {
|
||||||
found = true
|
found = true
|
||||||
t.Logf("found data %v", ch)
|
|
||||||
// ch.Data.Seek(0, 0) // the reader has to be reset
|
// ch.Data.Seek(0, 0) // the reader has to be reset
|
||||||
chunk.Data = ch.Data
|
chunk.Data = ch.Data
|
||||||
chunk.Size = ch.Size
|
chunk.Size = ch.Size
|
||||||
t.Logf("updated chunk %v", chunk)
|
|
||||||
close(chunk.C)
|
close(chunk.C)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -166,43 +163,31 @@ func (self *chunkerTester) Join(t *testing.T, chunker *TreeChunker, key Key) (da
|
||||||
}()
|
}()
|
||||||
<-quitC // waiting for it to finish
|
<-quitC // waiting for it to finish
|
||||||
w.Seek(0, 0)
|
w.Seek(0, 0)
|
||||||
t.Logf("reader size %v", w.Size())
|
|
||||||
return w.Slice(0, w.Size())
|
return w.Slice(0, w.Size())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChunker0(t *testing.T) {
|
func testRandomData(chunker *TreeChunker, tester *chunkerTester, n int, chunks int, t *testing.T) {
|
||||||
defer testlog(t).detach()
|
key, input := tester.Split(chunker, n)
|
||||||
|
tester.checkChunks(t, chunks)
|
||||||
chunker := &TreeChunker{
|
|
||||||
Branches: 2,
|
|
||||||
SplitTimeout: 100 * time.Millisecond,
|
|
||||||
}
|
|
||||||
chunker.Init()
|
|
||||||
tester := &chunkerTester{}
|
|
||||||
key, input := tester.Split(chunker, 32)
|
|
||||||
tester.checkChunks(t, 1)
|
|
||||||
t.Logf("chunks: %v", tester.chunks)
|
t.Logf("chunks: %v", tester.chunks)
|
||||||
output := tester.Join(t, chunker, key)
|
output := tester.Join(t, chunker, key)
|
||||||
|
t.Logf(" IN: %x\nOUT: %x\n", input, output)
|
||||||
if bytes.Compare(output, input) != 0 {
|
if bytes.Compare(output, input) != 0 {
|
||||||
t.Errorf("input and output mismatch\n IN: %x\nOUT: %x\n", input, output)
|
t.Errorf("input and output mismatch\n IN: %x\nOUT: %x\n", input, output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestChunker1(t *testing.T) {
|
func TestRandomData(t *testing.T) {
|
||||||
defer testlog(t).detach()
|
defer testlog(t).detach()
|
||||||
|
|
||||||
chunker := &TreeChunker{
|
chunker := &TreeChunker{
|
||||||
Branches: 2,
|
Branches: 2,
|
||||||
SplitTimeout: 100 * time.Millisecond,
|
SplitTimeout: 10 * time.Second,
|
||||||
|
JoinTimeout: 10 * time.Second,
|
||||||
}
|
}
|
||||||
chunker.Init()
|
chunker.Init()
|
||||||
tester := &chunkerTester{}
|
tester := &chunkerTester{}
|
||||||
key, input := tester.Split(chunker, 170)
|
testRandomData(chunker, tester, 70, 3, t)
|
||||||
tester.checkChunks(t, 3)
|
// testRandomData(chunker, tester, 179, 5, t)
|
||||||
t.Logf("chunks %x -> %x", key, input)
|
// testRandomData(chunker, tester, 253, 7, t)
|
||||||
// t.Logf("chunks: %v", tester.chunks)
|
t.Logf("chunks %v", tester.chunks)
|
||||||
// output := tester.Join(t, chunker, key)
|
|
||||||
// if bytes.Compare(output, input) != 0 {
|
|
||||||
// t.Errorf("input and output mismatch\n IN: %x\nOUT: %x\n", input, output)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue