Skip to content

Commit

Permalink
move directory recreation to the test. remove self.lockfile
Browse files Browse the repository at this point in the history
  • Loading branch information
ajslater committed Feb 5, 2022
1 parent 8760482 commit 50258e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 5 additions & 0 deletions tests/xapian_tests/tests/test_management_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import random
from decimal import Decimal
from io import StringIO
from pathlib import Path
from unittest import TestCase

from django.core.management import call_command
Expand Down Expand Up @@ -45,6 +46,10 @@ def setUp(self):
self.sample_objs.append(entry)
entry.save()

try:
Path(self.backend.path).mkdir(parents=True)
except FileExistsError:
pass
self.backend.update(self.index, BlogEntry.objects.all())

def verify_indexed_document_count(self, expected):
Expand Down
7 changes: 5 additions & 2 deletions xapian_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,12 @@ def filelocked(func):

def wrapper(self, *args, **kwargs):
"""Run the function inside a lock."""
with self.filelock:
if self.path == MEMORY_DB_NAME:
func(self, *args, **kwargs)
else:
Path(self.filelock.lock_file).touch()
with self.filelock:
func(self, *args, **kwargs)

return wrapper

Expand Down Expand Up @@ -197,7 +201,6 @@ def __init__(self, connection_alias, **connection_options):
pass

lockfile = Path(self.path) / "lockfile"
lockfile.touch()
self.filelock = FileLock(lockfile)

self.flags = connection_options.get('FLAGS', DEFAULT_XAPIAN_FLAGS)
Expand Down

0 comments on commit 50258e6

Please sign in to comment.