testrun

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package testrun carries correlation identity across test runners and their child processes. It is intentionally independent of any process or network fixture so those owners can evolve without changing the trace contract.

Index

Constants

View Source
const (
	EventSchemaVersion        = "windshare.test-event/v1"
	MaximumEventDocumentBytes = 1 << 20
	MaximumRecordedEvents     = 1024

	// Sink and writer calls cross caller-controlled boundaries. Separate limits
	// let the outer recorder retire a wedged sink after an inner adapter has had
	// enough time to report its own bounded delivery failure.
	EventSinkCallTimeout    = 2 * time.Second
	EventAdapterCallTimeout = time.Second
	EventWriterCallTimeout  = time.Second
	EventPayloadCallTimeout = time.Second

	ListenerReadyMilestone = "listener_ready"
)
View Source
const (
	RunIDEnvironment       = "WINDSHARE_TEST_RUN_ID"
	OperationIDEnvironment = "WINDSHARE_TEST_OPERATION_ID"
	ScenarioEnvironment    = "WINDSHARE_TEST_SCENARIO"
)

Variables

View Source
var (
	ErrEventDeliveryTimeout = errors.New("test event delivery timed out")
	ErrEventDeliveryPanic   = errors.New("test event delivery panicked")
	ErrEventJournalFull     = errors.New("test event journal is full")
	ErrEventPayloadTimeout  = errors.New("test event payload encoding timed out")
	ErrEventPayloadPanic    = errors.New("test event payload encoding panicked")
)

Functions

func IsDeliveryFailure

func IsDeliveryFailure(err error) bool

IsDeliveryFailure distinguishes external adapter health from preparation or authoritative-journal failures without evaluating caller error methods.

func ValidateEvent

func ValidateEvent(event Event) error

func ValidateIdentity

func ValidateIdentity(identity Identity) error

ValidateIdentity applies the same portable correlation contract used when an Operation is constructed. Protocol boundaries use this projection so event validation cannot silently accept identities that child propagation rejects.

func ValidateMilestone

func ValidateMilestone(milestone Milestone) error

ValidateMilestone lets higher-level lifecycle owners commit semantic state before publication without duplicating the recorder's portable wire rules.

Types

type Component

type Component string

Component and Milestone prevent recorder call sites from swapping two otherwise indistinguishable strings in the six-field trace contract.

type EnvironmentLookup

type EnvironmentLookup func(string) (string, bool)

EnvironmentLookup matches os.LookupEnv while keeping environment resolution deterministic in tests and embedders.

type Event

type Event struct {
	SchemaVersion string `json:"schema_version"`
	Identity
	Component string          `json:"component"`
	Milestone string          `json:"milestone"`
	Outcome   string          `json:"outcome"`
	Payload   json.RawMessage `json:"payload,omitempty"`
}

Event is the canonical structured record shared by in-process scenarios and owned child processes. Payload is optional semantic JSON context, never a replacement for one of the six stable correlation and decision fields. Its object order and numeric spelling are deliberately not a cross-runtime byte contract.

type EventSink

type EventSink interface {
	WriteEvent(Event) error
}

EventSink is defined at the recorder's consumption boundary so transports can be injected without making testrun depend on a process or network fixture.

func EventSinkFunc

func EventSinkFunc(function func(Event) error) EventSink

EventSinkFunc adapts a callback behind a persistent delivery boundary. The function spelling preserves concise injection call sites while preventing repeated direct calls from accumulating one wedged goroutine per attempt.

type Identity

type Identity struct {
	RunID       string `json:"run_id"`
	OperationID string `json:"operation_id"`
	Scenario    string `json:"scenario"`
}

Identity is the transport-neutral projection of an Operation. Process ownership may carry the same identity, but it does not own its semantics.

type JSONLineSink

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

JSONLineSink writes one complete canonical event per line. Sharing one sink per destination makes concurrent recorders atomic without relying on stderr prose or testing.T logging prefixes.

func NewJSONLineSink

func NewJSONLineSink(writer io.Writer) (*JSONLineSink, error)

func (*JSONLineSink) WriteEvent

func (sink *JSONLineSink) WriteEvent(event Event) error

type ListenerReadyContext

type ListenerReadyContext struct {
	Address string `json:"address"`
}

