Commit 271d953d authored by Kirill Smelkov's avatar Kirill Smelkov

X rebuild: tests: Move ΔBtail.Clone test out of hot inner loop into separate test

73s -> 68s
parent 43090ac7
......@@ -1119,11 +1119,6 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1
// after rebuild
/* trackSet=*/ t2.xkv.trackSet(keys12R2),
/*vδT=*/ δkv1_k12R2, δkv2_k12R2)
// XXX move vvv to separate test (out of this inner loop)
// ΔBtail.Clone had bug that aliased klon data to orig
assertΔTtail(t, "BUG: after clone check", δbtail, t2, treeRoot, xat,
/*vδT=*/ δkv1_k1R2, δkv2_k1R2)
//})
}
})
......@@ -1395,7 +1390,7 @@ func ΔBTest(xtest interface{}) ΔBTestEntry {
//
// It combines TreeSrv and client side access to ZODB with committed trees. XXX
//
// Create it with tTreeEnv().
// Create it with tNewTreeEnv().
type tTreeEnv struct {
*testing.T
......@@ -1455,7 +1450,7 @@ func tNewTreeEnv(t *testing.T) *tTreeEnv {
tree: "T/B:", // treegen.py creates the tree as initially empty
prev: nil,
at: head,
xkv: XGetTree(tt.db, head, tt.treeSrv.treeRoot),
xkv: XGetTree(tt.db, head, tt.Root()),
blkDataTab: xGetBlkDataTab(tt.db, head),
δZ: nil,
δxkv: nil,
......@@ -1474,6 +1469,10 @@ func (_ *tZODBCacheEverything) PCacheClassify(_ zodb.IPersistent) zodb.PCachePol
return zodb.PCachePinObject | zodb.PCacheKeepState
}
// Root returns OID of root tree node.
func (t *tTreeEnv) Root() zodb.Oid {
return t.treeSrv.treeRoot
}
// Head returns most-recently committed tree.
func (t *tTreeEnv) Head() *tTreeCommit {
......@@ -1506,9 +1505,9 @@ func (t *tTreeEnv) CommitTree(tree string) *tTreeCommit {
// if the tree does not exist yet - report its structure as empty
var xkv RBucketSet
if tree != DEL {
xkv = XGetTree(t.db, δZ.Tid, t.treeSrv.treeRoot)
xkv = XGetTree(t.db, δZ.Tid, t.Root())
} else {
// empty tree with real treeSrv.treeRoot as oid even though the tree is
// empty tree with real treeRoot as oid even though the tree is
// deleted. Having real oid in the root tests that after deletion,
// root of the tree stays in the tracking set. We need root to stay
// in trackSet because e.g. in
......@@ -1522,7 +1521,7 @@ func (t *tTreeEnv) CommitTree(tree string) *tTreeCommit {
&RBucket{
oid: zodb.InvalidOid,
parent: &RTree{
oid: t.treeSrv.treeRoot, // NOTE oid is not InvalidOid
oid: t.Root(), // NOTE oid is not InvalidOid
parent: nil,
},
lo: KeyMin,
......@@ -1634,11 +1633,11 @@ func testΔBTail(t_ *testing.T, testq chan ΔBTestEntry) {
}
// ΔBTail.Update
xverifyΔBTail_Update(t.T, subj, t.db, t.treeSrv.treeRoot, t1,t2)
xverifyΔBTail_Update(t.T, subj, t.db, t.Root(), t1,t2)
// ΔBTail.rebuild
if t0 != nil {
xverifyΔBTail_rebuild(t.T, t.db, t.treeSrv.treeRoot, t0,t1,t2)
xverifyΔBTail_rebuild(t.T, t.db, t.Root(), t0,t1,t2)
}
t0, t1 = t1, t2
......@@ -2040,6 +2039,39 @@ func TestΔBTailAllStructs(t *testing.T) {
// ---- misc ----
func TestΔBtailClone(t_ *testing.T) {
// ΔBtail.Clone had bug that aliased klon data to orig
t := tNewTreeEnv(t_)
X := exc.Raiseif
t0 := t.CommitTree("T2/B1:a-B2:b")
t1 := t.CommitTree("T2/B1:c-B2:d")
δbtail := NewΔBtail(t0.at, t.db)
_, err := δbtail.Update(t1.δZ); X(err)
_2 := SetKey{}; _2.Add(2)
xtrackKeys(δbtail, t1, _2)
err = δbtail.rebuildAll(); X(err)
xat := map[zodb.Tid]string{
t0.at: "at0",
t1.at: "at1",
}
δkv1_1 := map[Key]Δstring{2:{"b","d"}}
assertΔTtail(t.T, "orig @at1", δbtail, t1, t.Root(), xat, δkv1_1)
δbklon := δbtail.Clone()
assertΔTtail(t.T, "klon @at1", δbklon, t1, t.Root(), xat, δkv1_1)
t2 := t.CommitTree("T/B1:b,2:a")
_, err = δbtail.Update(t2.δZ); X(err)
xat[t2.at] = "at2"
δkv1_2 := map[Key]Δstring{1:{"a","c"}, 2:{"b","d"}}
δkv2_2 := map[Key]Δstring{1:{"c","b"}, 2:{"d","a"}}
assertΔTtail(t.T, "orig @at2", δbtail, t2, t.Root(), xat, δkv1_2, δkv2_2)
assertΔTtail(t.T, "klon @at1 after orig @at->@at2", δbklon, t1, t.Root(), xat, δkv1_1)
}
// IntSets generates all sets of integers in range [0,N)
func IntSets(N int) chan []int {
......
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