Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:MaterializeInc Materialize Scenario Actions

From Leeroopedia


Knowledge Sources misc/python/materialize/checks/scenarios.py, misc/python/materialize/checks/scenarios_upgrade.py
Domains Upgrade Testing, Scenario Composition, Python API
Last Updated 2026-02-08

Overview

Concrete scenario framework for composing upgrade test action sequences, provided by materialize.checks.scenarios and materialize.checks.scenarios_upgrade.

Description

The Scenario base class in scenarios.py is the entry point for defining upgrade test plans. Its constructor accepts a list of Check classes, an Executor, a Features object, and an optional seed for randomization. It filters the check classes (excluding base classes, non-idempotent checks when required, etc.) and instantiates them with the scenario's base version.

The abstract actions() method must be overridden by every concrete scenario to return a list[Action] that defines the complete sequence of operations. The framework provides many concrete scenarios:

In scenarios.py:

  • NoRestartNoUpgrade — baseline scenario with no restarts.
  • RestartEntireMz — kills and restarts Materialize between every phase.
  • DropCreateDefaultReplica, RestartClusterdCompute, KillClusterdStorage, RestartCockroach, RestartSourcePostgres, RestartRedpandaDebezium — infrastructure disruption scenarios.
  • SystemVarChange — scenarios that alter system variables between phases.

In scenarios_upgrade.py:

  • UpgradeEntireMz — single-hop upgrade from last released version.
  • UpgradeEntireMzTwoVersions — upgrade through previous and last versions.
  • UpgradeEntireMzFourVersions — four-hop upgrade through multiple minor versions.
  • UpgradeClusterdComputeLast / UpgradeClusterdComputeFirst — component-level upgrades.
  • PreflightCheckContinue / PreflightCheckRollback — zero-downtime upgrade scenarios.
  • ActivateSourceVersioningMigration — forced migration scenario.
  • SelfManagedLinearUpgradePathManipulateBeforeUpgrade, SelfManagedLinearUpgradePathManipulateDuringUpgrade, SelfManagedRandomUpgradePath, SelfManagedEarliestToLatestDirectUpgrade — self-managed upgrade scenarios.

Usage

Use the Scenario class when defining a new upgrade path to test. Subclass it, implement actions() to return the desired action sequence, and optionally override base_version() to specify the starting version.

Code Reference

Source Location

  • misc/python/materialize/checks/scenarios.py, lines 48–130 (base class and basic scenarios).
  • misc/python/materialize/checks/scenarios_upgrade.py, lines 93–867 (upgrade-specific scenarios).

Signature

class Scenario:
    def __init__(
        self,
        checks: list[type[Check]],
        executor: Executor,
        features: Features,
        seed: str | None = None,
    ) -> None: ...

    def checks(self) -> list[type[Check]]: ...

    def actions(self) -> list[Action]: ...

    def base_version(self) -> MzVersion: ...

    def run(self) -> None: ...

    def requires_external_idempotence(self) -> bool: ...

    def does_forced_migrations(self) -> bool: ...

    def _include_check_class(self, check_class: type[Check]) -> bool: ...

Concrete upgrade scenario example (UpgradeEntireMz):

class UpgradeEntireMz(Scenario):
    def base_version(self) -> MzVersion:
        return get_last_version()

    def actions(self) -> list[Action]:
        return [
            StartMz(self, tag=self.base_version()),
            Initialize(self),
            Manipulate(self, phase=1),
            KillMz(capture_logs=True),
            StartMz(self, tag=None),
            Manipulate(self, phase=2),
            Validate(self),
            KillMz(capture_logs=True),
            StartMz(self, tag=None),
            Validate(self),
        ]

Import

from materialize.checks.scenarios import Scenario

I/O Contract

Inputs

Parameter Type Description
checks list[type[Check]] All available check classes to be filtered and instantiated by the scenario.
executor Executor The execution backend (mzcompose or cloudtest) that will run the actions.
features Features Feature flags controlling which optional services (e.g., Azurite) are enabled.
seed None Optional seed for deterministic randomization of check ordering.

Outputs

Method Return Type Description
actions() list[Action] Ordered sequence of actions defining the complete upgrade scenario.
base_version() MzVersion The initial Materialize version for the scenario (defaults to current cargo version).
checks() list[type[Check]] The filtered and optionally shuffled list of check classes.

Usage Examples

Defining a custom two-hop upgrade scenario:

from materialize.checks.scenarios import Scenario
from materialize.checks.actions import Action, Initialize, Manipulate, Validate
from materialize.checks.mzcompose_actions import StartMz, KillMz
from materialize.checks.scenarios_upgrade import get_last_version, get_previous_version
from materialize.mz_version import MzVersion


class MyCustomUpgrade(Scenario):
    def base_version(self) -> MzVersion:
        return get_previous_version()

    def actions(self) -> list[Action]:
        return [
            StartMz(self, tag=self.base_version()),
            Initialize(self),
            KillMz(capture_logs=True),
            StartMz(self, tag=get_last_version()),
            Manipulate(self, phase=1),
            KillMz(capture_logs=True),
            StartMz(self, tag=None),
            Manipulate(self, phase=2),
            Validate(self),
        ]

Checking which scenarios require external idempotence:

scenario = UpgradeEntireMz(checks, executor, features)
if scenario.requires_external_idempotence():
    print("This scenario calls validate() multiple times")

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment