Move all sockets into subdir
This commit is contained in:
parent
81bbcf8761
commit
4bd7ce6f15
4 changed files with 20 additions and 5 deletions
|
@ -1,7 +1,12 @@
|
||||||
|
import os
|
||||||
import select
|
import select
|
||||||
|
import shutil
|
||||||
|
import tempfile
|
||||||
|
|
||||||
import ujson
|
import ujson
|
||||||
|
|
||||||
|
BASE_SOCKET_DIR = os.path.join(tempfile.gettempdir(), "catfish")
|
||||||
|
|
||||||
BUFFER_SIZE = 4096
|
BUFFER_SIZE = 4096
|
||||||
DEFAULT_SOCKET_READ_TIMEOUT = 0.01
|
DEFAULT_SOCKET_READ_TIMEOUT = 0.01
|
||||||
NEW_LINE = b"\n"
|
NEW_LINE = b"\n"
|
||||||
|
@ -22,3 +27,11 @@ def read_all_from_socket(socket):
|
||||||
break
|
break
|
||||||
data += message
|
data += message
|
||||||
return ujson.loads(data)
|
return ujson.loads(data)
|
||||||
|
|
||||||
|
|
||||||
|
def create_base_socket_dir():
|
||||||
|
os.mkdir(BASE_SOCKET_DIR)
|
||||||
|
|
||||||
|
|
||||||
|
def delete_base_socket_dir():
|
||||||
|
shutil.rmtree(BASE_SOCKET_DIR)
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
import os
|
import os
|
||||||
import tempfile
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
from catfish.router import start_router
|
from catfish.router import start_router
|
||||||
from catfish.utils.processes import terminate_processes
|
from catfish.utils.processes import terminate_processes
|
||||||
|
from catfish.utils.sockets import BASE_SOCKET_DIR
|
||||||
|
|
||||||
from .server import WORKER_SERVER_SOCKET, start_server
|
from .server import WORKER_SERVER_SOCKET, start_server
|
||||||
|
|
||||||
PID_FILE = os.path.join(tempfile.gettempdir(), "catfish.pid")
|
PID_FILE = os.path.join(BASE_SOCKET_DIR, "catfish.pid")
|
||||||
|
|
||||||
|
|
||||||
def is_running():
|
def is_running():
|
||||||
|
|
|
@ -3,15 +3,14 @@ import os
|
||||||
import shlex
|
import shlex
|
||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
import ujson
|
import ujson
|
||||||
from catfish.utils.sockets import NEW_LINE, read_all_from_socket
|
from catfish.utils.sockets import BASE_SOCKET_DIR, NEW_LINE, read_all_from_socket
|
||||||
|
|
||||||
WORKER_SERVER_SOCKET = os.path.join(tempfile.gettempdir(), "catfish.sock")
|
WORKER_SERVER_SOCKET = os.path.join(BASE_SOCKET_DIR, "catfish.sock")
|
||||||
|
|
||||||
|
|
||||||
def send_to_server(payload):
|
def send_to_server(payload):
|
||||||
|
|
|
@ -8,10 +8,12 @@ from click.testing import CliRunner
|
||||||
from catfish import worker
|
from catfish import worker
|
||||||
from catfish.__main__ import cli
|
from catfish.__main__ import cli
|
||||||
from catfish.utils.processes import CURRENT_PROCESS, terminate_processes
|
from catfish.utils.processes import CURRENT_PROCESS, terminate_processes
|
||||||
|
from catfish.utils.sockets import create_base_socket_dir, delete_base_socket_dir
|
||||||
|
|
||||||
|
|
||||||
class BaseTestCase(AsyncTestCase):
|
class BaseTestCase(AsyncTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
create_base_socket_dir()
|
||||||
worker.stop_worker()
|
worker.stop_worker()
|
||||||
self.cli_runner = CliRunner()
|
self.cli_runner = CliRunner()
|
||||||
self.cli = cli
|
self.cli = cli
|
||||||
|
@ -20,6 +22,7 @@ class BaseTestCase(AsyncTestCase):
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
worker.stop_worker()
|
worker.stop_worker()
|
||||||
terminate_processes(CURRENT_PROCESS.children(recursive=True))
|
terminate_processes(CURRENT_PROCESS.children(recursive=True))
|
||||||
|
delete_base_socket_dir()
|
||||||
|
|
||||||
|
|
||||||
class BaseWorkerTestCase(BaseTestCase):
|
class BaseWorkerTestCase(BaseTestCase):
|
||||||
|
|
Reference in a new issue