enginetest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 26 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 enginetest holds the differential checks that hold an engine of the shared C implementation against the pure-Go engine, which is the oracle: the same documents, requests, schemas and endpoints are judged by both, and the answers must agree. An engine is whatever runs the C engine's services (the cgo binding in pkg/ext-go/cgoengine, and any other build of the same C), so each engine's tests call these checks with their own Engine and nothing else changes.

Index

Constants

View Source
const GuestEnv = "ENGINETEST_GUEST"

GuestEnv names the mode in which a test binary serves as a plugin instead of running its tests. The process checks start the binary they run in as the child, with this variable set; an engine's TestMain calls MaybeServeGuest first.

Variables

This section is empty.

Functions

func CaseFoldingMatchesGoForEveryRune

func CaseFoldingMatchesGoForEveryRune(t *testing.T, e Engine)

CaseFoldingMatchesGoForEveryRune compares how the engine and Go decide that two artifact paths differ only in case, for every character whose lowercase differs from itself and for those next to them that do not fold. The engine pins the Unicode simple lowercase mapping of one version (lib/plugin/src/unicode_lower.h), where Go follows its toolchain: this test is what makes a toolchain that moves ahead of the table visible, and is skipped, with the reason, until the table is regenerated for it (pkg/ext-go/cgoengine/tools/README.md).

func Causes

func Causes(err error) string

Causes lists the classes an error can belong to. Two implementations agree when an error is in exactly the same classes, whatever its text.

func ContractMutationDifferential

func ContractMutationDifferential(t *testing.T, e Engine)

func DrainErrorCausesMatchGo

func DrainErrorCausesMatchGo(t *testing.T, e Engine)

DrainErrorCausesMatchGo compares calls and closes while a call is in flight. Every probe waits for the event it depends on, so nothing here races a timer: drain with no deadline, then a close that times out.

func DrainObserverEventsMatchGo

func DrainObserverEventsMatchGo(t *testing.T, e Engine)

DrainObserverEventsMatchGo reports a call refused while the session drains, and the call that was in flight when the drain began.

func EndpointAddressDifferential

func EndpointAddressDifferential(t *testing.T, e Engine)

The loopback test rests on net.SplitHostPort and net.ParseIP; the engine carries its own copies of their rules, so address text of every shape is compared.

func EndpointDefaultClock

func EndpointDefaultClock(t *testing.T, e Engine)

A policy with no clock uses the wall clock, as the Go package does.

func EndpointErrorsCarryNoValue

func EndpointErrorsCarryNoValue(t *testing.T, e Engine)

An endpoint is a credential: no outcome carries a part of one.

func EndpointFixture

func EndpointFixture(t *testing.T, e Engine)

Both implementations reproduce every outcome the fixture states.

func EndpointMutationDifferential

func EndpointMutationDifferential(t *testing.T, e Engine)

One-field mutations of an endpoint and of a policy are judged the same.

func EndpointTimeDifferential

func EndpointTimeDifferential(t *testing.T, e Engine)

Expiry is compared to the nanosecond, in any zone, at both edges of the allowed lifetime.

func EndpointTimeSpellingsAreStricterInTheEngine

func EndpointTimeSpellingsAreStricterInTheEngine(t *testing.T, e Engine)

Go parses a time with a lenient fallback when its fast path refuses a string (strict RFC 3339 checking is switched off in its source), so it accepts a few spellings that are not RFC 3339: an offset of 24 hours or 60 minutes, a comma before the fraction, year 0000. The engine accepts RFC 3339 and nothing else, which is the safe side of the difference: a host built on the engine refuses an endpoint a Go host would admit, never the other way round. The engine's side is pinned; Go's is only reported, since it may tighten.

func FrameValidationDifferential

func FrameValidationDifferential(t *testing.T, e Engine)

func FramesDescriptorDifferential

func FramesDescriptorDifferential(t *testing.T, e Engine)

func FramesMatchDifferential

func FramesMatchDifferential(t *testing.T, e Engine)

func FramesRequestDifferential

func FramesRequestDifferential(t *testing.T, e Engine)

func InstanceErrorCausesMatchGo

func InstanceErrorCausesMatchGo(t *testing.T, e Engine)

InstanceErrorCausesMatchGo runs the same sequence of operations through both managers and compares the class of every error.

func InstanceObserverEventsMatchGo

func InstanceObserverEventsMatchGo(t *testing.T, e Engine)

InstanceObserverEventsMatchGo runs the scenarios through both managers and requires the same events, in the same order: configured, retired and disposed, with the key and revision.

func MaybeServeGuest

func MaybeServeGuest()

MaybeServeGuest runs the plugin the environment asks for and exits, when GuestEnv is set. Call it at the start of TestMain.

func MultiFieldMutationDifferential

func MultiFieldMutationDifferential(t *testing.T, e Engine)

MultiFieldMutationDifferential changes three and four independent positions of a valid descriptor, request, response, progress frame, reverse request and package manifest at once and requires the C engine and the Go code to agree on whether the result is valid. The descriptor and request documents also carry the members that progress events and reverse calls added: an operation's progress flag, the reverse list, a request's rate and parent. EXT_PAIR_SCALE multiplies every sample size.

func OpenErrorCausesMatchGo

