rpctest

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 20 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 rpctest runs a real notesd API server (store, blobs, broker, vaults, engine and rpcserver) on a temporary socket, for tests of clients such as notesctl. The socket, the serving goroutine and its stop are lodge's kit's (github.com/frostyard/lodge/kit/rpctest).

Index

Constants

View Source
const Name = "notesd rpctest"

Name is what the test server reports from rpc.hello.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	kitrpctest.Options[api.Services]
	// Log receives the server's logs; nil discards them.
	Log *slog.Logger
	// DataDir holds the database; empty means a fresh temporary directory.
	// Reusing one after Stop restarts notesd on the same data.
	DataDir string
	// Now, when set, is the clock for stored timestamps.
	Now func() time.Time
	// Vault tunes the vaults' actors (intervals, batch size); its DB,
	// Blobs, Log, Publish and, when Now is set, Now are filled in.
	Vault vault.Config
	// HubListen serves the hub's endpoints on a loopback port, at
	// Server.HubURL, as notesd --hub does; HubAddr, when set, is the
	// address, so a restarted hub keeps its URL.
	HubListen bool
	HubAddr   string
	// Crash is the simulation's crash points (vault.Config.Crash and its
	// syncer and hub counterparts).
	Crash func(point string) bool
	// Syncer tunes the device's sync loops (quiet periods, backoff, the
	// device's name); its stores, broker, secrets, log and, when Now is
	// set, Now are filled in.
	Syncer syncer.Config
	// Build is what rpc.hello reports as build (rpcserver.Options.Build).
	Build string
	// Panics records the panics of handlers (rpcserver.Options.Panics).
	Panics *problems.Recorder
}

Options configure a test server. Their Services, when set, edit the engine's services before the router is built, so a client's tests can serve a fake domain.

type Server

type Server struct {
	Socket string
	Run    *kitrpctest.Run
	DB     *store.DB
	Blobs  *blobs.Store
	Broker *events.Broker
	Vaults *vault.Manager
	RPC    *rpcserver.Server
	// Router serves every domain; pass it to RPC.ServeConn to test a
	// connection of another caller kind.
	Router *api.Router
	// Hub and Syncer are this notesd's hub role and sync loops; Secrets
	// keeps its device tokens, in a file. HubURL is set with HubListen.
	Hub     *hub.Hub
	Syncer  *syncer.Syncer
	Secrets secrets.Store
	HubURL  string
	// contains filtered or unexported fields
}

Server is a running test server; it stops when the test ends.

func Start

func Start(t testing.TB) *Server

Start runs a server with default options.

func StartWith

func StartWith(t testing.TB, o Options) *Server

StartWith runs a server with a fresh database, on a socket of its own (SocketPath).

func (*Server) Dial

func (s *Server) Dial(t testing.TB) *api.Client

Dial connects and completes rpc.hello; the client closes when the test ends.

func (*Server) DialAs

func (s *Server) DialAs(t testing.TB, id api.Identity) *api.Client

DialAs connects as a connection its listener authenticated as id (a session or an agent behind lodge, a device) over an in-process pipe, and completes rpc.hello; the client closes when the test ends.

func (*Server) Done added in v0.5.0

func (s *Server) Done() <-chan struct{}

Done is closed when Stop has cancelled the server's context and every context derived from it (the vault actors', the hub's, the sync loops'), before Stop waits for them to return. A crash point that runs in such a background goroutine (a sync loop's apply) can wait for it, so that the notesd it stops does nothing more after the crash, as a real crash would. A crash point inside an RPC handler must not wait for it: Stop first stops serving, which waits for the handlers. Done does not mean the goroutines have returned: Stop waits for that.

func (*Server) Stop

func (s *Server) Stop()

Stop shuts the server down now, as a crash between transactions would: the socket closes and the database is closed. The test's cleanup does the same; Stop is for restarting on the same DataDir.

func (*Server) Stopped added in v0.3.0

func (s *Server) Stopped() <-chan struct{}

Stopped is closed when the server has stopped serving, which rpc.shutdown (or Stop) causes: the socket is closed and answers no more.

Jump to

Keyboard shortcuts

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