mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
TEST: Testing single block
This commit is contained in:
parent
04ffb08423
commit
dbee17b27d
2 changed files with 15 additions and 38 deletions
|
|
@ -195,6 +195,7 @@ type Firehose struct {
|
|||
blockPrintQueue chan *blockPrintJob
|
||||
blockOutputQueue chan *blockOutput
|
||||
flushDone sync.WaitGroup
|
||||
flushOutputDone sync.WaitGroup
|
||||
closeOnce sync.Once
|
||||
}
|
||||
|
||||
|
|
@ -270,24 +271,8 @@ func NewFirehose(config *FirehoseConfig) *Firehose {
|
|||
}
|
||||
|
||||
// Output channel to order the flushing linearly
|
||||
go func() {
|
||||
expected := uint64(1000) // TODO: We will need to determine at which block it starts
|
||||
buffer := make(map[uint64][]byte)
|
||||
firehose.flushOutputDone.Add(1)
|
||||
|
||||
for result := range firehose.blockOutputQueue {
|
||||
buffer[result.blockNum] = result.data
|
||||
|
||||
for {
|
||||
data, ok := buffer[expected]
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
firehose.flushToFirehose(data)
|
||||
delete(buffer, expected)
|
||||
expected++ // TODO: Assuming block numbers are linear
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
return firehose
|
||||
|
|
@ -2878,6 +2863,9 @@ func (f *Firehose) CloseBlockPrintQueue() {
|
|||
f.closeOnce.Do(func() {
|
||||
close(f.blockPrintQueue)
|
||||
f.flushDone.Wait()
|
||||
|
||||
close(f.blockOutputQueue)
|
||||
f.flushOutputDone.Wait()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestFirehose_BlockPrintsToFirehose_SingleBlock(t *testing.T) {
|
||||
|
|
@ -25,7 +24,7 @@ func TestFirehose_BlockPrintsToFirehose_SingleBlock(t *testing.T) {
|
|||
|
||||
f.OnBlockchainInit(params.AllEthashProtocolChanges)
|
||||
|
||||
blockNumbers := []uint64{123, 124, 125}
|
||||
blockNumbers := []uint64{0}
|
||||
|
||||
for i, blockNum := range blockNumbers {
|
||||
f.OnBlockStart(blockEvent(blockNum))
|
||||
|
|
@ -41,30 +40,22 @@ func TestFirehose_BlockPrintsToFirehose_SingleBlock(t *testing.T) {
|
|||
|
||||
f.OnClose()
|
||||
|
||||
output := f.InternalTestingBuffer().String()
|
||||
lines := strings.Split(strings.TrimSpace(f.InternalTestingBuffer().String()), "\n")
|
||||
require.Len(t, lines, 2)
|
||||
|
||||
outNumber := make([]string, 0)
|
||||
for i, line := range strings.Split(output, "\n") {
|
||||
if i == 0 {
|
||||
require.Equal(t, "FIRE INIT 3.0 geth 1.15.10", line)
|
||||
continue
|
||||
}
|
||||
require.Equal(t, "FIRE INIT 3.0 geth 1.15.10", lines[0])
|
||||
|
||||
fields := strings.SplitN(line, " ", 4)
|
||||
if len(fields) >= 3 {
|
||||
require.Equal(t, "FIRE", fields[0])
|
||||
require.Equal(t, "BLOCK", fields[1])
|
||||
outNumber = append(outNumber, fields[2])
|
||||
}
|
||||
}
|
||||
|
||||
require.Equal(t, []string{"123", "124", "125"}, outNumber)
|
||||
fields := strings.SplitN(lines[1], " ", 4)
|
||||
require.GreaterOrEqual(t, len(fields), 3)
|
||||
require.Equal(t, "FIRE", fields[0])
|
||||
require.Equal(t, "BLOCK", fields[1])
|
||||
require.Equal(t, "0", fields[2])
|
||||
}
|
||||
|
||||
func TestFirehose_BlocksPrintToFirehose_MultipleBlocksInOrder(t *testing.T) {
|
||||
|
||||
const blockCount = 10
|
||||
const baseBlockNum = 1000
|
||||
const baseBlockNum = 0
|
||||
|
||||
f := NewFirehose(&FirehoseConfig{
|
||||
ConcurrentBlockFlushing: true,
|
||||
|
|
@ -93,8 +84,6 @@ func TestFirehose_BlocksPrintToFirehose_MultipleBlocksInOrder(t *testing.T) {
|
|||
f.OnBlockEnd(nil)
|
||||
}
|
||||
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
f.OnClose()
|
||||
|
||||
output := f.InternalTestingBuffer().String()
|
||||
|
|
|
|||
Loading…
Reference in a new issue