Commit 97ecc0ab authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 35ce1704
...@@ -70,6 +70,8 @@ const ø = "ø" ...@@ -70,6 +70,8 @@ const ø = "ø"
// it is based on xbtreetest.T . // it is based on xbtreetest.T .
type T struct { type T struct {
*xbtreetest.T *xbtreetest.T
foid zodb.Oid // oid of zfile
} }
...@@ -434,28 +436,8 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) { ...@@ -434,28 +436,8 @@ func testΔFtail(t_ *testing.T, testq chan ΔFTestEntry) {
// update δFtail // update δFtail
δF, err := δFtail.Update(commit.ΔZ); X(err) δF, err := δFtail.Update(commit.ΔZ); X(err)
// assert δF points to the file if δfok != ø // assert δF matches δfok
if δF.Rev != commit.At { t.assertΔF(δF, commit.At, δfok)
t.Errorf("wrong δF.Rev: have %s ; want %s", δF.Rev, commit.At)
}
δfiles := setOid{}
for δfile := range δF.ByFile {
δfiles.Add(δfile)
}
δfilesOK := setOid{}
if δfok != nil {
δfilesOK.Add(foid)
}
if !δfiles.Equal(δfilesOK) {
t.Errorf("wrong δF.ByFile:\nhave keys: %s\nwant keys: %s", δfiles, δfilesOK)
continue
}
// verify δf
δf := δF.ByFile[foid]
if !reflect.DeepEqual(δf, δfok) {
t.Errorf("δf:\nhave: %v\nwant: %v", δf, δfok)
}
// track whole zfile again if new epoch was started // track whole zfile again if new epoch was started
if newEpoch { if newEpoch {
...@@ -598,22 +580,19 @@ func TestΔFtailSliceUntrackedUniform(t_ *testing.T) { ...@@ -598,22 +580,19 @@ func TestΔFtailSliceUntrackedUniform(t_ *testing.T) {
// commit t1. all 0, 1 and 2 are in the same bucket. // commit t1. all 0, 1 and 2 are in the same bucket.
t1 := t.CommitTree("T/B0:a,1:b,2:c") t1 := t.CommitTree("T/B0:a,1:b,2:c")
δF, err := δFtail.Update(t1.ΔZ); X(err) δF, err := δFtail.Update(t1.ΔZ); X(err)
// XXX assert δF == ø t.assertΔF(δF, t1.At, nil) // δf empty
_ = δF
t2 := t.CommitTree("t0:d,1:e,2:c Da:a,b:b,c:c2,d:d,e:e") // 0:-a+d 1:-b+e δc₂ t2 := t.CommitTree("t0:d,1:e,2:c Da:a,b:b,c:c2,d:d,e:e") // 0:-a+d 1:-b+e δc₂
δF, err = δFtail.Update(t2.ΔZ); X(err) δF, err = δFtail.Update(t2.ΔZ); X(err)
// XXX assert δF t.assertΔF(δF, t2.At, nil)
t3 := t.CommitTree("t0:d,1:e,2:c Da:a,b:b,c:c3,d:d3,e:e3") // δc₃ δd₃ δe₃ t3 := t.CommitTree("t0:d,1:e,2:c Da:a,b:b,c:c3,d:d3,e:e3") // δc₃ δd₃ δe₃
δF, err = δFtail.Update(t3.ΔZ); X(err) δF, err = δFtail.Update(t3.ΔZ); X(err)
// XXX assert δF t.assertΔF(δF, t3.At, nil)
t4 := t.CommitTree("t0:d,1:e,2:c Da:a,b:b,c:c4,d:d3,e:e4") // δc₄ δe₄ t4 := t.CommitTree("t0:d,1:e,2:c Da:a,b:b,c:c4,d:d3,e:e4") // δc₄ δe₄
δF, err = δFtail.Update(t4.ΔZ); X(err) δF, err = δFtail.Update(t4.ΔZ); X(err)
// XXX assert δF t.assertΔF(δF, t4.At, nil)
// load zfile via root['treegen/file'] // load zfile via root['treegen/file']
txn, ctx := transaction.New(context.Background()) txn, ctx := transaction.New(context.Background())
...@@ -693,11 +672,27 @@ func dataTabTxt(dataTab map[string]string) string { ...@@ -693,11 +672,27 @@ func dataTabTxt(dataTab map[string]string) string {
// newT creates new T. // newT creates new T.
func newT(t *testing.T) *T { func newT(t *testing.T) *T {
return &T{xbtreetest.NewT(t)} t.Helper()
tt := &T{xbtreetest.NewT(t), zodb.InvalidOid}
// find out zfile's oid
txn, ctx := transaction.New(context.Background())
defer func() {
txn.Abort()
}()
zconn, err := tt.DB.Open(ctx, &zodb.ConnOptions{At: tt.Head().At})
if err != nil {
tt.Fatal(err)
}
zfile, _ := tt.XLoadZFile(ctx, zconn)
tt.foid = zfile.POid()
return tt
} }
// XLoadZFile loads zfile from root["treegen/file"]@head. // XLoadZFile loads zfile from root["treegen/file"]@head.
func (t *T) XLoadZFile(ctx context.Context, zconn *zodb.Connection) (zfile *ZBigFile, blksize int64) { func (t *T) XLoadZFile(ctx context.Context, zconn *zodb.Connection) (zfile *ZBigFile, blksize int64) {
t.Helper()
X := exc.Raiseif X := exc.Raiseif
xzroot, err := zconn.Get(ctx, 0); X(err) xzroot, err := zconn.Get(ctx, 0); X(err)
zroot := xzroot.(*zodb.Map) zroot := xzroot.(*zodb.Map)
...@@ -714,6 +709,34 @@ func (t *T) XLoadZFile(ctx context.Context, zconn *zodb.Connection) (zfile *ZBig ...@@ -714,6 +709,34 @@ func (t *T) XLoadZFile(ctx context.Context, zconn *zodb.Connection) (zfile *ZBig
return zfile, blksize return zfile, blksize
} }
// assertΔF asserts that δF has rev and δf as expected.
func (t *T) assertΔF(δF ΔF, rev zodb.Tid, δfok *ΔFile) {
t.Helper()
// assert δF points to zfile if δfok != ø
if δF.Rev != rev {
t.Errorf("wrong δF.Rev: have %s ; want %s", δF.Rev, rev)
}
δfiles := setOid{}
for δfile := range δF.ByFile {
δfiles.Add(δfile)
}
δfilesOK := setOid{}
if δfok != nil {
δfilesOK.Add(t.foid)
}
if !δfiles.Equal(δfilesOK) {
t.Errorf("wrong δF.ByFile:\nhave keys: %s\nwant keys: %s", δfiles, δfilesOK)
return
}
// verify δf
δf := δF.ByFile[t.foid]
if !reflect.DeepEqual(δf, δfok) {
t.Errorf("δf:\nhave: %v\nwant: %v", δf, δfok)
}
}
// δfstr/vδfstr convert δf/vδf to string taking symbolic at into account. // δfstr/vδfstr convert δf/vδf to string taking symbolic at into account.
func (t *T) δfstr(δf *ΔFile) string { func (t *T) δfstr(δf *ΔFile) string {
s := fmt.Sprintf("@%s·%s", t.AtSymb(δf.Rev), δf.Blocks) s := fmt.Sprintf("@%s·%s", t.AtSymb(δf.Rev), δf.Blocks)
......
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