TEST: Testing concurrent and not concurrent

This commit is contained in:
David Zhou 2025-05-12 11:11:41 -04:00
parent e8ddd05284
commit 8d0ce228db
3 changed files with 39 additions and 35 deletions

View file

@ -632,7 +632,7 @@ func (f *Firehose) reorderCallOrdinals(call *pbeth.Call, ordinalBase uint64) (or
func (f *Firehose) OnClose() {
log.Info("Firehose closing...")
if f.concurrentBlockFlushing {
log.Info("waiting for worker goroutines to finish and shutting down channels")
log.Info("Closing channel: flushing the remaining blocks to firehose")
f.CloseBlockPrintQueue()
}
}
@ -1860,6 +1860,7 @@ func (f *Firehose) printBlockToFirehose(block *pbeth.Block, finalityStatus *Fina
panic(fmt.Errorf("failed to marshal block: %w", err))
}
// TODO: If multiple goroutine, this becomes shared resource
f.outputBuffer.Reset()
previousHash := block.PreviousID()
@ -2843,7 +2844,6 @@ func (f *Firehose) blockPrintWorker() {
func (f *Firehose) CloseBlockPrintQueue() {
if f.concurrentBlockFlushing {
f.closeOnce.Do(func() {
log.Info("Closing channel: flushing the remaining blocks to firehose")
close(f.blockPrintQueue)
f.flushDone.Wait()
})

View file

@ -38,26 +38,28 @@ func TestFirehosePrestate(t *testing.T) {
"./testdata/TestFirehosePrestate/extra_account_creations",
}
for _, folder := range testFolders {
name := filepath.Base(folder)
// TODO: have goroutine config on AND off
for _, concurrent := range []bool{true, false} {
for _, folder := range testFolders {
name := filepath.Base(folder)
for _, model := range tracingModels {
t.Run(string(model)+"/"+name, func(t *testing.T) {
tracer, tracingHooks, onClose := newFirehoseTestTracer(t, model)
defer onClose()
for _, model := range tracingModels {
t.Run(string(model)+"/"+name, func(t *testing.T) {
tracer, tracingHooks, onClose := newFirehoseTestTracer(t, model, concurrent)
defer onClose()
runPrestateBlock(t, filepath.Join(folder, "prestate.json"), tracingHooks)
runPrestateBlock(t, filepath.Join(folder, "prestate.json"), tracingHooks)
tracer.CloseBlockPrintQueue()
tracer.CloseBlockPrintQueue()
genesisLine, blockLines, unknownLines := readTracerFirehoseLines(t, tracer)
require.Len(t, unknownLines, 0, "Lines:\n%s", strings.Join(slicesMap(unknownLines, func(l unknownLine) string { return "- '" + string(l) + "'" }), "\n"))
require.NotNil(t, genesisLine)
blockLines.assertOnlyBlockEquals(t, filepath.Join(folder, string(model)), 1)
})
genesisLine, blockLines, unknownLines := readTracerFirehoseLines(t, tracer)
require.Len(t, unknownLines, 0, "Lines:\n%s", strings.Join(slicesMap(unknownLines, func(l unknownLine) string { return "- '" + string(l) + "'" }), "\n"))
require.NotNil(t, genesisLine)
blockLines.assertOnlyBlockEquals(t, filepath.Join(folder, string(model)), 1)
})
}
}
}
}
func TestFirehose_EIP7702(t *testing.T) {
// Copied from ./core/blockchain_test.go#L4180 (TestEIP7702)
@ -187,26 +189,28 @@ func TestFirehose_SystemCalls(t *testing.T) {
func testBlockTracesCorrectly(t *testing.T, genesisSpec *core.Genesis, engine consensus.Engine, blocks []*types.Block, goldenDir string) {
t.Helper()
for _, model := range tracingModels {
t.Run(string(model), func(t *testing.T) {
tracer, tracingHooks, onClose := newFirehoseTestTracer(t, model)
defer onClose()
for _, concurrent := range []bool{true, false} {
for _, model := range tracingModels {
t.Run(string(model), func(t *testing.T) {
tracer, tracingHooks, onClose := newFirehoseTestTracer(t, model, concurrent)
defer onClose()
chain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), nil, genesisSpec, nil, engine, vm.Config{Tracer: tracingHooks}, nil)
require.NoError(t, err, "failed to create tester chain")
chain, err := core.NewBlockChain(rawdb.NewMemoryDatabase(), nil, genesisSpec, nil, engine, vm.Config{Tracer: tracingHooks}, nil)
require.NoError(t, err, "failed to create tester chain")
chain.SetBlockValidatorAndProcessorForTesting(
ignoreValidateStateValidator{core.NewBlockValidator(genesisSpec.Config, chain)},
core.NewStateProcessor(genesisSpec.Config, chain.HeaderChain()),
)
chain.SetBlockValidatorAndProcessorForTesting(
ignoreValidateStateValidator{core.NewBlockValidator(genesisSpec.Config, chain)},
core.NewStateProcessor(genesisSpec.Config, chain.HeaderChain()),
)
defer chain.Stop()
n, err := chain.InsertChain(blocks)
require.NoError(t, err, "failed to insert chain block %d", n)
defer chain.Stop()
n, err := chain.InsertChain(blocks)
require.NoError(t, err, "failed to insert chain block %d", n)
tracer.CloseBlockPrintQueue()
tracer.CloseBlockPrintQueue()
assertBlockEquals(t, tracer, filepath.Join("testdata", goldenDir, string(model)), len(blocks))
})
assertBlockEquals(t, tracer, filepath.Join("testdata", goldenDir, string(model)), len(blocks))
})
}
}
}

View file

@ -29,17 +29,17 @@ type firehoseInitLine struct {
type firehoseBlockLines []firehoseBlockLine
func newFirehoseTestTracer(t *testing.T, model tracingModel) (*tracers.Firehose, *tracing.Hooks, func()) {
func newFirehoseTestTracer(t *testing.T, model tracingModel, concurrentBlockFlushing bool) (*tracers.Firehose, *tracing.Hooks, func()) {
t.Helper()
tracer, err := tracers.NewFirehoseFromRawJSON([]byte(fmt.Sprintf(`{
"concurrentBlockFlushing": true,
"concurrentBlockFlushing": %t,
"_private": {
"flushToTestBuffer": true,
"ignoreGenesisBlock": true,
"forcedBackwardCompatibility": %t
}
}`, model == tracingModelFirehose2_3)))
}`, concurrentBlockFlushing, model == tracingModelFirehose2_3)))
require.NoError(t, err)
hooks := tracers.NewTracingHooksFromFirehose(tracer)