Commit 6f2d565c authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 051cf040
...@@ -66,7 +66,7 @@ func (o *myObjectState) PyGetState() interface{} { ...@@ -66,7 +66,7 @@ func (o *myObjectState) PyGetState() interface{} {
return o.value return o.value
} }
// Peristent that is not registered to ZODB. // Persistent that is not registered to ZODB.
type Unregistered struct { type Unregistered struct {
Persistent Persistent
} }
...@@ -219,7 +219,7 @@ type tPersistentDB struct { ...@@ -219,7 +219,7 @@ type tPersistentDB struct {
conn *Connection conn *Connection
} }
// Get gets oid from t.conn and asserts it type. // Get gets oid from t.conn and asserts its type.
func (t *tPersistentDB) Get(oid Oid) *MyObject { func (t *tPersistentDB) Get(oid Oid) *MyObject {
t.Helper() t.Helper()
xobj, err := t.conn.Get(t.ctx, oid) xobj, err := t.conn.Get(t.ctx, oid)
...@@ -252,7 +252,10 @@ func (t *tPersistentDB) checkObj(obj *MyObject, oid Oid, serial Tid, state Objec ...@@ -252,7 +252,10 @@ func (t *tPersistentDB) checkObj(obj *MyObject, oid Oid, serial Tid, state Objec
t.Helper() t.Helper()
// any object with live pointer to it must be also in conn's cache. // any object with live pointer to it must be also in conn's cache.
connObj := t.conn.Cache().Get(oid) cache := t.conn.Cache()
cache.Lock()
connObj := cache.Get(oid)
cache.Unlock()
if obj != connObj { if obj != connObj {
t.Fatalf("cache.get %s -> not same object:\nhave: %#v\nwant: %#v", oid, connObj, oid) t.Fatalf("cache.get %s -> not same object:\nhave: %#v\nwant: %#v", oid, connObj, oid)
} }
...@@ -295,15 +298,15 @@ func (t *tPersistentDB) Resync(at Tid) { ...@@ -295,15 +298,15 @@ func (t *tPersistentDB) Resync(at Tid) {
t.txn = txn t.txn = txn
t.ctx = ctx t.ctx = ctx
assert.Equal(t, t.conn.db, db) assert.Same(t, t.conn.db, db)
assert.Equal(t, t.conn.txn, t.txn) assert.Same(t, t.conn.txn, t.txn)
assert.Equal(t, t.conn.At(), at) assert.Equal(t, t.conn.At(), at)
} }
// Abort aborts t's connection and verifies it becomes !live. // Abort aborts t's connection and verifies it becomes !live.
func (t *tPersistentDB) Abort() { func (t *tPersistentDB) Abort() {
t.Helper() t.Helper()
assert.Equal(t, t.conn.txn, t.txn) assert.Same(t, t.conn.txn, t.txn)
t.txn.Abort() t.txn.Abort()
assert.Equal(t, t.conn.txn, nil) assert.Equal(t, t.conn.txn, nil)
} }
...@@ -312,9 +315,14 @@ func (t *tPersistentDB) Abort() { ...@@ -312,9 +315,14 @@ func (t *tPersistentDB) Abort() {
// Persistent tests with storage. // Persistent tests with storage.
// //
// this test covers everything at application-level: Persistent, DB, Connection, LiveCache. // this test covers everything at application-level: Persistent, DB, Connection, LiveCache.
// func TestPersistentDB(t *testing.T) {
// XXX test for cache=y/n (raw data cache) // perform tests without and with raw data cache.
func TestPersistentDB(t0 *testing.T) { // (rawcache=y verifies how raw cache handles invalidations)
t.Run("rawcache=n", func(t *testing.T) { testPersistentDB(t, false) })
t.Run("rawcache=y", func(t *testing.T) { testPersistentDB(t, true) })
}
func testPersistentDB(t0 *testing.T, rawcache bool) {
X := exc.Raiseif X := exc.Raiseif
assert := assert.New(t0) assert := assert.New(t0)
...@@ -337,7 +345,7 @@ func TestPersistentDB(t0 *testing.T) { ...@@ -337,7 +345,7 @@ func TestPersistentDB(t0 *testing.T) {
// open connection to it via zodb/go // open connection to it via zodb/go
ctx := context.Background() ctx := context.Background()
stor, err := OpenStorage(ctx, zurl, &OpenOptions{ReadOnly: true}); X(err) stor, err := OpenStorage(ctx, zurl, &OpenOptions{ReadOnly: true, NoCache: !rawcache}); X(err)
db := NewDB(stor) db := NewDB(stor)
// testopen opens new db transaction/connection and wraps it with tPersistentDB. // testopen opens new db transaction/connection and wraps it with tPersistentDB.
...@@ -347,8 +355,8 @@ func TestPersistentDB(t0 *testing.T) { ...@@ -347,8 +355,8 @@ func TestPersistentDB(t0 *testing.T) {
txn, ctx := transaction.New(context.Background()) txn, ctx := transaction.New(context.Background())
conn, err := db.Open(ctx, opt); X(err) conn, err := db.Open(ctx, opt); X(err)
assert.Equal(conn.db, db) assert.Same(conn.db, db)
assert.Equal(conn.txn, txn) assert.Same(conn.txn, txn)
return &tPersistentDB{ return &tPersistentDB{
T: t0, T: t0,
...@@ -369,7 +377,9 @@ func TestPersistentDB(t0 *testing.T) { ...@@ -369,7 +377,9 @@ func TestPersistentDB(t0 *testing.T) {
// do not evict obj2 from live cache. obj1 is ok to be evicted. // do not evict obj2 from live cache. obj1 is ok to be evicted.
zcache1 := t.conn.Cache() zcache1 := t.conn.Cache()
zcache1.Lock()
zcache1.SetControl(&zcacheControl{[]Oid{_obj2.oid}}) zcache1.SetControl(&zcacheControl{[]Oid{_obj2.oid}})
zcache1.Unlock()
// get objects // get objects
obj1 := t.Get(101) obj1 := t.Get(101)
...@@ -455,7 +465,7 @@ func TestPersistentDB(t0 *testing.T) { ...@@ -455,7 +465,7 @@ func TestPersistentDB(t0 *testing.T) {
// open new connection - it should be conn1 but at updated database view // open new connection - it should be conn1 but at updated database view
t3 := testopen(&ConnOptions{}) t3 := testopen(&ConnOptions{})
assert.Equal(t3.conn, t1.conn) // XXX is assert.Same(t3.conn, t1.conn)
t = t3 t = t3
assert.Equal(t.conn.At(), at2) assert.Equal(t.conn.At(), at2)
assert.Equal(db.pool, []*Connection{}) assert.Equal(db.pool, []*Connection{})
...@@ -484,8 +494,8 @@ func TestPersistentDB(t0 *testing.T) { ...@@ -484,8 +494,8 @@ func TestPersistentDB(t0 *testing.T) {
runtime.GC() // need only 2 runs since cache uses finalizers runtime.GC() // need only 2 runs since cache uses finalizers
} }
xobj1 := t.conn.Cache().Get(101) xobj1 := t.conn.Cache().Get(101) // XXX locking
xobj2 := t.conn.Cache().Get(102) xobj2 := t.conn.Cache().Get(102) // XXX locking
assert.Equal(xobj1, nil) assert.Equal(xobj1, nil)
assert.NotEqual(xobj2, nil) assert.NotEqual(xobj2, nil)
obj2 = xobj2.(*MyObject) obj2 = xobj2.(*MyObject)
...@@ -506,7 +516,9 @@ func TestPersistentDB(t0 *testing.T) { ...@@ -506,7 +516,9 @@ func TestPersistentDB(t0 *testing.T) {
// pin obj2 into live cache, similarly to conn1 // pin obj2 into live cache, similarly to conn1
rzcache := t.conn.Cache() rzcache := t.conn.Cache()
rzcache.Lock()
rzcache.SetControl(&zcacheControl{[]Oid{_obj2.oid}}) rzcache.SetControl(&zcacheControl{[]Oid{_obj2.oid}})
rzcache.Unlock()
// it should see latest data // it should see latest data
robj1 := t.Get(101) robj1 := t.Get(101)
......
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