From e839c5f1c93e1fe024a2656d319721a7b23c6461 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Sat, 29 May 2021 11:39:31 +0300 Subject: refactor: count chunks via file system, not via chunk server API --- subplot/server.py | 18 +++++++++++++----- subplot/server.yaml | 4 ++-- 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'subplot') diff --git a/subplot/server.py b/subplot/server.py index df594f7..cfe91ab 100644 --- a/subplot/server.py +++ b/subplot/server.py @@ -134,13 +134,21 @@ def json_body_matches(ctx, wanted=None): assert_eq(body.get(key, "not.there"), wanted[key]) -def server_has_n_file_chunks(ctx, n=None): +def server_has_n_chunks(ctx, n=None): assert_eq = globals()["assert_eq"] n = int(n) - url = f"{ctx['server_url']}/chunks?data=true" - _request(ctx, requests.get, url) - num_chunks = len(ctx["http.json"]) - assert_eq(n, num_chunks) + files = find_files(ctx["config"]["chunks"]) + files = [json.load(open(x)) for x in files if x.endswith(".meta")] + logging.debug(f"server_has_n_file_chunks: n={n}") + logging.debug(f"server_has_n_file_chunks: len(files)={len(files)}") + logging.debug(f"server_has_n_file_chunks: files={files}") + assert_eq(n, len(files)) + + +def find_files(root): + for dirname, _, names in os.walk(root): + for name in names: + yield os.path.join(dirname, name) # Make an HTTP request. diff --git a/subplot/server.yaml b/subplot/server.yaml index 60f8a44..5b8a242 100644 --- a/subplot/server.yaml +++ b/subplot/server.yaml @@ -44,5 +44,5 @@ - then: "the body matches file {filename}" function: body_matches_file -- then: "server has {n:int} file chunks" - function: server_has_n_file_chunks +- then: "server has {n:int} chunks" + function: server_has_n_chunks -- cgit v1.2.1