single authsrv instance per process

This commit is contained in:
ed 2021-06-11 23:01:13 +02:00
parent fbe656957d
commit 60ac68d000
15 changed files with 156 additions and 109 deletions

View file

@ -11,6 +11,7 @@ import subprocess as sp
class Cpp(object):
def __init__(self, args):
self.ls_pre = set(list(os.listdir()))
self.p = sp.Popen([sys.executable, "-m", "copyparty"] + args)
# , stdout=sp.PIPE, stderr=sp.PIPE)
@ -27,27 +28,29 @@ class Cpp(object):
if wait:
self.t.join()
def main():
t1 = set(list(os.listdir()))
try:
main2()
finally:
t2 = os.listdir()
for f in t2:
if f not in t1 and f.startswith("up."):
def clean(self):
t = os.listdir()
for f in t:
if f not in self.ls_pre and f.startswith("up."):
os.unlink(f)
def main2():
def tc1():
ub = "http://127.0.0.1:4321/"
td = os.path.join("srv", "smoketest")
try:
shutil.rmtree(td)
except:
pass
if os.path.exists(td):
raise
os.mkdir(td)
for _ in range(10):
try:
os.mkdir(td)
except:
time.sleep(0.1) # win10
assert os.path.exists(td)
vidp = os.path.join(tempfile.gettempdir(), "smoketest.h264")
if not os.path.exists(vidp):
@ -57,8 +60,17 @@ def main2():
with open(vidp, "rb") as f:
ovid = f.read()
args = ["-p", "4321", "-e2dsa", "-e2tsr", "--th-ff-jpg"]
args = [
"-p",
"4321",
"-e2dsa",
"-e2tsr",
"--th-ff-jpg",
"--hist",
os.path.join(td, "dbm"),
]
pdirs = []
hpaths = {}
for d1 in ["r", "w", "a"]:
pdirs.append("{}/{}".format(td, d1))
@ -72,8 +84,19 @@ def main2():
udirs = [x.split("/", 2)[2] for x in pdirs]
perms = [x.rstrip("j/")[-1] for x in pdirs]
for pd, ud, p in zip(pdirs, udirs, perms):
# args += ["-v", "{}:{}:{}".format(d.split("/", 1)[1], d, d[-1])]
args += ["-v", "{}:{}:{}".format(pd, ud, p)]
if ud[-1] == "j":
continue
hp = None
if pd.endswith("st/a"):
hp = os.path.join(td, "db1")
elif pd[:-1].endswith("a/j/"):
hp = os.path.join(td, "dbm")
else:
hp = "-"
hpaths[ud] = os.path.join(pd, ".hist") if hp == "-" else hp
args += ["-v", "{}:{}:{}:chist={}".format(pd, ud, p, hp)]
# print(repr(args))
# return
@ -98,6 +121,9 @@ def main2():
except:
pass
cpp.clean()
# GET permission
for d, p in zip(udirs, perms):
u = "{}{}/a.h264".format(ub, d)
r = requests.get(u)
@ -105,12 +131,14 @@ def main2():
if ok != (p in ["a"]):
raise Exception("get {} with perm {} at {}".format(ok, p, u))
# stat filesystem
for d, p in zip(pdirs, perms):
u = "{}/a.h264".format(d)
ok = os.path.exists(u)
if ok != (p in ["a", "w"]):
raise Exception("stat {} with perm {} at {}".format(ok, p, u))
# GET thumbnail, vreify contents
for d, p in zip(udirs, perms):
u = "{}{}/a.h264?th=j".format(ub, d)
r = requests.get(u)
@ -118,8 +146,34 @@ def main2():
if ok != (p in ["a"]):
raise Exception("thumb {} with perm {} at {}".format(ok, p, u))
# check tags
for d, p in zip(udirs, perms):
u = "{}{}?ls".format(ub, d)
r = requests.get(u)
j = r.json() if r else False
tag = None
if j:
for f in j["files"]:
tag = tag or f["tags"].get("res")
r_ok = bool(j)
w_ok = bool(r_ok and j.get("files"))
if not r_ok or w_ok != (p in ["a"]):
raise Exception("ls {} with perm {} at {}".format(ok, p, u))
if (tag and p != "a") or (not tag and p == "a"):
raise Exception("tag {} with perm {} at {}".format(ok, p, u))
if tag is not None and tag != "48x32":
raise Exception("tag [{}] at {}".format(tag, u))
cpp.stop(True)
def main():
tc1()
if __name__ == "__main__":
main()