Commit 5b18d781 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 3356c294
......@@ -46,6 +46,16 @@ type Storage struct {
baseAt0 zodb.Tid
}
// baseMutatedError is reported when Storage.base is detected to change.
type baseMutatedError struct {
baseAt0 zodb.Tid
baseHead zodb.Tid
}
func (e *baseMutatedError) Error() string {
return fmt.Sprintf("base.head mutated from @%s to @%s", e.baseAt0, e.baseHead)
}
// Close implements zodb.IStorageDriver .
func (d *Storage) Close() (err error) {
......
......@@ -26,6 +26,7 @@ import (
"fmt"
"net/url"
"os"
"reflect"
"regexp"
"testing"
......@@ -170,11 +171,11 @@ func TestWatch(t *testing.T) {
}
// MutateBase mutates ddat.base with new commit.
func (ddat *DemoData) MutateBase() error {
_, err = xtesting.ZPyCommitRaw(ddat.base, 0, xtesting.ZRawObject{
func (ddat *DemoData) MutateBase() (zodb.Tid, error) {
return xtesting.ZPyCommitRaw(ddat.base, 0, xtesting.ZRawObject{
Oid: 1,
Data: []byte("ZZZ"),
}); X(err)
})
}
// TestSync_vs_BaseMutate verifies Sync wrt base mutation.
......@@ -187,10 +188,13 @@ func TestSync_vs_BaseMutate(t *testing.T) {
t.Fatalf("sync0: head=%s err=%s", head, err)
}
err = ddat.MutateBase(); X(err)
tid, err := ddat.MutateBase(); X(err)
head, err := ddrv.Sync(context.Background())
errOk := &zodb.OpError{URL: ddrv.URL(), Op: "sync", Err: ...}
head, err = ddrv.Sync(context.Background())
errOk := &zodb.OpError{URL: ddrv.URL(), Op: "sync", Err: &baseMutatedError{
baseAt0: 0,
baseHead: tid,
}}
if !reflect.DeepEqual(err, errOk) {
t.Fatalf("after base mutate: sync: unexpected error:\nhave: %s\nwant: %s",
err, errOk)
......@@ -204,12 +208,12 @@ func TestWatchLoad_vs_BaseMutate(t *testing.T) {
X := xtesting.FatalIf(t)
watchq := make(chan zodb.Event)
ddrv, at0, err = demoOpen(ddat.URL(), &zodb.DriverOptions{
ddrv, at0, err := demoOpen(ddat.URL(), &zodb.DriverOptions{
ReadOnly: true,
Watchq: watchq,
}); X(err)
err = ddat.MutateBase(); X(err)
tid, err := ddat.MutateBase(); X(err)
// first wait for error from watchq
event := <-watchq
......@@ -218,15 +222,20 @@ func TestWatchLoad_vs_BaseMutate(t *testing.T) {
t.Fatalf("unexpected event: %T", event)
}
evErrOk := &zodb.EventError{Err: ...} // XXX
errBaseMutated := &baseMutatedError{
baseAt0: 0,
baseHead: tid,
}
evErrOk := &zodb.EventError{Err: errBaseMutated}
if !reflect.DeepEqual(evErr, evErrOk) {
t.Fatalf("after base mutate: unexpected event:\nhave: %s\nwant: %s", evErr, evErrOk)
}
// now make sure Load fails with "base mutated" error
xid := zodb.Xid{Oid: 1, At: zodb.MaxTid}
xid := zodb.Xid{Oid: 1, At: at0}
data, serial, err := ddrv.Load(context.Background(), xid)
errOk := &zodb.OpError{URL: ddrv.URL(), Op: "load", Args: xid, Err: ...}
errOk := &zodb.OpError{URL: ddrv.URL(), Op: "load", Args: xid, Err: errBaseMutated}
if !reflect.DeepEqual(err, errOk) {
t.Fatalf("after base mutate: load: unexpected error:\nhave: %s\nwant: %s",
err, errOk)
......
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