Commit 9d13ca2c authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 9d8e264f
......@@ -814,7 +814,7 @@ func Open(ctx context.Context, path string, opt *zodb.DriverOptions) (_ *FileSto
var errFirstRead chan error
if checkTailGarbage {
defer xerr.Contextf(&err, "open %s: checking whether it is garbage at @%d", path, index.TopPos)
defer xerr.Contextf(&err, "open %s: checking whether it is garbage @%d", path, index.TopPos)
errFirstRead = make(chan error, 1)
}
......
......@@ -482,17 +482,27 @@ func TestOpenRecovery(t *testing.T) {
main, err := ioutil.ReadFile("testdata/1.fs"); X(err)
index, err := ioutil.ReadFile("testdata/1.fs.index"); X(err)
lastTidOk := _1fs_dbEntryv[len(_1fs_dbEntryv)-1].Header.Tid
topPos := int64(_1fs_indexTopPos)
voteTail, err := ioutil.ReadFile("testdata/1voted.tail"); X(err)
workdir := xworkdir(t)
ctx := context.Background()
for l := len(voteTail); l >= 0; l-- {
// checkL runs f on main + voteTail[:l]
checkL := func(t *testing.T, l int, f func(t *testing.T, tfs string)) {
t.Run(fmt.Sprintf("tail=+vote%d", l), func(t *testing.T) {
tfs := fmt.Sprintf("%s/1+vote%d.fs", workdir, l)
err := ioutil.WriteFile(tfs, append(main, voteTail[:l]...), 0600); X(err)
err = ioutil.WriteFile(tfs+".index", index, 0600); X(err)
f(t, tfs)
})
}
// if txn header can be fully read - it should be all ok
// XXX also test +0?
for l := len(voteTail); l >= TxnHeaderFixSize; l-- {
checkL(t, l, func(t *testing.T, tfs string) {
fs := xfsopen(t, tfs)
head, err := fs.LastTid(ctx); X(err)
if head != lastTidOk {
......@@ -502,4 +512,20 @@ func TestOpenRecovery(t *testing.T) {
err = fs.Close(); X(err)
})
}
// if txn header is not complete - open should fail
for _, l := range []int{TxnHeaderFixSize-1,1} {
checkL(t, l, func(t *testing.T, tfs string) {
_, err := Open(ctx, tfs, &zodb.DriverOptions{ReadOnly: true})
estr := ""
if err != nil {
estr = err.Error()
}
ewant := fmt.Sprintf("open %s: checking whether it is garbage @%d: %s",
tfs, topPos, &RecordError{tfs, "transaction record", topPos, "read", io.ErrUnexpectedEOF})
if estr != ewant {
t.Fatalf("unexpected error:\nhave: %q\nwant: %q", estr, ewant)
}
})
}
}
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