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

.

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