mzcompose.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 that skipping versions when upgrading will fail.
  11. """
  12. from materialize.mz_version import MzVersion
  13. from materialize.mzcompose.composition import Composition
  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.testdrive import Testdrive
  18. from materialize.ui import UIError
  19. from materialize.version_list import (
  20. get_minor_mz_versions_listed_in_docs,
  21. )
  22. mz_options: dict[MzVersion, str] = {}
  23. SERVICES = [
  24. Cockroach(setup_materialize=True),
  25. Mz(app_password=""),
  26. Materialized(external_metadata_store=True, metadata_store="cockroach"),
  27. Testdrive(no_reset=True, metadata_store="cockroach"),
  28. ]
  29. def workflow_default(c: Composition) -> None:
  30. def process(name: str) -> None:
  31. if name == "default":
  32. return
  33. with c.test_case(name):
  34. c.workflow(name)
  35. c.test_parts(list(c.workflows.keys()), process)
  36. def workflow_test_version_skips(c: Composition) -> None:
  37. current_version = MzVersion.parse_cargo()
  38. # If the current version is `v0.X.0-dev`, two_minor_releases_before will be `v0.X-2.Y`.
  39. # where Y is the most recent patch version of the minor version.
  40. last_two_minor_releases = get_minor_mz_versions_listed_in_docs(
  41. respect_released_tag=True
  42. )[-2:]
  43. two_minor_releases_before = last_two_minor_releases[-2]
  44. one_minor_release_before = last_two_minor_releases[-1]
  45. if current_version.major == one_minor_release_before.major:
  46. assert (
  47. one_minor_release_before.minor < current_version.minor
  48. ), "current minor version matches last released minor version from docs; was the release bump merged?"
  49. print(
  50. f"Testing that a migration from two minor releases before (={two_minor_releases_before})"
  51. f" to the current version (={current_version}) should fail"
  52. )
  53. c.down(destroy_volumes=True)
  54. with c.override(
  55. Materialized(
  56. image=f"materialize/materialized:{two_minor_releases_before}",
  57. external_metadata_store=True,
  58. options=[
  59. opt
  60. for start_version, opt in mz_options.items()
  61. if two_minor_releases_before >= start_version
  62. ],
  63. metadata_store="cockroach",
  64. )
  65. ):
  66. c.up("materialized")
  67. c.kill("materialized")
  68. try:
  69. # This will bring up version `0.X.0-dev`.
  70. # Note: We actually want to retry this 0 times, but we need to retry at least once so a
  71. # UIError is raised instead of an AssertionError
  72. c.up("materialized", max_tries=1)
  73. raise RuntimeError("skipping versions should fail")
  74. except UIError:
  75. # Noting useful in the error message to assert. Ideally we'd check that the error is due to
  76. # skipping versions.
  77. pass