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 ...@@ -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 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" //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 ( import (
"bytes" "bytes"
"fmt" "fmt"
...@@ -44,18 +50,23 @@ func loadFile(t *testing.T, path string) string { ...@@ -44,18 +50,23 @@ func loadFile(t *testing.T, path string) string {
} }
func testDump(t *testing.T, dir fs1.IterDir, d Dumper) { func testDump(t *testing.T, dir fs1.IterDir, d Dumper) {
testv := []string{"1", "empty"}
for _, tt := range testv {
t.Run("db=" + tt, func(t *testing.T) {
buf := bytes.Buffer{} buf := bytes.Buffer{}
err := Dump(&buf, "../testdata/1.fs", dir, d) err := Dump(&buf, fmt.Sprintf("../testdata/%s.fs", tt), dir, d)
if err != nil { if err != nil {
t.Fatalf("%s: %v", d.DumperName(), err) 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() { if dumpOk != buf.String() {
t.Errorf("%s: dump different:\n%v", d.DumperName(), diff.Diff(dumpOk, buf.String())) t.Errorf("%s: dump different:\n%v", d.DumperName(), diff.Diff(dumpOk, buf.String()))
} }
})
}
} }
func TestFsDump(t *testing.T) { testDump(t, fs1.IterForward, &DumperFsDump{}) } func TestFsDump(t *testing.T) { testDump(t, fs1.IterForward, &DumperFsDump{}) }
......
************************************************************
file identifier: 'FS21'
FS21
\ No newline at end of file
...@@ -20,10 +20,12 @@ ...@@ -20,10 +20,12 @@
package zodbtools 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/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 ( import (
"bytes" "bytes"
"context" "context"
"fmt"
"io/ioutil" "io/ioutil"
"regexp" "regexp"
"testing" "testing"
...@@ -64,8 +66,8 @@ func loadZdumpPy(t *testing.T, path string) string { ...@@ -64,8 +66,8 @@ func loadZdumpPy(t *testing.T, path string) string {
return string(dump) return string(dump)
} }
func withTestdata1Fs(t testing.TB, f func(zstor zodb.IStorage)) { func withTestdataFs(t testing.TB, db string, f func(zstor zodb.IStorage)) {
zstor, err := zodb.OpenStorage(context.Background(), "../../zodb/storage/fs1/testdata/1.fs", &zodb.OpenOptions{ReadOnly: true}) zstor, err := zodb.OpenStorage(context.Background(), fmt.Sprintf("../../zodb/storage/fs1/testdata/%s.fs", db), &zodb.OpenOptions{ReadOnly: true})
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -76,7 +78,10 @@ func withTestdata1Fs(t testing.TB, f func(zstor zodb.IStorage)) { ...@@ -76,7 +78,10 @@ func withTestdata1Fs(t testing.TB, f func(zstor zodb.IStorage)) {
} }
func TestZodbDump(t *testing.T) { func TestZodbDump(t *testing.T) {
withTestdata1Fs(t, func(zstor zodb.IStorage) { 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{} buf := bytes.Buffer{}
err := Dump(context.Background(), &buf, zstor, 0, zodb.TidMax, false) err := Dump(context.Background(), &buf, zstor, 0, zodb.TidMax, false)
...@@ -84,18 +89,20 @@ func TestZodbDump(t *testing.T) { ...@@ -84,18 +89,20 @@ func TestZodbDump(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
dumpOk := loadZdumpPy(t, "testdata/1.zdump.pyok") dumpOk := loadZdumpPy(t, fmt.Sprintf("testdata/%s.zdump.pyok", tt))
if dumpOk != buf.String() { if dumpOk != buf.String() {
t.Errorf("dump different:\n%v", diff.Diff(dumpOk, buf.String())) t.Errorf("dump different:\n%v", diff.Diff(dumpOk, buf.String()))
} }
}) })
})
}
} }
func BenchmarkZodbDump(b *testing.B) { func BenchmarkZodbDump(b *testing.B) {
// FIXME small testdata/1.fs is not representative for benchmarking // 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() b.ResetTimer()
for i := 0; i < b.N; i++ { 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