fix test by closing logger file

Was expecting lumberjack.Rotate() to close the file
This commit is contained in:
Chris Ziogas 2024-03-29 22:03:34 +02:00
parent cba97ef430
commit 4708a19319
No known key found for this signature in database
GPG key ID: 2329CF479E36E2DA
2 changed files with 5 additions and 7 deletions

View file

@ -528,10 +528,8 @@ func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockG
engine = beacon.New(ethash.NewFaker())
)
tmpDir := t.TempDir()
traceOutputPath := filepath.ToSlash(tmpDir)
traceOutputPath := filepath.ToSlash(t.TempDir())
traceOutputFilename := path.Join(traceOutputPath, "supply.jsonl")
t.Cleanup(func() { os.RemoveAll(tmpDir) })
// Load supply tracer
tracer, err := tracers.LiveDirectory.New("supply", json.RawMessage(fmt.Sprintf(`{"path":"%s"}`, traceOutputPath)))
@ -555,7 +553,6 @@ func testSupplyTracer(t *testing.T, genesis *core.Genesis, gen func(*core.BlockG
}
// Check and compare the results
// TODO: replace file to pass results
file, err := os.OpenFile(traceOutputFilename, os.O_RDONLY, 0666)
if err != nil {
return nil, chain, fmt.Errorf("failed to open output file: %v", err)

View file

@ -67,15 +67,16 @@ func newSupply(cfg json.RawMessage) (*tracing.Hooks, error) {
}
// Store traces in a rotating file
loggerOutput := &lumberjack.Logger{
loggerOutputFile := &lumberjack.Logger{
Filename: filepath.Join(config.Path, "supply.jsonl"),
}
defer loggerOutputFile.Close()
if config.MaxSize > 0 {
loggerOutput.MaxSize = config.MaxSize
loggerOutputFile.MaxSize = config.MaxSize
}
logger := log.New(loggerOutput, "", 0)
logger := log.New(loggerOutputFile, "", 0)
supplyInfo := newSupplyInfo()