ListenerReadyContext is shared by process fixtures and listener-owning children so the published address remains a typed protocol field.

type Milestone

type Milestone string
const (
	ScenarioLifecycleMilestone Milestone = "scenario_lifecycle"
	PeerReadyMilestone         Milestone = "peer_ready"
	LaneAdoptedMilestone       Milestone = "lane_adopted"
	CleanupMilestone           Milestone = "cleanup"
)

type Operation

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

Operation identifies one scenario within a run. Its fields are immutable so correlation cannot drift after child environments or events are created.

func NewOperation

func NewOperation(runID, operationID, scenario string) (Operation, error)

NewOperation validates a correlation tuple read from a trusted protocol boundary such as a child environment or a test fixture.

func OperationFromEnvironment

func OperationFromEnvironment(lookup EnvironmentLookup) (Operation, bool, error)

OperationFromEnvironment reads an all-or-nothing child correlation tuple. A partially propagated tuple is an orchestration failure, not an invitation to invent a second identity inside the child.

func (Operation) ChildEnvironment

func (operation Operation) ChildEnvironment(base []string) ([]string, error)

ChildEnvironment returns a copy with one authoritative value for each correlation variable. Case-insensitive replacement prevents Windows from retaining a second spelling that a cross-platform child might interpret.

func (Operation) EventIdentity

func (operation Operation) EventIdentity() Identity

EventIdentity projects correlation without exposing mutable operation state.

func (Operation) ID

func (operation Operation) ID() string

func (Operation) RunID

func (operation Operation) RunID() string

func (Operation) Scenario

func (operation Operation) Scenario() string

type Outcome

type Outcome string

Outcome is deliberately closed so trace consumers never have to infer success semantics from free-form log prose.

const (
	OutcomeStarted   Outcome = "started"
	OutcomeSucceeded Outcome = "succeeded"
	OutcomeFailed    Outcome = "failed"
)

type PreparedEvent

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

PreparedEvent is a fully validated immutable event that cannot be forged outside this package. Separating preparation lets lifecycle owners mutate phase state only after caller marshal hooks have completed safely.

type Recorder

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

Recorder binds immutable operation identity and component context once. This prevents protocol operation IDs from being substituted into observability envelopes at individual call sites.

func NewRecorder

func NewRecorder(operation Operation, component Component, sink EventSink) (*Recorder, error)

func (*Recorder) Events

func (recorder *Recorder) Events() []Event

Events returns the recorder-owned authoritative journal. Delivery adapters may fail or time out, but a consumer can always pull the bounded event history without invoking external code from a lifecycle-critical path.

func (*Recorder) PrepareEvent

func (recorder *Recorder) PrepareEvent(
	milestone Milestone,
	outcome Outcome,
	payload any,
) (PreparedEvent, error)

PrepareEvent invokes the recorder's persistent caller-payload boundary. Once a payload hook fails, panics, or times out, later preparations fail immediately without creating another caller goroutine.

func (*Recorder) Record

func (recorder *Recorder) Record(milestone Milestone, outcome Outcome, payload any) error

func (*Recorder) RecordEncoded

func (recorder *Recorder) RecordEncoded(
	milestone Milestone,
	outcome Outcome,
	payload json.RawMessage,
) error

RecordEncoded publishes already-encoded semantic JSON without invoking a caller marshaler. Lifecycle frameworks use this path for their closed payload model so a retired caller-payload boundary cannot suppress cleanup or terminal evidence.

func (*Recorder) RecordPrepared

func (recorder *Recorder) RecordPrepared(prepared PreparedEvent) error

RecordPrepared commits an event only after every caller-controlled preparation hook and deterministic validation step has completed.

type Run

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

Run identifies one package-suite invocation, including every child scenario launched by that invocation.

func NewRun

func NewRun(id string) (Run, error)

NewRun validates an externally supplied run identity.

func PackageRun

func PackageRun() (Run, error)

PackageRun resolves the runner-provided identity once. Direct go test invocations receive a process-local fallback, while malformed explicit input fails closed instead of producing uncorrelatable logs.

func (Run) ID

func (run Run) ID() string

ID returns the validated run identity.

func (Run) NewOperation

func (run Run) NewOperation(scenario string) (Operation, error)

NewOperation generates a fresh identity for a scenario.

Jump to

Keyboard shortcuts

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