Skip to content

Commit

Permalink
Add a unittest to test transactions aren't freed by deallocations in …
Browse files Browse the repository at this point in the history
…a fork
  • Loading branch information
Callum Walker committed Jun 24, 2024
1 parent 658b193 commit 7ec283a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions tests/txn_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@

from __future__ import absolute_import
from __future__ import with_statement
import os
import struct
import sys
import unittest
import weakref

import testlib
from testlib import B
from testlib import INT_TYPES
from testlib import BytesType
from testlib import UnicodeType

import lmdb

Expand All @@ -39,6 +42,8 @@
ULONG_0001 = struct.pack('L', 1) # L != size_t
ULONG_0002 = struct.pack('L', 2) # L != size_t

NO_READERS = UnicodeType('(no active readers)\n')


class InitTest(unittest.TestCase):
def tearDown(self):
Expand Down Expand Up @@ -565,5 +570,24 @@ def test_open_close(self):
assert r2() is None


class ForkTest(unittest.TestCase):

def test_dealloc_in_fork(self):
temp_dir = testlib.temp_dir()
env = lmdb.open(temp_dir)
txn = env.begin()

r = env.readers()
assert r != NO_READERS

pid = os.fork()
if pid == 0:
del txn
os._exit(0)

os.waitpid(pid, 0)
assert env.readers() == r, '%r != %r' % (env.readers(), r)


if __name__ == '__main__':
unittest.main()

0 comments on commit 7ec283a

Please sign in to comment.