func OpenErrorCausesMatchGo(t *testing.T, e Engine)

OpenErrorCausesMatchGo compares failures while admitting a plugin.

func OpenObserverEventsMatchGo

func OpenObserverEventsMatchGo(t *testing.T, e Engine)

OpenObserverEventsMatchGo does the same for the ways admitting a plugin can fail: the verify, connect and handshake events, and their codes.

func PairwiseMutationDifferential

func PairwiseMutationDifferential(t *testing.T, e Engine)

PairwiseMutationDifferential changes two independent positions of a valid descriptor, request, response and package manifest at once and requires the C engine and the Go code to agree on whether the result is valid.

func ProcessObserverEventsMatchGo

func ProcessObserverEventsMatchGo(t *testing.T, e Engine)

ProcessObserverEventsMatchGo opens a child process through the pure-Go session (process.Start as the connect step) and through the engine, which owns the child, and requires the same events and the same error classes for every way admitting it can fail, and for a call that finds the child gone.

func RetryHintBoundMatchesGo

func RetryHintBoundMatchesGo(t *testing.T, e Engine)

A retry hint is whole milliseconds from zero to one year: the C engine used to accept anything an int64 holds.

func Run

func Run(t *testing.T, e Engine)

Run runs every check as a subtest. An engine that keeps the names of the checks as tests of its own (so that a failure names the check in its CI log) calls them one by one instead.

func SchemaGeneratedDifferential

func SchemaGeneratedDifferential(t *testing.T, e Engine)

SchemaGeneratedDifferential compares the C engine and the Go schema package on seeded random schemas that combine several keywords and nest, and on values built to sit on and across the bounds they declare. EXT_PAIR_SCALE multiplies the sample.

func SchemaMatrixDifferential

func SchemaMatrixDifferential(t *testing.T, e Engine)

func SessionErrorCausesMatchGo

func SessionErrorCausesMatchGo(t *testing.T, e Engine)

SessionErrorCausesMatchGo drives identical backends through the C-backed session and the pure-Go session and requires the same error classes and the same final state for every call.

func SessionObserverEventsMatchGo

func SessionObserverEventsMatchGo(t *testing.T, e Engine)

SessionObserverEventsMatchGo drives the scenarios of TestSessionErrorCausesMatchGo through the C-backed and the pure-Go session with an observer, and requires the same events in the same order: the stage, the identity, the contract and operation (blank when they are not valid names), the request id and the code.

func ZeroTimeInAnyZoneMatchesGo

func ZeroTimeInAnyZoneMatchesGo(t *testing.T, e Engine)

Go's zero time is no time at all, in whatever zone it is written.

Types

type Check

type Check struct {
	Name string
	Run  func(*testing.T, Engine)
}

Check is one differential check: it holds the engine against the pure-Go engine.

func Checks

func Checks() []Check

Checks lists every check this package holds, in a fixed order.

type Engine

type Engine struct {
	// Name says which engine failed, in messages.
	Name string
	// Call runs one of the engine's pure services (descriptor.validate, schema.validate,
	// endpoint.check, ...) on bounded JSON. No plugin is executed.
	Call func(operation string, input json.RawMessage) (json.RawMessage, error)
	// Fixtures is the directory of the shared fixtures, lib/plugin/testdata.
	Fixtures string
	// NewInstances opens the engine's instance manager over string values. Optional: the checks
	// that compare instance managers are skipped without it.
	NewInstances func(instance.Options[string]) (Instances, error)
	// Open admits a plugin through the engine, as plugin.Open does through the oracle. Optional:
	// the checks that compare sessions are skipped without it.
	Open func(ctx context.Context, d plugin.Descriptor, o plugin.Options) (Session, error)
	// OpenProcess is Open with a child process the engine itself starts (launch.Executable is the
	// test binary, which serves as the plugin: see MaybeServeGuest). Optional: the process check is
	// skipped without it.
	OpenProcess func(ctx context.Context, d plugin.Descriptor, launch Launch, o plugin.Options) (Session, error)
}

Engine is an implementation of the shared engine under test.

type EventLog

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

EventLog keeps the observer events of one session: everything but the duration.

func (*EventLog) Observe

func (r *EventLog) Observe(_ context.Context, e plugin.Event)

func (*EventLog) Text

func (r *EventLog) Text() string

type Instances

type Instances interface {
	Configure(ctx context.Context, key, revision string, config json.RawMessage) error
	Remove(key string) error
	Close(ctx context.Context) error
	// Acquire leases the instance stored under key and returns its value.
	Acquire(key string) (string, Lease, error)
}

Instances is the part of an instance manager that the checks use: the same calls on the oracle (instance.Manager) and on the engine under test.

type Launch

type Launch struct {
	Executable  string
	Environment []string
}

Launch is what an engine starts as the plugin's child process.

type Lease

type Lease interface{ Release() error }

Lease is held until Release; Release reports the error of disposing of a retired instance.

type Session

type Session interface {
	Call(context.Context, plugin.ContractRef, string, json.RawMessage) (json.RawMessage, error)
	State() plugin.State
	Close(context.Context) error
	Abort() error
}

Session is the part of a session that the checks use, the same on the oracle (plugin.Session) and on the engine under test.

Jump to

Keyboard shortcuts

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