sessiontest

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package sessiontest holds the shared Session test support: a controlled memory storage and an opened Session kernel with its publications.

Ports packages/durable/test/session-support.ts

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateConversation

func CreateConversation(t testing.TB, kernel *session.SessionImpl) durable.ConversationId

CreateConversation creates one ownerless conversation and returns its ID.

func DocumentChanges

func DocumentChanges(publication durable.CommitPublication) []durable.DocumentChange

DocumentChanges returns the document changes of a publication that carry a value: creations and updates, no retirements.

func DocumentCopyChanges

func DocumentCopyChanges(publication durable.CommitPublication) []durable.DocumentCopyChange

DocumentCopyChanges returns the document copy changes of a publication.

func DocumentRetireChanges

func DocumentRetireChanges(publication durable.CommitPublication) []durable.DocumentRetireChange

DocumentRetireChanges returns the document retirements of a publication.

func Flush

func Flush(kernel *session.SessionImpl)

Flush waits until every scheduled watch and state delivery drained, as upstream's flush waits one macrotask.

func ObserveCommitsFunc

func ObserveCommitsFunc(s interface {
	ObserveCommits(durable.CommitObserver) durable.CommitObservation
}, f func(ctx context.Context, publication durable.CommitPublication)) func()

ObserveCommitsFunc observes the commits of s (a Session or a Harness) with f and returns the observation's Detach.

func RefusingAt

func RefusingAt(
	commit func(ctx context.Context, batches [][]durable.StorageWrite, receive func(index int, seq durable.Seq)) (durable.CommitResult, error),
	ctx context.Context,
	batches [][]durable.StorageWrite,
	receive func(index int, seq durable.Seq),
	refuses func(writes []durable.StorageWrite) bool,
	err error,
) (durable.CommitResult, error)

RefusingAt commits batches through commit up to the first one refuses matches, which it refuses with err: what a storage does whose own check refuses that batch.

Types

type CommitFunc

type CommitFunc func(ctx context.Context, publication durable.CommitPublication)

CommitFunc is a CommitObserver that runs a function for each publication and ignores its end.

func (CommitFunc) Advance

func (f CommitFunc) Advance(ctx context.Context, publication durable.CommitPublication)

Advance runs the function.

func (CommitFunc) End

End ignores the end.

type ControlledStorage

type ControlledStorage struct {
	*storage.MemoryStorage
	// contains filtered or unexported fields
}

ControlledStorage is memory storage with observable commits, held calls, and injected commit failures.

func NewControlledStorage

func NewControlledStorage() *ControlledStorage

NewControlledStorage returns an empty controlled memory storage.

func (*ControlledStorage) AdmittedCommits

func (controlled *ControlledStorage) AdmittedCommits() [][]durable.StorageWrite

AdmittedCommits returns the exact batches the Session admitted.

func (*ControlledStorage) Adopting

func (controlled *ControlledStorage) Adopting() bool

Adopting reports whether the caller runs inside a receipt callback of a Storage.Commit, the storage's synchronous step.

func (*ControlledStorage) AfterAdopt

func (controlled *ControlledStorage) AfterAdopt(after func())

AfterAdopt makes the next commit run after, once, in its synchronous step right after its first receipt returned.

func (*ControlledStorage) Commit

func (controlled *ControlledStorage) Commit(ctx context.Context, batches [][]durable.StorageWrite, receive func(index int, seq durable.Seq)) (durable.CommitResult, error)

Commit records and holds the call, then fails its first batch if a failure is set (a refusal: nothing stored), or commits it in memory, Adopting set while each receipt runs and AfterAdopt run after the first one.

func (*ControlledStorage) Commits

func (controlled *ControlledStorage) Commits() [][]durable.StorageWrite

Commits returns detached copies of the admitted batches for value assertions.

func (*ControlledStorage) Crash

func (controlled *ControlledStorage) Crash()

Crash simulates a crash during the held commit: it never reaches storage, and later commits proceed.

func (*ControlledStorage) Document

Document counts and materializes.

func (*ControlledStorage) DocumentReadCount

func (controlled *ControlledStorage) DocumentReadCount() int

DocumentReadCount returns the number of document materializations.

func (*ControlledStorage) FailNextCommit

func (controlled *ControlledStorage) FailNextCommit(err error)

FailNextCommit makes the next commit fail with err.

func (*ControlledStorage) FindDocument

FindDocument honors a held gate, then resolves.

func (*ControlledStorage) HoldCommits

func (controlled *ControlledStorage) HoldCommits() *Gate

HoldCommits holds every commit until the returned gate is released.

func (*ControlledStorage) HoldFindDocument

func (controlled *ControlledStorage) HoldFindDocument() *Gate

HoldFindDocument holds every document lookup until the returned gate is released.

func (*ControlledStorage) LastCommit

func (controlled *ControlledStorage) LastCommit() []durable.StorageWrite

LastCommit returns the newest admitted batch.

func (*ControlledStorage) MintCount

func (controlled *ControlledStorage) MintCount() int

MintCount returns the number of minted IDs.

func (*ControlledStorage) MintId

func (controlled *ControlledStorage) MintId() (int64, error)

MintId counts and mints.

type Gate

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

Gate holds calls until released and reports when the first held call arrives.

func (*Gate) Entered

func (gate *Gate) Entered() <-chan struct{}

Entered is closed when the first held call arrives.

func (*Gate) Release

func (gate *Gate) Release()

Release lets every held call proceed and stops holding later calls.

type Harness

type Harness struct {
	Storage      *ControlledStorage
	Session      *session.SessionImpl
	Publications *Publications
}

Harness is a Session kernel plus its controlled storage and every committed publication.

func OpenReportingTestSession

func OpenReportingTestSession(report func(error)) Harness

OpenReportingTestSession is OpenTestSession with a Session that hands its failure, and the errors of its listeners, to report.

func OpenTestSession

func OpenTestSession() Harness

OpenTestSession opens a Session kernel over a controlled storage.

type Publications

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

Publications collects every committed publication.

func (*Publications) All

func (publications *Publications) All() []durable.CommitPublication

All returns the publications so far.

func (*Publications) Last

func (publications *Publications) Last() durable.CommitPublication

Last returns the newest publication.

func (*Publications) Len

func (publications *Publications) Len() int

Len returns the number of publications.

Jump to

Keyboard shortcuts

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