MCPcopy Create free account
hub / github.com/ddnet/ddnet / Mastersrv

Class Mastersrv

scripts/integration_test.py:509–559  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

507
508
509class Mastersrv(Runnable):
510 def __init__(self, test_env, extra_args=[], config=None, communities_json=None): # noqa: B006 mutable-default-arguments
511 name = f"mastersrv{test_env.num_mastersrvs}"
512 if communities_json is not None:
513 communities_json_filename = f"{name}-communities.json"
514 with open(os.path.join(test_env.tmp_dir, communities_json_filename), "w", encoding="utf-8") as f:
515 f.write(communities_json)
516 config = config + f"""\
517[communities]
518json = {communities_json_filename!r}
519"""
520 if config is not None:
521 config_filename = f"{name}.toml"
522 with open(os.path.join(test_env.tmp_dir, config_filename), "w", encoding="utf-8") as f:
523 f.write(config)
524 extra_args = extra_args + [
525 "--config",
526 config_filename,
527 ]
528
529 super().__init__(
530 test_env,
531 name,
532 [
533 test_env.ddnet_mastersrv,
534 "--listen",
535 "[::]:0",
536 "--test-servers-route",
537 ]
538 + extra_args,
539 extra_env_vars={"RUST_LOG": "info,mastersrv=debug"},
540 log_is_stderr=True,
541 allow_unclean_exit=True, # We don't have a way to exit the mastersrv cleanly.
542 )
543 test_env.num_mastersrvs += 1
544
545 def next_event(self, timeout_id):
546 event = super().next_event(timeout_id)
547 if isinstance(event, Log):
548 if event.line.startswith("warp::server: listening on http://[::]:"):
549 self.port = int(event.line[len("warp::server: listening on http://[::]:") :])
550 return event
551
552 def exit(self):
553 self.process.terminate()
554
555 def wait_for_startup(self, timeout=5):
556 self.wait_for_log_prefix("warp::server: listening on http://[::]:", timeout=timeout)
557
558 def servers_json(self):
559 return json.loads(urlopen(f"http://[::1]:{self.port}/ddnet/15/test-servers.json").read())
560
561
562ALL_TESTS = []

Callers 1

mastersrvMethod · 0.85

Calls

no outgoing calls

Tested by 1

mastersrvMethod · 0.68