From 4ac04ae0feba560e93f0fad55772b8830b759d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E5=BD=AC?= Date: Wed, 17 Jul 2019 19:20:24 +0800 Subject: all: replace fmt.Print* calls with t.Log* in tests (#19670) --- eth/downloader/downloader_test.go | 4 ++-- eth/filters/bench_test.go | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'eth') diff --git a/eth/downloader/downloader_test.go b/eth/downloader/downloader_test.go index e1f0e03fc..b23043b1c 100644 --- a/eth/downloader/downloader_test.go +++ b/eth/downloader/downloader_test.go @@ -1614,8 +1614,8 @@ func TestRemoteHeaderRequestSpan(t *testing.T) { if failed { res := strings.Replace(fmt.Sprint(data), " ", ",", -1) exp := strings.Replace(fmt.Sprint(tt.expected), " ", ",", -1) - fmt.Printf("got: %v\n", res) - fmt.Printf("exp: %v\n", exp) + t.Logf("got: %v\n", res) + t.Logf("exp: %v\n", exp) t.Errorf("test %d: wrong values", i) } } diff --git a/eth/filters/bench_test.go b/eth/filters/bench_test.go index 434e6a44c..fc7e6f527 100644 --- a/eth/filters/bench_test.go +++ b/eth/filters/bench_test.go @@ -64,7 +64,7 @@ const benchFilterCnt = 2000 func benchmarkBloomBits(b *testing.B, sectionSize uint64) { benchDataDir := node.DefaultDataDir() + "/geth/chaindata" - fmt.Println("Running bloombits benchmark section size:", sectionSize) + b.Log("Running bloombits benchmark section size:", sectionSize) db, err := rawdb.NewLevelDBDatabase(benchDataDir, 128, 1024, "") if err != nil { @@ -76,7 +76,7 @@ func benchmarkBloomBits(b *testing.B, sectionSize uint64) { } clearBloomBits(db) - fmt.Println("Generating bloombits data...") + b.Log("Generating bloombits data...") headNum := rawdb.ReadHeaderNumber(db, head) if headNum == nil || *headNum < sectionSize+512 { b.Fatalf("not enough blocks for running a benchmark") @@ -111,16 +111,16 @@ func benchmarkBloomBits(b *testing.B, sectionSize uint64) { rawdb.WriteBloomBits(db, uint(i), sectionIdx, sectionHead, comp) } //if sectionIdx%50 == 0 { - // fmt.Println(" section", sectionIdx, "/", cnt) + // b.Log(" section", sectionIdx, "/", cnt) //} } d := time.Since(start) - fmt.Println("Finished generating bloombits data") - fmt.Println(" ", d, "total ", d/time.Duration(cnt*sectionSize), "per block") - fmt.Println(" data size:", dataSize, " compressed size:", compSize, " compression ratio:", float64(compSize)/float64(dataSize)) + b.Log("Finished generating bloombits data") + b.Log(" ", d, "total ", d/time.Duration(cnt*sectionSize), "per block") + b.Log(" data size:", dataSize, " compressed size:", compSize, " compression ratio:", float64(compSize)/float64(dataSize)) - fmt.Println("Running filter benchmarks...") + b.Log("Running filter benchmarks...") start = time.Now() mux := new(event.TypeMux) var backend *testBackend @@ -140,8 +140,8 @@ func benchmarkBloomBits(b *testing.B, sectionSize uint64) { } } d = time.Since(start) - fmt.Println("Finished running filter benchmarks") - fmt.Println(" ", d, "total ", d/time.Duration(benchFilterCnt), "per address", d*time.Duration(1000000)/time.Duration(benchFilterCnt*cnt*sectionSize), "per million blocks") + b.Log("Finished running filter benchmarks") + b.Log(" ", d, "total ", d/time.Duration(benchFilterCnt), "per address", d*time.Duration(1000000)/time.Duration(benchFilterCnt*cnt*sectionSize), "per million blocks") db.Close() } @@ -158,7 +158,7 @@ func clearBloomBits(db ethdb.Database) { func BenchmarkNoBloomBits(b *testing.B) { benchDataDir := node.DefaultDataDir() + "/geth/chaindata" - fmt.Println("Running benchmark without bloombits") + b.Log("Running benchmark without bloombits") db, err := rawdb.NewLevelDBDatabase(benchDataDir, 128, 1024, "") if err != nil { b.Fatalf("error opening database at %v: %v", benchDataDir, err) @@ -171,14 +171,14 @@ func BenchmarkNoBloomBits(b *testing.B) { clearBloomBits(db) - fmt.Println("Running filter benchmarks...") + b.Log("Running filter benchmarks...") start := time.Now() mux := new(event.TypeMux) backend := &testBackend{mux, db, 0, new(event.Feed), new(event.Feed), new(event.Feed), new(event.Feed)} filter := NewRangeFilter(backend, 0, int64(*headNum), []common.Address{{}}, nil) filter.Logs(context.Background()) d := time.Since(start) - fmt.Println("Finished running filter benchmarks") - fmt.Println(" ", d, "total ", d*time.Duration(1000000)/time.Duration(*headNum+1), "per million blocks") + b.Log("Finished running filter benchmarks") + b.Log(" ", d, "total ", d*time.Duration(1000000)/time.Duration(*headNum+1), "per million blocks") db.Close() } -- cgit v1.2.3