Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a5e8ab5

Browse files
committed
merge r58023 to fix issue1112 on windows. make this test more robust
and deterministic.
1 parent 1cc5544 commit a5e8ab5

1 file changed

Lines changed: 22 additions & 10 deletions

File tree

Lib/bsddb/test/test_1413192.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
2-
# http://python.org/sf/1413192
1+
# http://bugs.python.org/issue1413192
32
#
4-
# This test relies on the variable names, see the bug report for details.
3+
# See the bug report for details.
54
# The problem was that the env was deallocated prior to the txn.
65

76
import shutil
@@ -15,15 +14,28 @@
1514

1615
env_name = tempfile.mkdtemp()
1716

18-
env = db.DBEnv()
19-
env.open(env_name, db.DB_CREATE | db.DB_INIT_TXN | db.DB_INIT_MPOOL)
20-
the_txn = env.txn_begin()
17+
# Wrap test operation in a class so we can control destruction rather than
18+
# waiting for the controlling Python executable to exit
19+
20+
class Context:
21+
22+
def __init__(self):
23+
self.env = db.DBEnv()
24+
self.env.open(env_name,
25+
db.DB_CREATE | db.DB_INIT_TXN | db.DB_INIT_MPOOL)
26+
self.the_txn = self.env.txn_begin()
27+
28+
self.map = db.DB(self.env)
29+
self.map.open('xxx.db', "p",
30+
db.DB_HASH, db.DB_CREATE, 0o666, txn=self.the_txn)
31+
del self.env
32+
del self.the_txn
33+
2134

22-
map = db.DB(env)
23-
map.open('xxx.db',
24-
"p", db.DB_HASH, db.DB_CREATE, 0o666, txn=the_txn)
35+
context = Context()
36+
del context
2537

26-
# try not to leave a turd (won't help Windows since files are still open)
38+
# try not to leave a turd
2739
try:
2840
shutil.rmtree(env_name)
2941
except EnvironmentError:

0 commit comments

Comments
 (0)