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 ¶
- func CreateConversation(t testing.TB, kernel *session.SessionImpl) durable.ConversationId
- func DocumentChanges(publication durable.CommitPublication) []durable.DocumentChange
- func DocumentCopyChanges(publication durable.CommitPublication) []durable.DocumentCopyChange
- func DocumentRetireChanges(publication durable.CommitPublication) []durable.DocumentRetireChange
- func Flush(kernel *session.SessionImpl)
- func ObserveCommitsFunc(s interface{ ... }, ...) func()
- func RefusingAt(...) (durable.CommitResult, error)
- type CommitFunc
- type ControlledStorage
- func (controlled *ControlledStorage) AdmittedCommits() [][]durable.StorageWrite
- func (controlled *ControlledStorage) Adopting() bool
- func (controlled *ControlledStorage) AfterAdopt(after func())
- func (controlled *ControlledStorage) Commit(ctx context.Context, batches [][]durable.StorageWrite, ...) (durable.CommitResult, error)
- func (controlled *ControlledStorage) Commits() [][]durable.StorageWrite
- func (controlled *ControlledStorage) Crash()
- func (controlled *ControlledStorage) Document(ctx context.Context, id durable.DocumentId, at durable.DocumentPoint) (*durable.StoredDocument, error)
- func (controlled *ControlledStorage) DocumentReadCount() int
- func (controlled *ControlledStorage) FailNextCommit(err error)
- func (controlled *ControlledStorage) FindDocument(ctx context.Context, address durable.DocumentAddress, at durable.DocumentPoint) (*durable.DocumentRecord, error)
- func (controlled *ControlledStorage) HoldCommits() *Gate
- func (controlled *ControlledStorage) HoldFindDocument() *Gate
- func (controlled *ControlledStorage) LastCommit() []durable.StorageWrite
- func (controlled *ControlledStorage) MintCount() int
- func (controlled *ControlledStorage) MintId() (int64, error)
- type Gate
- type Harness
- type Publications
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.
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 ¶
func (controlled *ControlledStorage) Document(ctx context.Context, id durable.DocumentId, at durable.DocumentPoint) (*durable.StoredDocument, error)
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 ¶
func (controlled *ControlledStorage) FindDocument(ctx context.Context, address durable.DocumentAddress, at durable.DocumentPoint) (*durable.DocumentRecord, error)
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.
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 ¶
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.