mzcompose.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. Verify that Materialize has the same results with different sets of feature flags.
  11. """
  12. from materialize.feature_flag_consistency.feature_flag_consistency_test import (
  13. FeatureFlagConsistencyTest,
  14. )
  15. from materialize.feature_flag_consistency.input_data.feature_flag_configurations import (
  16. FEATURE_FLAG_CONFIGURATION_PAIRS,
  17. )
  18. from materialize.mzcompose.composition import Composition, WorkflowArgumentParser
  19. from materialize.mzcompose.services.cockroach import Cockroach
  20. from materialize.mzcompose.services.materialized import Materialized
  21. from materialize.mzcompose.services.mz import Mz
  22. from materialize.mzcompose.services.postgres import Postgres
  23. from materialize.mzcompose.test_result import FailedTestExecutionError
  24. from materialize.output_consistency.execution.evaluation_strategy import (
  25. EVALUATION_STRATEGY_NAME_DFR,
  26. INTERNAL_EVALUATION_STRATEGY_NAMES,
  27. )
  28. from materialize.output_consistency.execution.query_output_mode import (
  29. QUERY_OUTPUT_MODE_CHOICES,
  30. QueryOutputMode,
  31. )
  32. from materialize.output_consistency.output_consistency_test import (
  33. upload_output_consistency_results_to_test_analytics,
  34. )
  35. SERVICES = [
  36. Cockroach(setup_materialize=True),
  37. Postgres(),
  38. Materialized(name="mz_this"), # Overridden below
  39. Materialized(name="mz_other"), # Overridden below
  40. Mz(app_password=""),
  41. ]
  42. def workflow_default(c: Composition, parser: WorkflowArgumentParser) -> None:
  43. """
  44. Test the consistency with another mz version.
  45. """
  46. c.down(destroy_volumes=True)
  47. test = FeatureFlagConsistencyTest()
  48. parser.add_argument("--configuration", action="append", default=[], type=str)
  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. "--query-output-mode",
  62. type=lambda mode: QueryOutputMode[mode.upper()],
  63. choices=QUERY_OUTPUT_MODE_CHOICES,
  64. default=QueryOutputMode.SELECT,
  65. )
  66. args = test.parse_output_consistency_input_args(parser)
  67. port_mz_default_internal, port_mz_system_internal = 6875, 6877
  68. port_mz_default_this, port_mz_system_this = 6875, 6877
  69. port_mz_default_other, port_mz_system_other = 16875, 16877
  70. configurations = args.configuration
  71. if len(configurations) == 0:
  72. configurations = FEATURE_FLAG_CONFIGURATION_PAIRS.keys()
  73. runtime_per_config_in_sec = args.max_runtime_in_sec / len(configurations)
  74. test_summaries = []
  75. for configuration in configurations:
  76. test.set_configuration_pair_by_name(configuration)
  77. assert test.flag_configuration_pair is not None
  78. print(f"Running flag configuration: {test.flag_configuration_pair.name}")
  79. with c.override(
  80. Materialized(
  81. name="mz_this",
  82. ports=[
  83. f"{port_mz_default_this}:{port_mz_default_internal}",
  84. f"{port_mz_system_this}:{port_mz_system_internal}",
  85. ],
  86. additional_system_parameter_defaults=test.flag_configuration_pair.config1.to_system_params(),
  87. use_default_volumes=False,
  88. ),
  89. Materialized(
  90. name="mz_other",
  91. ports=[
  92. f"{port_mz_default_other}:{port_mz_default_internal}",
  93. f"{port_mz_system_other}:{port_mz_system_internal}",
  94. ],
  95. additional_system_parameter_defaults=test.flag_configuration_pair.config2.to_system_params(),
  96. use_default_volumes=False,
  97. ),
  98. ):
  99. c.up("mz_this", "mz_other")
  100. default_connection = c.sql_connection(
  101. service="mz_this", port=port_mz_default_internal
  102. )
  103. mz_system_connection = c.sql_connection(
  104. service="mz_this", port=port_mz_system_internal, user="mz_system"
  105. )
  106. test.mz2_connection = c.sql_connection(
  107. service="mz_other", port=port_mz_default_internal
  108. )
  109. test.mz2_system_connection = c.sql_connection(
  110. service="mz_other", port=port_mz_system_internal, user="mz_system"
  111. )
  112. test.evaluation_strategy_name = args.evaluation_strategy
  113. test_summary = test.run_output_consistency_tests(
  114. default_connection,
  115. mz_system_connection,
  116. args,
  117. query_output_mode=args.query_output_mode,
  118. override_max_runtime_in_sec=runtime_per_config_in_sec,
  119. )
  120. test_summaries.append(test_summary)
  121. assert len(test_summaries) > 0
  122. merged_summary = test_summaries[0]
  123. for test_summary in test_summaries[1:]:
  124. merged_summary.merge(test_summary)
  125. upload_output_consistency_results_to_test_analytics(c, merged_summary)
  126. if not merged_summary.all_passed():
  127. raise FailedTestExecutionError(errors=merged_summary.failures)