Commit a708663d authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb/fs1tools: tests: Use fresh dumper for each subtest

We were reusing Dumper instance in between testDump subtests. This was
not noticed, as it was only "1" and then "empty" case, because "emtpy"
has no transactions. However in the next patch we'll add another
subcase, and if the dumper instance is not reset, it will think that it
starts from transaction number non-zero, which would differ from fresh
dumper output.

-> Fix it.
parent fc69e00d
// Copyright (C) 2017 Nexedi SA and Contributors. // Copyright (C) 2017-2021 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
// it under the terms of the GNU General Public License version 3, or (at your // it under the terms of the GNU General Public License version 3, or (at your
...@@ -48,10 +48,11 @@ func loadFile(t *testing.T, path string) string { ...@@ -48,10 +48,11 @@ func loadFile(t *testing.T, path string) string {
return string(data) return string(data)
} }
func testDump(t *testing.T, dir fs1.IterDir, d Dumper) { func testDump(t *testing.T, dir fs1.IterDir, newd func() Dumper) {
testv := []string{"1", "empty"} testv := []string{"1", "empty"}
for _, tt := range testv { for _, tt := range testv {
t.Run("db=" + tt, func(t *testing.T) { t.Run("db=" + tt, func(t *testing.T) {
d := newd()
buf := bytes.Buffer{} buf := bytes.Buffer{}
err := Dump(&buf, fmt.Sprintf("../testdata/%s.fs", tt), dir, d) err := Dump(&buf, fmt.Sprintf("../testdata/%s.fs", tt), dir, d)
...@@ -68,9 +69,13 @@ func testDump(t *testing.T, dir fs1.IterDir, d Dumper) { ...@@ -68,9 +69,13 @@ func testDump(t *testing.T, dir fs1.IterDir, d Dumper) {
} }
} }
func TestFsDump(t *testing.T) { testDump(t, fs1.IterForward, &DumperFsDump{}) } func newFsDump() Dumper { return &DumperFsDump{} }
func TestFsDumpv(t *testing.T) { testDump(t, fs1.IterForward, &DumperFsDumpVerbose{}) } func newFsDumpv() Dumper { return &DumperFsDumpVerbose{} }
func TestFsTail(t *testing.T) { testDump(t, fs1.IterBackward, &DumperFsTail{Ntxn: 1000000}) } func newFsTail() Dumper { return &DumperFsTail{Ntxn: 1000000} }
func TestFsDump(t *testing.T) { testDump(t, fs1.IterForward, newFsDump) }
func TestFsDumpv(t *testing.T) { testDump(t, fs1.IterForward, newFsDumpv) }
func TestFsTail(t *testing.T) { testDump(t, fs1.IterBackward, newFsTail) }
func BenchmarkTail(b *testing.B) { func BenchmarkTail(b *testing.B) {
// FIXME small testdata/1.fs is not representative for benchmarking // FIXME small testdata/1.fs is not representative for benchmarking
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment