pulumi/pkg/engine/lifecycletest/fuzzing
Will Jones 85e39e09f6
Add the ability to fuzz parents and aliases (#17654)
In #17623 and the PRs that followed it, we added fuzz testing
capabilities to the engine's lifecycle test suite, with a view to
randomly generating test cases in the hopes of proactively finding
snapshot integrity bugs in our code. This commit extends the fuzzer so
that it randomly parents, re-parents, and aliases reparented resources,
covering the various parent/child relationships that these actions lead
to and which can result in snapshot integrity issues if handled
improperly. In particular, we can now fuzz the following:

* Randomly parenting a resource to another resource in an initial
snapshot.
* Randomly updating a resource in a program to either add, remove, or
change an existing parent.
* Randomly aliasing a resource whose parent (and consequently URN) has
been changed by a program to point back to the URN it had originally.

Part of #17213
2024-11-01 10:32:56 +00:00
..
README.md Support generating random fixtures in lifecycle tests (#17627) 2024-10-31 15:16:38 +00:00
fixture.go Support generating random fixtures in lifecycle tests (#17627) 2024-10-31 15:16:38 +00:00
plan.go Support generating random fixtures in lifecycle tests (#17627) 2024-10-31 15:16:38 +00:00
pretty.go Support generating random resources in lifecycle tests (#17623) 2024-10-29 13:22:47 +00:00
program.go Add the ability to fuzz parents and aliases (#17654) 2024-11-01 10:32:56 +00:00
provider.go Support generating random providers in lifecycle tests (#17626) 2024-10-29 17:51:29 +00:00
resource.go Add the ability to fuzz parents and aliases (#17654) 2024-11-01 10:32:56 +00:00
snapshot.go Add the ability to fuzz parents and aliases (#17654) 2024-11-01 10:32:56 +00:00
stack.go Support generating random resources in lifecycle tests (#17623) 2024-10-29 13:22:47 +00:00

README.md

(lifecycle-fuzzing)=

Fuzzing

Snapshot integrity errors are very problematic when they occur and can be hard to spot and prevent. To this end, a subset of the lifecycle test suite uses a combination of fuzzing and property-based testing via the Rapid Go library to randomly generate snapshots and programs to see whether or not it is possible to trigger a snapshot integrity error.

While snapshot integrity issues often happen as part of a chain of snapshot operations (e.g. the execution of multiple steps in a deployment), the precursor to any error state will always be a valid snapshot. Thus, rather than having to generate random chains of operations, we can instead simplify the problem to generating valid starting snapshots and then executing a single random operation on them. The strategy we employ is thus as follows:

  • Generate a snapshot (snapshot.go) consisting of a random set of resources (resource.go), including appropriate providers. Resources may randomly depend on each other, and may have random properties, such as whether they are custom resources or components, pending replacement, and so on.

  • Generate a program (program.go) from the previously generated snapshot. The program may choose to register any subset (including none) of the resources in the snapshot, as well as any set of new resources before, in between and after those specified in the snapshot. Resources from the snapshot that are registered may be copied as-is or registered with different properties.

  • Generate a set of provider implementations for the program (provider.go). Provider operations such as , , etc. may be configured to fail randomly, or return one of a set of random results (e.g. an update vs a replace for Diff), on a per-resource basis.

  • Generate an operation (one of preview, up, refresh and destroy) and associated configuration (such as a list of --targets), known in the test suite as a plan to execute (plan.go).

  • Combine the snapshot, program, providers and plan to form a fixture (fixture.go) and execute it. If the operation yields a valid snapshot, the test passes, whether the operation completes successfully or not. If an invalid snapshot is produced, the test fails and the reproducing combination of snapshot, program, providers and plan is returned for debugging.