Skip to content

Commit a35fdb7

Browse files
committed
Updated test(s).
1 parent c50e9e9 commit a35fdb7

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
ROOT_DIR = os.path.abspath(os.curdir)
1111
TMP_FILE_DIR = os.path.join(ROOT_DIR, "tmp")
12+
WORKER_PORT_MAP_FILE_PATH = os.path.join(TMP_FILE_DIR, './worker_process_data.txt')
13+
1214

1315
# Should we actually ocr or just extract text from PDFs ? NOTE: OCR IS STILL APPLIED TO IMAGES if detected | possible vals : "OCR", "NO_OCR"
1416
OPERATION_MODE = os.environ.get("OCR_SERVICE_OPERATION_MODE", "OCR")

ocr_service/tests/process.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import unittest
55

66
from ocr_service.app.app import create_app
7+
from ocr_service.utils.utils import sync_port_mapping
78

89
from ..tests.test_utils import *
910

@@ -97,6 +98,8 @@ def _setup_logging(cls):
9798

9899
@staticmethod
99100
def _setup_app(cls):
101+
sync_port_mapping(worker_id=0, worker_pid=os.getpid())
102+
100103
cls.app = create_app()
101104
cls.client = cls.app.test_client()
102105

ocr_service/utils/utils.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ def get_process_id_by_process_name(process_name: str = "") -> int:
101101
def sync_port_mapping(worker_id = None, worker_pid = None):
102102

103103

104-
f_path = os.path.join(TMP_FILE_DIR, './worker_process_data.txt')
105104
open_mode = "r+"
106-
if not os.path.exists(f_path):
105+
106+
if not os.path.exists(WORKER_PORT_MAP_FILE_PATH):
107107
open_mode = "w+"
108108

109-
with open(f_path, encoding="utf-8", mode=open_mode) as f:
109+
with open(WORKER_PORT_MAP_FILE_PATH, encoding="utf-8", mode=open_mode) as f:
110110
fcntl.lockf(f, fcntl.LOCK_EX)
111111

112112
port_mapping = {}
@@ -124,7 +124,13 @@ def sync_port_mapping(worker_id = None, worker_pid = None):
124124

125125
def get_assigned_port(current_worker_pid):
126126
port_mapping = {}
127-
with open(os.path.join(TMP_FILE_DIR, './worker_process_data.txt'), encoding="utf-8", mode='r+') as f:
127+
128+
open_mode = "r+"
129+
130+
if not os.path.exists(WORKER_PORT_MAP_FILE_PATH):
131+
open_mode = "w+"
132+
133+
with open(WORKER_PORT_MAP_FILE_PATH, encoding="utf-8", mode=open_mode) as f:
128134
fcntl.lockf(f, fcntl.LOCK_EX)
129135
port_mapping = json.loads(f.read())
130136
fcntl.lockf(f, fcntl.LOCK_UN)

0 commit comments

Comments
 (0)