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

.

parent a1ceb162
......@@ -169,46 +169,71 @@ func TestWatch(t *testing.T) {
})
}
// withDemoBaseMutated tests f with demo: client connected to Storage and base
// just mutated with new commit.
func withDemoBaseMutated(t *testing.T, f func(t *testing.T, ddrv *Storage)) {
// MutateBase mutates ddat.base with new commit.
func (ddat *DemoData) MutateBase() error {
_, 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) {
X := xtesting.FatalIf(t)
/* XXX kill?
head, err := ddrv.Sync(context.Background())
if !(head == 0 && err == nil) {
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)
})
}
// 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)
err = ddat.MutateBase(); X(err)
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.
func TestLoad_vs_BaseMutate(t *testing.T) {
withDemoBaseMutated(t, func(t *testing.T, ddrv *Storage) {
func TestWatchLoad_vs_BaseMutate(t *testing.T) {
withDemoData(t, func(t *testing.T, ddat *DemoData) {
X := xtesting.FatalIf(t)
// XXX first wait for error from watchq
data, serial, err := ddrv.Load(context.Background(), ...)
// XXX verify err
watchq := make(chan zodb.Event)
ddrv, at0, err = demoOpen(ddat.URL(), &zodb.DriverOptions{
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