Commit 463ef9ad authored by Kirill Smelkov's avatar Kirill Smelkov

go/internal/xtesting: DrvTestWatch: Verify that watching works with empty transactions

It was not the case with ZEO4 server because we did not had
ZEO@bf80d23d yet.
parent b516190c
...@@ -383,12 +383,23 @@ func DrvTestWatch(t *testing.T, zurl string, zdrvOpen zodb.DriverOpener) { ...@@ -383,12 +383,23 @@ func DrvTestWatch(t *testing.T, zurl string, zdrvOpen zodb.DriverOpener) {
// run py `zodb commit`. // run py `zodb commit`.
// //
// if one day it is either fixed, or worked around, we could ↑ 10 to 100. // if one day it is either fixed, or worked around, we could ↑ 10 to 100.
data0 := ""
lastDataAt := zodb.Tid(0)
for i := zodb.Oid(1); i <= 10; i++ { for i := zodb.Oid(1); i <= 10; i++ {
data0 := fmt.Sprintf("data0.%d", i) empty := (5 <= i && i <= 7) // this transactions are committed as empty
datai := fmt.Sprintf("data%d", i)
at = xcommit(at, objv := []ZRawObject{}
ZRawObject{0, b(data0)}, datai := ""
ZRawObject{i, b(datai)}) if !empty {
data0 = fmt.Sprintf("data0.%d", i)
datai = fmt.Sprintf("data%d", i)
objv = append(objv, ZRawObject{0, b(data0)})
objv = append(objv, ZRawObject{i, b(datai)})
}
at = xcommit(at, objv...)
if !empty {
lastDataAt = at
}
// TODO also test for watcher errors // TODO also test for watcher errors
event := <-watchq event := <-watchq
...@@ -405,16 +416,22 @@ func DrvTestWatch(t *testing.T, zurl string, zdrvOpen zodb.DriverOpener) { ...@@ -405,16 +416,22 @@ func DrvTestWatch(t *testing.T, zurl string, zdrvOpen zodb.DriverOpener) {
δ = event δ = event
} }
if objvWant := []zodb.Oid{0, i}; !(δ.Tid == at && reflect.DeepEqual(δ.Changev, objvWant)) { objvWant := []zodb.Oid{}
if !empty {
objvWant = []zodb.Oid{0, i}
}
if !(δ.Tid == at && reflect.DeepEqual(δ.Changev, objvWant)) {
t.Fatalf("watch:\nhave: %s %s\nwant: %s %s", δ.Tid, δ.Changev, at, objvWant) t.Fatalf("watch:\nhave: %s %s\nwant: %s %s", δ.Tid, δ.Changev, at, objvWant)
} }
checkHead(at) checkHead(at)
// make sure we can load what was committed. // make sure we can load what was committed.
checkLoad(at, 0, data0, at) checkLoad(at, 0, data0, lastDataAt)
if !empty {
checkLoad(at, i, datai, at) checkLoad(at, i, datai, at)
} }
}
err = zdrv.Close(); X(err) err = zdrv.Close(); X(err)
......
...@@ -647,7 +647,7 @@ mainloop: ...@@ -647,7 +647,7 @@ mainloop:
// our index & notify client watchers. There is no expected errors here. // our index & notify client watchers. There is no expected errors here.
// //
// (keep in sync with Index.Update) // (keep in sync with Index.Update)
var δoid []zodb.Oid δoid := []zodb.Oid{}
δidx := map[zodb.Oid]int64{} // oid -> pos(data record) δidx := map[zodb.Oid]int64{} // oid -> pos(data record)
for { for {
err = it.NextData() err = it.NextData()
......
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