Commit 4c621541 authored by Kirill Smelkov's avatar Kirill Smelkov

X fs1: test for empty-file case

parent 98fa98ce
......@@ -23,6 +23,12 @@ package fs1tools
//go:generate sh -c "python2 -c 'from ZODB.FileStorage import fsdump; fsdump.main()' ../testdata/1.fs >testdata/1.fsdump.ok"
//go:generate sh -c "python2 -c 'from ZODB.FileStorage.fsdump import Dumper; import sys; d = Dumper(sys.argv[1]); d.dump()' ../testdata/1.fs >testdata/1.fsdumpv.ok"
// fstail.py crashes on empty.fs . The output should be empty file so generate it with just echo.
////go:generate sh -c "python2 -m ZODB.scripts.fstail -n 1000000 ../testdata/empty.fs >testdata/empty.fstail.ok"
//go:generate sh -c "echo -n >testdata/empty.fstail.ok"
//go:generate sh -c "python2 -c 'from ZODB.FileStorage import fsdump; fsdump.main()' ../testdata/empty.fs >testdata/empty.fsdump.ok"
//go:generate sh -c "python2 -c 'from ZODB.FileStorage.fsdump import Dumper; import sys; d = Dumper(sys.argv[1]); d.dump()' ../testdata/empty.fs >testdata/empty.fsdumpv.ok"
import (
"bytes"
"fmt"
......@@ -44,17 +50,22 @@ func loadFile(t *testing.T, path string) string {
}
func testDump(t *testing.T, dir fs1.IterDir, d Dumper) {
buf := bytes.Buffer{}
testv := []string{"1", "empty"}
for _, tt := range testv {
t.Run("db=" + tt, func(t *testing.T) {
buf := bytes.Buffer{}
err := Dump(&buf, "../testdata/1.fs", dir, d)
if err != nil {
t.Fatalf("%s: %v", d.DumperName(), err)
}
err := Dump(&buf, fmt.Sprintf("../testdata/%s.fs", tt), dir, d)
if err != nil {
t.Fatalf("%s: %v", d.DumperName(), err)
}
dumpOk := loadFile(t, fmt.Sprintf("testdata/1.%s.ok", d.DumperName()))
dumpOk := loadFile(t, fmt.Sprintf("testdata/%s.%s.ok", tt, d.DumperName()))
if dumpOk != buf.String() {
t.Errorf("%s: dump different:\n%v", d.DumperName(), diff.Diff(dumpOk, buf.String()))
if dumpOk != buf.String() {
t.Errorf("%s: dump different:\n%v", d.DumperName(), diff.Diff(dumpOk, buf.String()))
}
})
}
}
......
************************************************************
file identifier: 'FS21'
FS21
\ No newline at end of file
......@@ -20,10 +20,12 @@
package zodbtools
//go:generate sh -c "python2 -m zodbtools.zodb dump ../../zodb/storage/fs1/testdata/1.fs >testdata/1.zdump.pyok"
//go:generate sh -c "python2 -m zodbtools.zodb dump ../../zodb/storage/fs1/testdata/empty.fs >testdata/empty.zdump.pyok"
import (
"bytes"
"context"
"fmt"
"io/ioutil"
"regexp"
"testing"
......@@ -64,8 +66,8 @@ func loadZdumpPy(t *testing.T, path string) string {
return string(dump)
}
func withTestdata1Fs(t testing.TB, f func(zstor zodb.IStorage)) {
zstor, err := zodb.OpenStorage(context.Background(), "../../zodb/storage/fs1/testdata/1.fs", &zodb.OpenOptions{ReadOnly: true})
func withTestdataFs(t testing.TB, db string, f func(zstor zodb.IStorage)) {
zstor, err := zodb.OpenStorage(context.Background(), fmt.Sprintf("../../zodb/storage/fs1/testdata/%s.fs", db), &zodb.OpenOptions{ReadOnly: true})
if err != nil {
t.Fatal(err)
}
......@@ -76,26 +78,31 @@ func withTestdata1Fs(t testing.TB, f func(zstor zodb.IStorage)) {
}
func TestZodbDump(t *testing.T) {
withTestdata1Fs(t, func(zstor zodb.IStorage) {
buf := bytes.Buffer{}
err := Dump(context.Background(), &buf, zstor, 0, zodb.TidMax, false)
if err != nil {
t.Fatal(err)
}
dumpOk := loadZdumpPy(t, "testdata/1.zdump.pyok")
if dumpOk != buf.String() {
t.Errorf("dump different:\n%v", diff.Diff(dumpOk, buf.String()))
}
})
testv := []string{"1", "empty"}
for _, tt := range testv {
t.Run("db=" + tt, func(t *testing.T) {
withTestdataFs(t, tt, func(zstor zodb.IStorage) {
buf := bytes.Buffer{}
err := Dump(context.Background(), &buf, zstor, 0, zodb.TidMax, false)
if err != nil {
t.Fatal(err)
}
dumpOk := loadZdumpPy(t, fmt.Sprintf("testdata/%s.zdump.pyok", tt))
if dumpOk != buf.String() {
t.Errorf("dump different:\n%v", diff.Diff(dumpOk, buf.String()))
}
})
})
}
}
func BenchmarkZodbDump(b *testing.B) {
// FIXME small testdata/1.fs is not representative for benchmarking
withTestdata1Fs(b, func(zstor zodb.IStorage) {
withTestdataFs(b, "1", func(zstor zodb.IStorage) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
......
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