BUG: Fixed order

This commit is contained in:
David Zhou 2025-05-13 13:19:07 -04:00
parent dbee17b27d
commit a053ac76fd
2 changed files with 20 additions and 1 deletions

View file

@ -272,7 +272,26 @@ func NewFirehose(config *FirehoseConfig) *Firehose {
// Output channel to order the flushing linearly // Output channel to order the flushing linearly
firehose.flushOutputDone.Add(1) firehose.flushOutputDone.Add(1)
go func() {
defer firehose.flushOutputDone.Done()
expected := uint64(0)
buffer := make(map[uint64][]byte)
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++
}
}
}()
} }
return firehose return firehose

View file

@ -54,7 +54,7 @@ func TestFirehose_BlockPrintsToFirehose_SingleBlock(t *testing.T) {
func TestFirehose_BlocksPrintToFirehose_MultipleBlocksInOrder(t *testing.T) { func TestFirehose_BlocksPrintToFirehose_MultipleBlocksInOrder(t *testing.T) {
const blockCount = 10 const blockCount = 100
const baseBlockNum = 0 const baseBlockNum = 0
f := NewFirehose(&FirehoseConfig{ f := NewFirehose(&FirehoseConfig{