sessiontest

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2026 License: MIT Imports: 7 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.

func DocumentCopyChanges

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

DocumentCopyChanges returns the document copy changes 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.

Types

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) Commit

func (controlled *ControlledStorage) Commit(ctx context.Context, writes []durable.StorageWrite) (durable.Seq, error)

Commit records the batch, honors a held gate and an injected failure, then commits.

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 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