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 ...@@ -825,6 +825,7 @@ func xverifyΔBTail_Update1(t *testing.T, subj string, db *zodb.DB, treeRoot zod
// assertTrack verifies that trackIdx == trackIdxOK. // assertTrack verifies that trackIdx == trackIdxOK.
// XXX place // XXX place
func assertTrack(t *testing.T, subj string, trackIdx, trackIdxOK trackIndex) { func assertTrack(t *testing.T, subj string, trackIdx, trackIdxOK trackIndex) {
t.Helper()
if !reflect.DeepEqual(trackIdx, trackIdxOK) { if !reflect.DeepEqual(trackIdx, trackIdxOK) {
t.Errorf("%s:\n\thave: %v\n\twant: %v", subj, 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) { ...@@ -833,6 +834,7 @@ func assertTrack(t *testing.T, subj string, trackIdx, trackIdxOK trackIndex) {
// assertTrack verifies state of .trackIdx and .trackNew. // assertTrack verifies state of .trackIdx and .trackNew.
// XXX place // XXX place
func (δbtail *ΔBtail) assertTrack(t *testing.T, subj string, trackIdxOK, trackNewOK trackIndex) { func (δbtail *ΔBtail) assertTrack(t *testing.T, subj string, trackIdxOK, trackNewOK trackIndex) {
t.Helper()
assertTrack(t, subj + ": trackIdx", δbtail.trackIdx, trackIdxOK) assertTrack(t, subj + ": trackIdx", δbtail.trackIdx, trackIdxOK)
assertTrack(t, subj + ": trackNew", δbtail.trackNew, trackNewOK) assertTrack(t, subj + ": trackNew", δbtail.trackNew, trackNewOK)
...@@ -883,25 +885,24 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1 ...@@ -883,25 +885,24 @@ 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) { t.Run(fmt.Sprintf(" T%s;R", keys1), func(t *testing.T) {
δbtail := NewΔBtail(t0.at, db) δbtail := NewΔBtail(t0.at, db)
// FIXME do Update(t0->t1) only once + clone after it
// assert trackIdx=ø, trackNew=ø, vδB=[] // assert trackIdx=ø, trackNew=ø, vδB=[]
δbtail.assertTrack(t, "@at0", ø, ø) // XXX + 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) // after Track(keys1)
keys1, keys1,
/*trackIdx=*/ ø,
/*trackNew=*/ t1.xkv.trackIdx(keys1), /*trackNew=*/ t1.xkv.trackIdx(keys1),
// after rebuild // after rebuild
/*trackIdx=*/ t1.xkv.trackIdx(keys1), /*trackIdx=*/ t1.xkv.trackIdx(keys1),
/*vδB=*/ /*XXX temp*/nil /*[δ1/Tadj(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 - keys1
tRestKeys2 := tAllKeys.Difference(keys1) tRestKeys2 := tAllKeys.Difference(keys1)
...@@ -912,27 +913,13 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1 ...@@ -912,27 +913,13 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1
keys2.Add(tRestKeyv2[idx2]) keys2.Add(tRestKeyv2[idx2])
} }
t.Run(fmt.Sprintf(" →%s T%s;R", t2.tree, keys2), func(t *testing.T) { t.Run(fmt.Sprintf(" T%s;R", keys2), func(t *testing.T) {
//δbtail = NewΔBtail(t0.at, db)
//step1()
//δbtail_ := δbtail
δbtail_ := δbtail.clone() δbtail_ := δbtail.clone()
xverifyΔBTail_rebuild_TR(t, db, δbtail_, t2, treeRoot, xat,
// 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) // after Track(keys2)
keys2, keys2,
// FIXME vvv trackNew should not cover ranges that are already in trackIdx // FIXME vvv trackNew should not cover ranges that are already in trackIdx
/*trackIdx*/ t2.xkv.trackIdx(keys1_2),
/*trackNew*/ t2.xkv.trackIdx(keys2), /*trackNew*/ t2.xkv.trackIdx(keys2),
// after rebuild // after rebuild
...@@ -941,14 +928,14 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1 ...@@ -941,14 +928,14 @@ func xverifyΔBTail_rebuild(t *testing.T, db *zodb.DB, treeRoot zodb.Oid, t0, t1
}) })
} }
}) })
})
} }
}) })
} }
// xverifyΔBTail_rebuild1 verifies ΔBTree state: // xverifyΔBTail_rebuild_U verifies ΔBTree state after Update(ti->tj).
// 1. after Update(ti->tj), func xverifyΔBTail_rebuild_U(t *testing.T, δbtail *ΔBtail, ti, tj *tTreeCommit, xat map[zodb.Tid]string, trackIdx trackIndex) {
// 2. after further Track(keys), rebuild t.Helper()
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) {
X := exc.Raiseif X := exc.Raiseif
ø := trackIndex{} ø := trackIndex{}
...@@ -958,6 +945,13 @@ func xverifyΔBTail_rebuild1(t *testing.T, db *zodb.DB, δbtail *ΔBtail, ti, tj ...@@ -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, ø) δbtail.assertTrack(t, fmt.Sprintf("after Update(@%s→@%s)", xat[ti.at], xat[tj.at]), trackIdx, ø)
// XXX vδB=[ø] // XXX vδB=[ø]
_ = δ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) // Track(keys)
txn, ctx := transaction.New(context.Background()) 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