lint_test_flags.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. #
  10. # lint_test_flags.py - Check that new configs are used in parallel workload and other tests
  11. import argparse
  12. import random
  13. import re
  14. import sys
  15. from pathlib import Path
  16. from materialize.mz_version import MzVersion
  17. from materialize.mzcompose import (
  18. UNINTERESTING_SYSTEM_PARAMETERS,
  19. get_default_system_parameters,
  20. )
  21. from materialize.parallel_workload.action import FlipFlagsAction
  22. CONFIG_REGEX = re.compile(r' Config::new\(\s*"([^"]+)"', re.MULTILINE)
  23. def main() -> int:
  24. parser = argparse.ArgumentParser(
  25. prog="lint-tests-flags",
  26. formatter_class=argparse.RawDescriptionHelpFormatter,
  27. description="Check that new configs are used in parallel workload and other tests",
  28. )
  29. parser.parse_args()
  30. configs = []
  31. for path in Path("src").rglob("*.rs"):
  32. if path in [Path("src/dyncfg/src/lib.rs"), Path("src/dyncfg-file/src/lib.rs")]:
  33. continue # contains tests
  34. with path.open(encoding="utf-8") as file:
  35. content = file.read()
  36. if matches := CONFIG_REGEX.findall(content):
  37. configs.extend(matches)
  38. action = FlipFlagsAction(random.Random(), None)
  39. parallel_workload_known_flags = set(action.flags_with_values).union(
  40. action.uninteresting_flags
  41. )
  42. mzcompose_known_flags = set(
  43. get_default_system_parameters(MzVersion.parse_cargo()).keys()
  44. ).union(UNINTERESTING_SYSTEM_PARAMETERS)
  45. found = False
  46. for config in configs:
  47. if config not in parallel_workload_known_flags:
  48. print(
  49. f'Configuration flag "{config}" seems to have been introduced/changed. Make sure parallel-workload\'s FlipFlagsAction in misc/python/materialize/parallel_workload/action.py knows about some valid values for it'
  50. )
  51. found = True
  52. for config in configs:
  53. if config not in mzcompose_known_flags:
  54. print(
  55. f'Configuration flag "{config}" seems to have been introduced/changed. Make sure get_variable_system_parameters/get_minimal_system_parameters/UNINTERESTING_SYSTEM_PARAMETERS in misc/python/materialize/mzcompose/__init__.py knows about some valid values for it'
  56. )
  57. found = True
  58. return int(found)
  59. if __name__ == "__main__":
  60. sys.exit(main())