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

.

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