finalizer

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package finalizer removes what a cloud suite run left behind in the shared organisation.

The framework's cleanup registry deletes only what a scenario registered and gives up on a delete that failed, so a failed scenario, a refused delete or an interrupted step can leave resources in a long-lived organisation. A Tracker records the name suffix of every runner of a run and, after the run, deletes each entry of the organisation's collections that is named with one of those suffixes. It is shared by the cloud suite's step packages; each supplies the Collections of the platform it drives.

Index

Constants

View Source
const DefaultMinAttempt = 15 * time.Second

DefaultMinAttempt is the time a deletion gets when its collection's Timeout is already spent.

Variables

This section is empty.

Functions

func OwnedBy

func OwnedBy(names, suffixes []string) bool

OwnedBy reports whether any name carries one of the suffixes as a whole name segment, so an entry of another run, or one the suite never creates, is never matched. Names are compared lower-cased with underscores read as dashes, the form a generated handle takes.

Types

type Collection

type Collection struct {
	// Name identifies the collection in diagnostics and in the removed list.
	Name string
	// List returns the entries of the collection. When it fails part way it may return the
	// entries it read together with the error; those are still swept and the error is reported.
	List func(ctx context.Context) ([]Leftover, error)
	// Delete removes one entry by its ID. An entry that is already gone is not an error.
	Delete func(ctx context.Context, id string) error
	// Timeout bounds the time this collection may spend, within the caller's own deadline. Each
	// deletion may use what is left of it. Once it is spent, a deletion still gets MinAttempt, so
	// no leftover goes without an attempt. Zero leaves only the caller's deadline.
	Timeout time.Duration
	// MinAttempt is the time a deletion gets after Timeout is spent. Zero means
	// DefaultMinAttempt.
	MinAttempt time.Duration
}

Collection is one list of the system under test that a Tracker reads and deletes from.

type Leftover

type Leftover struct {
	// ID is what Collection.Delete needs to delete the entry.
	ID string
	// Names are every value a generated name can appear in for this entry, such as its id,
	// handle and display name. A handle cut to fit a length limit loses the runner suffix, but
	// the display name it was cut from keeps it.
	Names []string
}

Leftover is one entry a Sweep found in the system under test.

type Tracker

type Tracker struct {
	// contains filtered or unexported fields
}

Tracker holds the runner suffixes of one run and sweeps the organisation for entries named with them. Every name from the framework's unique generator carries its runner's suffix.

func NewTracker

func NewTracker(log *slog.Logger) *Tracker

NewTracker returns a Tracker that has seen no runner yet. A nil logger selects the default logger.

func (*Tracker) Owns

func (t *Tracker) Owns(names []string) bool

Owns reports whether any of the names carries the suffix of a tracked runner.

func (*Tracker) Sweep

func (t *Tracker) Sweep(ctx context.Context, collections []Collection) ([]string, error)

Sweep runs through the collections in order. For each it lists the collection, keeps the entries named with a tracked suffix and deletes them, carrying on past a failure. It returns what it removed as "<collection name>/<id>", each one a leak the registry cleanup missed, and the joined errors for what it could not list or delete.

func (*Tracker) Track

func (t *Tracker) Track(suffix string)

Track records a runner's name suffix, as Generator.Suffix reports it. An empty suffix is ignored, because it would match every name.

func (*Tracker) Tracked

func (t *Tracker) Tracked() bool

Tracked reports whether any runner suffix has been recorded.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL