Commit a6300c60 authored by Kirill Smelkov's avatar Kirill Smelkov

X δbtail: tests: Clone after second update

        $ time go test -failfast -short -run 'ΔBTail/rebuild' >x

before:

        real    1m15,669s
        user    1m31,340s
        sys     0m10,171s

after:

	real    0m43,071s
	user    0m57,487s
	sys     0m4,869s
parent d52b0519
......@@ -825,6 +825,7 @@ func xverifyΔBTail_Update1(t *testing.T, subj string, db *zodb.DB, treeRoot zod
// assertTrack verifies that trackIdx == trackIdxOK.
// XXX place
func assertTrack(t *testing.T, subj string, trackIdx, trackIdxOK trackIndex) {
t.Helper()
if !reflect.DeepEqual(trackIdx, trackIdxOK) {
t.Errorf("%s:\n\thave: %v\n\twant: %v", subj, trackIdx, trackIdxOK)
}
......@@ -833,6 +834,7 @@ func assertTrack(t *testing.T, subj string, trackIdx, trackIdxOK trackIndex) {
// assertTrack verifies state of .trackIdx and .trackNew.
// XXX place
func (δbtail *ΔBtail) assertTrack(t *testing.T, subj string, trackIdxOK, trackNewOK trackIndex) {
t.Helper()
assertTrack(t, subj + ": trackIdx", δbtail.trackIdx, trackIdxOK)
assertTrack(t, subj + ": trackNew", δbtail.trackNew, trackNewOK)
......@@ -883,72 +885,57 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1
t.Run(fmt.Sprintf(" T%s;R", keys1), func(t *testing.T) {
δbtail := NewΔBtail(t0.at, db)
// FIXME do Update(t0->t1) only once + clone after it
// assert trackIdx=ø, trackNew=ø, vδB=[]
δbtail.assertTrack(t, "@at0", ø, ø) // XXX + vδB
step1 := func() { // XXX will be not needed with clone
xverifyΔBTail_rebuild1(t, db, δbtail, t0, t1, treeRoot, xat,
// after Update(t0->t1):
/*trackIdx=*/ ø,
xverifyΔBTail_rebuild_U(t, δbtail, t0, t1, xat, /*trackIdx=*/ø)
xverifyΔBTail_rebuild_TR(t, db, δbtail, t1, treeRoot, xat,
// after Track(keys1)
keys1,
/*trackIdx=*/ ø,
/*trackNew=*/ t1.xkv.trackIdx(keys1),
// after rebuild
/*trackIdx=*/ t1.xkv.trackIdx(keys1),
/*trackIdx=*/ t1.xkv.trackIdx(keys1),
/*vδB=*/ /*XXX temp*/nil /*[δ1/Tadj(keys1)*/)
}
step1()
t.Run(fmt.Sprintf(" →%s", t2.tree), func(t *testing.T) {
// tracked keys1 becomes tracked keys1_2 after Update(t1->t2)
keys1_2 := kadj12.Map(keys1)
xverifyΔBTail_rebuild_U(t, δbtail, t1, t2, xat, /*trackIdx=*/t2.xkv.trackIdx(keys1_2))
// tRestKeys2 = tAllKeys - keys1
tRestKeys2 := tAllKeys.Difference(keys1)
tRestKeyv2 := tRestKeys2.SortedElements()
for k2idx := range IntSets(len(tRestKeyv2)) {
keys2 := SetKey{}
for _, idx2 := range k2idx {
keys2.Add(tRestKeyv2[idx2])
}
// tRestKeys2 = tAllKeys - keys1
tRestKeys2 := tAllKeys.Difference(keys1)
tRestKeyv2 := tRestKeys2.SortedElements()
for k2idx := range IntSets(len(tRestKeyv2)) {
keys2 := SetKey{}
for _, idx2 := range k2idx {
keys2.Add(tRestKeyv2[idx2])
t.Run(fmt.Sprintf(" T%s;R", keys2), func(t *testing.T) {
δbtail_ := δbtail.clone()
xverifyΔBTail_rebuild_TR(t, db, δbtail_, t2, treeRoot, xat,
// after Track(keys2)
keys2,
// FIXME vvv trackNew should not cover ranges that are already in trackIdx
/*trackIdx*/ t2.xkv.trackIdx(keys1_2),
/*trackNew*/ t2.xkv.trackIdx(keys2),
// after rebuild
/* trackIdx=*/ t2.xkv.trackIdx(keys1_2.Union(keys2)),
/*vδB=*/ /*XXX temp*/nil /*[δ1/keys1+keys2, δ2/keys1+keys2]*/)
})
}
t.Run(fmt.Sprintf(" →%s T%s;R", t2.tree, keys2), func(t *testing.T) {
//δbtail = NewΔBtail(t0.at, db)
//step1()
//δbtail_ := δbtail
δbtail_ := δbtail.clone()
// FIXME do Update(t1->t2) only once + clone after it
// tracked keys1 becomes tracked keys1_2 after Update(t1->t2)
keys1_2 := kadj12.Map(keys1)
xverifyΔBTail_rebuild1(t, db, δbtail_, t1, t2, treeRoot, xat,
// after Update(t1->t2):
/*trackIdx=*/ t2.xkv.trackIdx(keys1_2),
// after Track(keys2)
keys2,
// FIXME vvv trackNew should not cover ranges that are already in trackIdx
/*trackNew*/ t2.xkv.trackIdx(keys2),
// after rebuild
/* trackIdx=*/ t2.xkv.trackIdx(keys1_2.Union(keys2)),
/*vδB=*/ /*XXX temp*/nil /*[δ1/keys1+keys2, δ2/keys1+keys2]*/)
})
}
})
})
}
})
}
// xverifyΔBTail_rebuild1 verifies ΔBTree state:
// 1. after Update(ti->tj),
// 2. after further Track(keys), rebuild
func xverifyΔBTail_rebuild1(t *testing.T, db *zodb.DB, δbtail *ΔBtail, ti, tj *tTreeCommit, treeRoot zodb.Oid, xat map[zodb.Tid]string, trackIdx trackIndex, keys SetKey, trackNew, trackIdxAfterRebuild trackIndex,vδBok []ΔB) {
// xverifyΔBTail_rebuild_U verifies ΔBTree state after Update(ti->tj).
func xverifyΔBTail_rebuild_U(t *testing.T, δbtail *ΔBtail, ti, tj *tTreeCommit, xat map[zodb.Tid]string, trackIdx trackIndex) {
t.Helper()
X := exc.Raiseif
ø := trackIndex{}
......@@ -958,6 +945,13 @@ func xverifyΔBTail_rebuild1(t *testing.T, db *zodb.DB, δbtail *ΔBtail, ti, tj
δbtail.assertTrack(t, fmt.Sprintf("after Update(@%s→@%s)", xat[ti.at], xat[tj.at]), trackIdx, ø)
// XXX vδB=[ø]
_ = δB
}
// xverifyΔBTail_rebuild_TR verifies ΔBTree state after Track(keys) + rebuild.
func xverifyΔBTail_rebuild_TR(t *testing.T, db *zodb.DB, δbtail *ΔBtail, tj *tTreeCommit, treeRoot zodb.Oid, xat map[zodb.Tid]string, keys SetKey, trackIdx trackIndex, trackNew, trackIdxAfterRebuild trackIndex,vδBok []ΔB) {
t.Helper()
X := exc.Raiseif
ø := trackIndex{}
// Track(keys)
txn, ctx := transaction.New(context.Background())
......
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