Commit a2c660a7 authored by Kirill Smelkov's avatar Kirill Smelkov

test/gen_testdata: Prevent object with OID=1 to be deleted

Previously it was like this by luck, but recent changes shuffled
generated output and one of delete selection started to point to OID 1:

    (zdev+py39.env) kirr@deca:~/src/wendelin/z/zodbtools/zodbtools/test/testdata$ grep '^obj .* delete' 1.zdump.zpickledis.ok
    obj 0000000000000001 delete
    obj 0000000000000002 delete

However NEO/go tests depend on object with OID=1 to be present:

https://lab.nexedi.com/kirr/neo/-/blob/1ad088c8/go/neo/neo_test.go#L216-219

and it breaks there if here we let that object with OID=1 to be deleted.

-> Prevent ZODB/go breakage by explicitly making sure that OID=1 stays
present under any conditions.

The actual places where gen_testdata.py from zodbtools is used in
ZODB/go and Wendelin.core are e.g. here:

https://lab.nexedi.com/kirr/neo/-/blob/f7776fc1/go/zodb/storage/fs1/py/gen-testdata
https://lab.nexedi.com/nexedi/wendelin.core/-/blob/07087ec8/wcfs/internal/zdata/testdata/zblk_test_gen.py
parent f38e7941
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
# NOTE as of 14 Mar 2017 FileStorage cannot commit transactions with non-ASCII # NOTE as of 14 Mar 2017 FileStorage cannot commit transactions with non-ASCII
# metadata - so it is not tested # metadata - so it is not tested
# NOTE besides zodbtools this module is also used in ZODB/go and in Wendelin.core .
from ZODB.FileStorage import FileStorage from ZODB.FileStorage import FileStorage
from ZODB import DB from ZODB import DB
from ZODB.Connection import TransactionMetaData from ZODB.Connection import TransactionMetaData
...@@ -216,6 +218,7 @@ def _gen_testdb(outfs_path, zext): ...@@ -216,6 +218,7 @@ def _gen_testdb(outfs_path, zext):
namev = [_ for _ in "abcdefg"] namev = [_ for _ in "abcdefg"]
Niter = 3 Niter = 3
nameobj1 = None # name used when adding first object
for i in range(Niter): for i in range(Niter):
stor = FileStorage(outfs_path, create=(i == 0)) stor = FileStorage(outfs_path, create=(i == 0))
db = DB(stor) db = DB(stor)
...@@ -238,6 +241,10 @@ def _gen_testdb(outfs_path, zext): ...@@ -238,6 +241,10 @@ def _gen_testdb(outfs_path, zext):
commit(u"user%i.%i" % (i,j), u"step %i.%i" % (i, j), ext(name)) commit(u"user%i.%i" % (i,j), u"step %i.%i" % (i, j), ext(name))
if nameobj1 is None:
nameobj1 = name
assert obj._p_oid == p64(1), repr(obj._p_oid)
# undo a transaction one step before a latest one a couple of times # undo a transaction one step before a latest one a couple of times
for j in range(2): for j in range(2):
# XXX undoLog, despite what its interface says: # XXX undoLog, despite what its interface says:
...@@ -267,7 +274,8 @@ def _gen_testdb(outfs_path, zext): ...@@ -267,7 +274,8 @@ def _gen_testdb(outfs_path, zext):
commit(u"user", u"cyclic reference", ext("cycle")) commit(u"user", u"cyclic reference", ext("cycle"))
# delete an object # delete an object
name = rand.choice(keys(root)) _ = keys(root); _.remove(nameobj1) # preserve the first obj not to go
name = rand.choice(_)
obj = root[name] obj = root[name]
root[name] = Object("%s%i*" % (name, i)) root[name] = Object("%s%i*" % (name, i))
# NOTE user/ext are kept empty on purpose - to also test this case # NOTE user/ext are kept empty on purpose - to also test this case
......
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