mzcompose.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. Test the consistency with another mz version.
  11. """
  12. import argparse
  13. from materialize.mzcompose.composition import Composition, WorkflowArgumentParser
  14. from materialize.mzcompose.services.cockroach import Cockroach
  15. from materialize.mzcompose.services.materialized import Materialized
  16. from materialize.mzcompose.services.mz import Mz
  17. from materialize.mzcompose.services.postgres import Postgres
  18. from materialize.mzcompose.test_result import FailedTestExecutionError
  19. from materialize.output_consistency.execution.evaluation_strategy import (
  20. EVALUATION_STRATEGY_NAME_DFR,
  21. INTERNAL_EVALUATION_STRATEGY_NAMES,
  22. )
  23. from materialize.output_consistency.execution.query_output_mode import (
  24. QUERY_OUTPUT_MODE_CHOICES,
  25. QueryOutputMode,
  26. )
  27. from materialize.output_consistency.output_consistency_test import (
  28. upload_output_consistency_results_to_test_analytics,
  29. )
  30. from materialize.version_ancestor_overrides import (
  31. ANCESTOR_OVERRIDES_FOR_CORRECTNESS_REGRESSIONS,
  32. )
  33. from materialize.version_consistency.version_consistency_test import (
  34. VersionConsistencyTest,
  35. )
  36. from materialize.version_list import (
  37. resolve_ancestor_image_tag,
  38. )
  39. SERVICES = [
  40. Cockroach(setup_materialize=True),
  41. Postgres(),
  42. Materialized(name="mz_this"), # Overridden below
  43. Materialized(name="mz_other"), # Overridden below
  44. Mz(app_password=""),
  45. ]
  46. def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
  47. c.down(destroy_volumes=True)
  48. test = VersionConsistencyTest()
  49. parser.add_argument(
  50. "--evaluation-strategy",
  51. default=EVALUATION_STRATEGY_NAME_DFR,
  52. type=str,
  53. choices=INTERNAL_EVALUATION_STRATEGY_NAMES,
  54. )
  55. parser.add_argument(
  56. "--other-tag",
  57. type=str,
  58. default="common-ancestor",
  59. )
  60. parser.add_argument(
  61. "--allow-same-version-comparison",
  62. action=argparse.BooleanOptionalAction,
  63. default=False,
  64. )
  65. parser.add_argument(
  66. "--query-output-mode",
  67. type=lambda mode: QueryOutputMode[mode.upper()],
  68. choices=QUERY_OUTPUT_MODE_CHOICES,
  69. default=QueryOutputMode.SELECT,
  70. )
  71. args = test.parse_output_consistency_input_args(parser)
  72. port_mz_default_internal, port_mz_system_internal = 6875, 6877
  73. port_mz_default_this, port_mz_system_this = 6875, 6877
  74. port_mz_default_other, port_mz_system_other = 16875, 16877
  75. tag_mz_other = resolve_tag(args.other_tag)
  76. print(f"Using {tag_mz_other} as tag for other mz version")
  77. with c.override(
  78. Materialized(
  79. name="mz_this",
  80. image=None,
  81. ports=[
  82. f"{port_mz_default_this}:{port_mz_default_internal}",
  83. f"{port_mz_system_this}:{port_mz_system_internal}",
  84. ],
  85. use_default_volumes=False,
  86. ),
  87. Materialized(
  88. name="mz_other",
  89. image=f"materialize/materialized:{tag_mz_other}",
  90. ports=[
  91. f"{port_mz_default_other}:{port_mz_default_internal}",
  92. f"{port_mz_system_other}:{port_mz_system_internal}",
  93. ],
  94. use_default_volumes=False,
  95. ),
  96. ):
  97. c.up("mz_this", "mz_other")
  98. default_connection = c.sql_connection(
  99. service="mz_this", port=port_mz_default_internal
  100. )
  101. mz_system_connection = c.sql_connection(
  102. service="mz_this", port=port_mz_system_internal, user="mz_system"
  103. )
  104. test.mz2_connection = c.sql_connection(
  105. service="mz_other", port=port_mz_default_internal
  106. )
  107. test.mz2_system_connection = c.sql_connection(
  108. service="mz_other", port=port_mz_system_internal, user="mz_system"
  109. )
  110. test.evaluation_strategy_name = args.evaluation_strategy
  111. test_summary = test.run_output_consistency_tests(
  112. default_connection,
  113. mz_system_connection,
  114. args,
  115. query_output_mode=args.query_output_mode,
  116. )
  117. upload_output_consistency_results_to_test_analytics(c, test_summary)
  118. if not test_summary.all_passed():
  119. raise FailedTestExecutionError(errors=test_summary.failures)
  120. def resolve_tag(tag: str) -> str:
  121. if tag == "common-ancestor":
  122. return resolve_ancestor_image_tag(
  123. ANCESTOR_OVERRIDES_FOR_CORRECTNESS_REGRESSIONS
  124. )
  125. return tag