Commit 26e8e3d3 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 96ed5401
......@@ -606,12 +606,14 @@ mainloop:
//tracef("-> tid=%s δoidv=%v", it.Txnh.Tid, oidv)
select {
case <-fs.down:
return nil
if fs.watchq != nil {
select {
case <-fs.down:
return nil
case fs.watchq <- zodb.WatchEvent{it.Txnh.Tid, oidv}:
// ok
case fs.watchq <- zodb.WatchEvent{it.Txnh.Tid, oidv}:
// ok
}
}
}
}
......
......@@ -117,7 +117,11 @@ func checkLoad(t *testing.T, fs *FileStorage, xid zodb.Xid, expect objState) {
}
func xfsopen(t testing.TB, path string) *FileStorage {
fs, err := Open(context.Background(), path)
return xfsopenopt(t, path, &zodb.DriverOptions{ReadOnly: true})
}
func xfsopenopt(t testing.TB, path string, opt *zodb.DriverOptions) *FileStorage {
fs, err := Open(context.Background(), path, opt)
if err != nil {
t.Fatal(err)
}
......@@ -125,7 +129,7 @@ func xfsopen(t testing.TB, path string) *FileStorage {
}
func TestLoad(t *testing.T) {
fs := xfsopen(t, "testdata/1.fs") // TODO open read-only
fs := xfsopen(t, "testdata/1.fs")
defer exc.XRun(fs.Close)
// current knowledge of what was "before" for an oid as we scan over
......@@ -274,7 +278,7 @@ func testIterate(t *testing.T, fs *FileStorage, tidMin, tidMax zodb.Tid, expectv
}
func TestIterate(t *testing.T) {
fs := xfsopen(t, "testdata/1.fs") // TODO open ro
fs := xfsopen(t, "testdata/1.fs")
defer exc.XRun(fs.Close)
// all []tids in test database
......@@ -310,7 +314,7 @@ func TestIterate(t *testing.T) {
}
func BenchmarkIterate(b *testing.B) {
fs := xfsopen(b, "testdata/1.fs") // TODO open ro
fs := xfsopen(b, "testdata/1.fs")
defer exc.XRun(fs.Close)
ctx := context.Background()
......@@ -421,7 +425,8 @@ func TestWatch(t *testing.T) {
// force tfs creation & open tfs at go side
at := xcommit(0, Object{0, "data0"})
fs := xfsopen(t, tfs)
watchq := make(chan zodb.WatchEvent)
fs := xfsopenopt(t, tfs, &zodb.DriverOptions{ReadOnly: true, WatchQ: watchq})
ctx := context.Background()
checkLastTid := func(lastOk zodb.Tid) {
......@@ -439,7 +444,7 @@ func TestWatch(t *testing.T) {
// commit -> check watcher observes what we committed.
//
// XXX python `import pkg_resources` takes ~ 200ms.
// XXX python `import pkg_resources` takes ~ 300ms.
// https://github.com/pypa/setuptools/issues/510
//
// Since pkg_resources are used everywhere (e.g. in zodburi to find all
......@@ -452,13 +457,10 @@ func TestWatch(t *testing.T) {
Object{0, fmt.Sprintf("data0.%d", i)},
Object{i, fmt.Sprintf("data%d", i)})
tid, objv, err := fs.Watch(ctx)
if err != nil {
t.Fatal(err)
}
e := <-watchq // XXX err?
if objvWant := []zodb.Oid{0, i}; !(tid == at && reflect.DeepEqual(objv, objvWant)) {
t.Fatalf("watch:\nhave: %s %s\nwant: %s %s", tid, objv, at, objvWant)
if objvWant := []zodb.Oid{0, i}; !(e.Tid == at && reflect.DeepEqual(e.Changev, objvWant)) {
t.Fatalf("watch:\nhave: %s %s\nwant: %s %s", e.Tid, e.Changev, at, objvWant)
}
checkLastTid(at)
......@@ -469,8 +471,13 @@ func TestWatch(t *testing.T) {
t.Fatal(err)
}
_, _, err = fs.Watch(ctx)
if e, eWant := errors.Cause(err), os.ErrClosed; e != eWant {
t.Fatalf("watch after close -> %v; want: cause %v", err, eWant)
}
e := <-watchq
_ = e
_ = errors.Cause(nil)
// XXX e.Err == ErrClosed
//_, _, err = fs.Watch(ctx)
//if e, eWant := errors.Cause(err), os.ErrClosed; e != eWant {
// t.Fatalf("watch after close -> %v; want: cause %v", err, eWant)
//}
}
......@@ -463,8 +463,8 @@ type Notifier interface {
// WatchEvent is one event describing observed database change.
type WatchEvent struct {
Tid Tid
Oidv []Oid
Tid Tid
Changev []Oid // XXX name
}
// Watcher allows to be notified of changes to database.
......
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