Commit 3356c294 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent a1ceb162
...@@ -169,46 +169,71 @@ func TestWatch(t *testing.T) { ...@@ -169,46 +169,71 @@ func TestWatch(t *testing.T) {
}) })
} }
// withDemoBaseMutated tests f with demo: client connected to Storage and base // MutateBase mutates ddat.base with new commit.
// just mutated with new commit. func (ddat *DemoData) MutateBase() error {
func withDemoBaseMutated(t *testing.T, f func(t *testing.T, ddrv *Storage)) { _, err = xtesting.ZPyCommitRaw(ddat.base, 0, xtesting.ZRawObject{
Oid: 1,
Data: []byte("ZZZ"),
}); X(err)
}
// TestSync_vs_BaseMutate verifies Sync wrt base mutation.
func TestSync_vs_BaseMutate(t *testing.T) {
withDemo(t, func(t *testing.T, ddat *DemoData, ddrv *Storage) { withDemo(t, func(t *testing.T, ddat *DemoData, ddrv *Storage) {
X := xtesting.FatalIf(t) X := xtesting.FatalIf(t)
/* XXX kill?
head, err := ddrv.Sync(context.Background()) head, err := ddrv.Sync(context.Background())
if !(head == 0 && err == nil) { if !(head == 0 && err == nil) {
t.Fatalf("sync0: head=%s err=%s", head, err) t.Fatalf("sync0: head=%s err=%s", head, err)
} }
*/
_, err = xtesting.ZPyCommitRaw(ddat.base, 0, xtesting.ZRawObject{
Oid: 1,
Data: []byte("ZZZ"),
}); X(err)
f(t, ddrv) err = ddat.MutateBase(); X(err)
})
}
// TestSync_vs_BaseMutate verifies Sync wrt base mutation.
func TestSync_vs_BaseMutate(t *testing.T) {
withDemoBaseMutated(t, func(t *testing.T, ddrv *Storage) {
X := xtesting.FatalIf(t)
head, err := ddrv.Sync(context.Background()) head, err := ddrv.Sync(context.Background())
// XXX verify err errOk := &zodb.OpError{URL: ddrv.URL(), Op: "sync", Err: ...}
if !reflect.DeepEqual(err, errOk) {
t.Fatalf("after base mutate: sync: unexpected error:\nhave: %s\nwant: %s",
err, errOk)
}
}) })
} }
// TestWatchLoad_vs_BaseMutate verifies Watch and Load wrt base mutation. // TestWatchLoad_vs_BaseMutate verifies Watch and Load wrt base mutation.
func TestLoad_vs_BaseMutate(t *testing.T) { func TestWatchLoad_vs_BaseMutate(t *testing.T) {
withDemoBaseMutated(t, func(t *testing.T, ddrv *Storage) { withDemoData(t, func(t *testing.T, ddat *DemoData) {
X := xtesting.FatalIf(t) X := xtesting.FatalIf(t)
// XXX first wait for error from watchq watchq := make(chan zodb.Event)
data, serial, err := ddrv.Load(context.Background(), ...) ddrv, at0, err = demoOpen(ddat.URL(), &zodb.DriverOptions{
// XXX verify err ReadOnly: true,
Watchq: watchq,
}); X(err)
err = ddat.MutateBase(); X(err)
// first wait for error from watchq
event := <-watchq
evErr, ok := event.(*zodb.EventError)
if !ok {
t.Fatalf("unexpected event: %T", event)
}
evErrOk := &zodb.EventError{Err: ...} // XXX
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}
data, serial, err := ddrv.Load(context.Background(), xid)
errOk := &zodb.OpError{URL: ddrv.URL(), Op: "load", Args: xid, Err: ...}
if !reflect.DeepEqual(err, errOk) {
t.Fatalf("after base mutate: load: unexpected error:\nhave: %s\nwant: %s",
err, errOk)
}
if !(data == nil && serial == 0) {
t.Fatalf("after base mutate: load: unexpected data=%v serial=%v", data, serial)
}
}) })
} }
......
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