23from b2test_utils
import is_ci
25from validationtestutil
import check_execute
31def http_post(command, json_args, retries=10, delay=1.0):
32 call_url = validation_url + command
33 print(f
"Posting {json_args} to {command}")
34 for i
in range(retries):
36 r = requests.post(call_url, json=json_args, timeout=5)
39 except requests.exceptions.ConnectionError:
40 print(f
"Server not reachable yet (attempt {i+1}/{retries})")
42 print(f
"Failed to reach server at {call_url}")
46def wait_for_port_any(port: int, timeout: float = 30.0):
47 """Wait until something listens on either 127.0.0.1 or ::1."""
49 while time.time() - start < timeout:
50 for host
in (
"127.0.0.1",
"::1"):
52 with socket.create_connection((host, port), timeout=1):
60def check_for_plotting(revs, tmp_folder):
62 Checks if creating new plots for a revision combination works
63 :param revs: List of revisions
65 :param tmp_folder: Temporary folder
68 print(f
"Trying to recreate plots for revisions {revs}")
70 res = http_post(
"create_comparison", {
"revision_list": revs})
75 prog_key = res.json()[
"progress_key"]
85 res = http_post(
"check_comparison_status", {
"input": prog_key})
90 if res.json()[
"status"] ==
"complete":
95 if time.time() - start > max_wait_time:
97 f
"Waited for {max_wait_time} seconds for the requested plots to complete and nothing happened"
109 if not os.path.exists(comp_folder):
110 print(f
"Comparison folder {comp_folder} does not exist")
112 if not os.path.isfile(comp_json):
113 print(f
"Comparison json {comp_json} does not exist")
117 some_plot = os.path.join(
120 "validationTestPlots_gaus_histogram.pdf",
122 if not os.path.isfile(some_plot):
123 print(f
"Comparison plot {some_plot} does not exist")
126 print(
"Comparison properly created")
130def check_for_content(revs, min_matrix_plots, min_plot_objects):
132 Checks for the expected content on the validation website
134 with splinter.Browser(
"firefox", headless=
True)
as browser:
136 url = validation_url +
"static/validation.html"
137 print(f
"Opening {url} to perform checks")
140 if len(browser.title) == 0:
141 print(
"Validation website cannot be loaded")
144 found_revs = browser.find_by_css(
".revision-label")
147 rr = [web_r
for web_r
in found_revs
if web_r.value == r]
150 f
"Revision {r} was not found on validation website. It should be there."
154 plot_objects = browser.find_by_css(
".object")
156 print(f
"Checking for a minimum number of {min_plot_objects} plot objects")
157 if len(plot_objects) < min_plot_objects:
159 f
"Only {len(plot_objects)} plots found, while {min_plot_objects} are expected"
164 checkbox_overview = browser.find_by_id(
"check_show_overview")
166 checkbox_overview.check()
167 found_matrix_plots = browser.find_by_css(
".plot_matrix_item")
169 if len(found_matrix_plots) < min_matrix_plots:
170 print(f
"Only {len(found_matrix_plots)} matrix plots found, while {min_matrix_plots} are expected")
178 Runs two test validations, starts the web server and queries data
183 revs_to_gen = [
"stack_test_1",
"stack_test_2",
"stack_test_3"]
187 with tempfile.TemporaryDirectory()
as tmpdir:
190 os.chdir(str(tmpdir))
192 for r
in revs_to_gen:
193 check_execute(f
"b2validation -p 4 --test --tag {r}")
201 server_process = subprocess.Popen([
"b2validation-server",
"--ip",
"::"])
203 server_process = subprocess.Popen([
"b2validation-server",
"--ip",
"127.0.0.1"])
206 active_host = wait_for_port_any(8000, timeout=30)
208 print(
"Validation server did not start within 30 s")
209 server_process.terminate()
213 global validation_url
214 if ":" in active_host:
215 validation_url = f
"http://[{active_host}]:8000/"
217 validation_url = f
"http://{active_host}:8000/"
221 success = success
and check_for_content(
222 revs_to_gen + [
"reference"], 7, 7
226 success = success
and check_for_plotting(
227 revs_to_gen[:-1], str(tmpdir)
229 except BaseException:
232 e = sys.exc_info()[0]
235 print(traceback.format_exc())
239 server_process.terminate()
241 server_process.wait()
247if __name__ ==
"__main__":
get_html_plots_tag_comparison_json(output_base_dir, tags)
get_html_plots_tag_comparison_folder(output_base_dir, tags)