Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable multitests for the consolereader #111

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codec/console_reader_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func BenchmarkConsoleReader(b *testing.B) {
channel <- string(line)
}

readers[n] = testReaderConsoleReader(b.Helper, channel, func() {}, zaptest.NewLogger(b, zaptest.Level(zap.InfoLevel)))
readers[n] = testReaderConsoleReader(b.Helper, channel, func() {}, zaptest.NewLogger(b, zaptest.Level(zap.InfoLevel)), newABIDecoder())

// We close it right now, it will still be fully consumed
close(channel)
Expand Down
26 changes: 16 additions & 10 deletions codec/consolereader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ func TestParseFromFile(t *testing.T) {
tests := []struct {
name string
deepMindFile string
includeBlock func(block *pbantelope.Block) bool
strictMode bool
// includeBlock func(block *pbantelope.Block) bool
// readerOptions []ConsoleReaderOption
}{
// {"full", "testdata/deep-mind.dmlog", nil /*nil*/},
// {"full-3.1.x", "testdata/deep-mind-3.1.x.dmlog", nil /*nil*/},
{"dmlog", "testdata/dm.log", nil /*nil*/},
// {"full", "testdata/deep-mind.dmlog", /*nil nil*/},
{"full-3.1.x", "testdata/deep-mind-3.1.x.dmlog", false /*nil, nil*/},
{"dmlog", "testdata/dm.log", true /*nil, nil*/},
// {"max-console-log", "testdata/deep-mind.dmlog", blockWithConsole /*[]ConsoleReaderOption{LimitConsoleLength(10)}*/},
}

Expand All @@ -60,7 +61,7 @@ func TestParseFromFile(t *testing.T) {
// }
//}()

cr := testFileConsoleReader(t, test.deepMindFile)
cr := testFileConsoleReader(t, test.deepMindFile, test.strictMode)

var reader ObjectReader = func() (interface{}, error) {
out, err := cr.ReadBlock()
Expand Down Expand Up @@ -147,7 +148,7 @@ func unifiedDiff(t *testing.T, cnt1, cnt2 []byte) string {
func TestGeneratePBBlocks(t *testing.T) {
t.Skip("generate only when deep-mind-3.1.x.dmlog changes")

cr := testFileConsoleReader(t, "testdata/deep-mind-3.1.x.dmlog")
cr := testFileConsoleReader(t, "testdata/deep-mind-3.1.x.dmlog", false)

for {
out, err := cr.ReadBlock()
Expand Down Expand Up @@ -177,15 +178,20 @@ func TestGeneratePBBlocks(t *testing.T) {
}
}

func testFileConsoleReader(t *testing.T, filename string) *ConsoleReader {
func testFileConsoleReader(t *testing.T, filename string, strictMode bool) *ConsoleReader {
t.Helper()

fl, err := os.Open(filename)
require.NoError(t, err)

abiDecoder := newABIDecoder()
if strictMode {
abiDecoder = newABIDecoderInStrictMode()
}

// todo use this if you want A LOT of logging
// cr := testReaderConsoleReader(t.Helper, make(chan string, 10000), func() { fl.Close() }, zaptest.NewLogger(t))
cr := testReaderConsoleReader(t.Helper, make(chan string, 10000), func() { fl.Close() }, nil)
cr := testReaderConsoleReader(t.Helper, make(chan string, 10000), func() { fl.Close() }, nil, abiDecoder)

go func() {
err := cr.ProcessData(fl)
Expand All @@ -197,7 +203,7 @@ func testFileConsoleReader(t *testing.T, filename string) *ConsoleReader {
return cr
}

func testReaderConsoleReader(helperFunc func(), lines chan string, closer func(), logger *zap.Logger) *ConsoleReader {
func testReaderConsoleReader(helperFunc func(), lines chan string, closer func(), logger *zap.Logger, abiDecoder *ABIDecoder) *ConsoleReader {

l := &ConsoleReader{
lines: lines,
Expand All @@ -208,7 +214,7 @@ func testReaderConsoleReader(helperFunc func(), lines chan string, closer func()
globalStats: newConsoleReaderStats(),
currentBlock: &pbantelope.Block{},
currentTrace: &pbantelope.TransactionTrace{},
abiDecoder: newABIDecoderInStrictMode(),
abiDecoder: abiDecoder,
},
logger: zlogTest,
}
Expand Down