aboutsummaryrefslogtreecommitdiffstats
path: root/library/python/filelock/ut/lib
diff options
context:
space:
mode:
authormonster <monster@ydb.tech>2022-07-07 14:41:37 +0300
committermonster <monster@ydb.tech>2022-07-07 14:41:37 +0300
commit06e5c21a835c0e923506c4ff27929f34e00761c2 (patch)
tree75efcbc6854ef9bd476eb8bf00cc5c900da436a2 /library/python/filelock/ut/lib
parent03f024c4412e3aa613bb543cf1660176320ba8f4 (diff)
downloadydb-06e5c21a835c0e923506c4ff27929f34e00761c2.tar.gz
fix ya.make
Diffstat (limited to 'library/python/filelock/ut/lib')
-rw-r--r--library/python/filelock/ut/lib/test_filelock.py83
1 files changed, 0 insertions, 83 deletions
diff --git a/library/python/filelock/ut/lib/test_filelock.py b/library/python/filelock/ut/lib/test_filelock.py
deleted file mode 100644
index 1b11d891231..00000000000
--- a/library/python/filelock/ut/lib/test_filelock.py
+++ /dev/null
@@ -1,83 +0,0 @@
-import os
-import time
-import logging
-import multiprocessing
-import tempfile
-import threading
-
-import library.python.filelock
-
-
-def _acquire_lock(lock_path, out_file_path):
- with library.python.filelock.FileLock(lock_path):
- with open(out_file_path, "a") as out:
- out.write("{}:{}\n".format(os.getpid(), time.time()))
- time.sleep(2)
-
-
-def test_filelock():
- temp_dir = tempfile.mkdtemp()
- lock_path = os.path.join(temp_dir, "file.lock")
- out_file_path = os.path.join(temp_dir, "out.txt")
-
- process_count = 5
- processes = []
- for i in range(process_count):
- process = multiprocessing.Process(target=_acquire_lock, args=(lock_path, out_file_path))
- process.start()
- processes.append(process)
-
- for process in processes:
- process.join()
-
- pids = []
- times = []
- with open(out_file_path) as out:
- content = out.read()
- logging.info("Times:\n%s", content)
- for line in content.strip().split("\n"):
- pid, time_val = line.split(":")
- pids.append(pid)
- times.append(float(time_val))
-
- assert len(set(pids)) == process_count
- time1 = times.pop()
- while times:
- time2 = times.pop()
- assert int(time1) - int(time2) >= 2
- time1 = time2
-
-
-def test_filelock_init_acquired():
- temp_dir = tempfile.mkdtemp()
- lock_path = os.path.join(temp_dir, "file.lock")
-
- with library.python.filelock.FileLock(lock_path):
- sublock = library.python.filelock.FileLock(lock_path)
- del sublock
-
-
-def test_concurrent_lock():
- filename = 'con.lock'
-
- def lock():
- l = library.python.filelock.FileLock(filename)
- time.sleep(1)
- l.acquire()
- l.release()
- try:
- os.unlink(filename)
- except OSError:
- pass
-
- threads = []
- for i in range(100):
- t = threading.Thread(target=lock)
- t.daemon = True
- threads.append(t)
-
- for t in threads:
- t.start()
-
- for t in threads:
- t.join()