Documentation
¶
Overview ¶
Package synctest is sync's seeded simulation (ADR-0020, docs/design/sync.md#testing): a hub and devices, each a whole notesd from rpctest over its own data directory and vault, syncing over loopback through links the simulation cuts and heals, while a seeded plan of steps edits, creates, moves, deletes, crashes and restarts. At each quiet point it checks that every vault equals the hub's heads, that no inserted token was lost, that no conflict copy exists, that the log holds its invariants, and that every device agrees with the hub.
Index ¶
- func Files(n *Node) map[string]string
- func PlanText(plan []Step) string
- func Run(t testing.TB, o Options, plan []Step) (err error)
- type Node
- type Op
- type Options
- type Profile
- type Step
- type World
- func (w *World) AddDevice(name string, vault map[string]string) (*Node, error)
- func (w *World) Check() error
- func (w *World) CheckIndexes() error
- func (w *World) Close()
- func (w *World) Delete(d *Node, p string) error
- func (w *World) Heads() map[string]string
- func (w *World) History(p string) ([]api.Revision, error)
- func (w *World) HubFile(p string) (api.LogFile, bool)
- func (w *World) Move(d *Node, from, to string) error
- func (w *World) MoveDisk(d *Node, from, to string) error
- func (w *World) Offline(d *Node)
- func (w *World) Online(d *Node)
- func (w *World) PairAgain(d *Node) error
- func (w *World) RemoveDevice(d *Node)
- func (w *World) Reset(d *Node) error
- func (w *World) RestartHub()
- func (w *World) Revoke(d *Node) error
- func (w *World) Settle() error
- func (w *World) SettleOnline() error
- func (w *World) Snapshot(d *Node) map[string]string
- func (w *World) Status(d *Node) (api.SyncStatus, error)
- func (w *World) Token() string
- func (w *World) Write(d *Node, p, content string) error
- func (w *World) WriteDisk(d *Node, p string, content []byte) error
- func (w *World) WriteFrom(d *Node, p, base, content string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Node ¶
type Node struct {
Name string
Dir string // the vault's folder
Srv *rpctest.Server
C *api.Client
Vault int64
// contains filtered or unexported fields
}
Node is one notesd of the world, with one vault.
type Op ¶
type Op int
Op is what a step does.
const ( Edit Op = iota // an editor's write with the current base StaleEdit // an editor's write with an older base: a local merge Append // an agent's append Outside // another program's edit on disk Create // a new note Daily // today's note, a path two devices may create offline Delete // a delete with the current base Move // a move through notesd DiskMove // a rename on disk Attach // an attachment that is not text, written on disk Offline // the device's link cut Online // the device's link healed Crash // a crash at a point, then a restart HubRestart // the hub stopped and started again HubCrash // the hub crashing after a push's rename DropAnswer // the hub losing a push's answer Reset // sync.reset // The ops below plan only in a Profile that weighs them, so the default // plans stay what they were. Swap // two notes swap paths through notesd CaseRename // a note's name changes only in case BigAttach // an attachment over 10 MB, written on disk RevokeAndPair // the hub revokes the device, which pairs again Snapshot // the device's vault copied, for a later Rejoin Rejoin // the device replaced by a new one joining with its copy )
The steps a plan is made of (ADR-0020).
type Options ¶
type Options struct {
Seed uint64
Devices int // [3]
Steps int
// Concurrent lets steps overlap sync; stepwise (the default) lets the
// world go quiet after every step, so a seed replays exactly.
Concurrent bool
// CheckEvery is how many steps pass between full checks [25 stepwise,
// 100 concurrent]; a run always checks at its end.
CheckEvery int
Log *slog.Logger // [discard]
// Watch, when set, logs each node's copy of the file at that path
// after every step: a debugging aid.
Watch string
// Profile, when set, adds a scenario's checks to every quiet point;
// its weights are PlanWith's to plan with.
Profile *Profile
}
Options configure a run.
type Profile ¶
type Profile struct {
// Weights are how often each op is planned, against the others; an op
// without a weight is never planned. Nil plans the default weights.
Weights map[Op]int
// Check runs at each quiet point, after the world's own checks.
Check func(w *World) error
}
Profile shapes a seeded run for a scenario (plan 0004, Phase 6): which ops it plans and how often, and checks of its own at each quiet point.
type Step ¶
Step is one planned step. A and B are choices, resolved against the world as the step runs (the k-th file by path, a line), so a plan with steps dropped still runs: what the reducer needs.
func PlanWith ¶
PlanWith makes the steps of a seed with weights, as Plan does with the default ones.
type World ¶
World is a hub and devices syncing one vault.
func NewWorld ¶
NewWorld starts a hub serving the seed files and o.Devices devices that have joined it.
func (*World) AddDevice ¶
AddDevice starts a device named name whose vault holds vault, pairs it with the hub and joins the hub's vault, as a user does with a copy of their notes. Tokens in vault the oracle has not seen are written by it.
func (*World) Check ¶
Check lets the world go quiet and checks it (ADR-0020): every device's files are the hub's heads; every token no writer removed is in a head or a conflict revision; no file is a conflict copy; the log has no gaps, every base is earlier, and no two live files share a path ignoring case; every device agrees with the hub.
func (*World) CheckIndexes ¶
CheckIndexes checks that every node's index equals a fresh rebuild of its vault: the last check of a run, since a rebuild costs a notesd.
func (*World) Delete ¶
Delete deletes the file at p on device d through notesd, with the base it reads; the tokens it held are removed on purpose.
func (*World) Move ¶
Move moves the file at from to to on device d through notesd, updating the links that name it.
func (*World) MoveDisk ¶
MoveDisk renames from to to on device d's disk, as a file manager would, and has notesd index both paths.
func (*World) PairAgain ¶
PairAgain pairs device d with the hub again, as its user does after a revocation; its vault then syncs again.
func (*World) RemoveDevice ¶
RemoveDevice stops device d and takes it out of the world. Settle first: what d has not pushed goes with it.
func (*World) RestartHub ¶
func (w *World) RestartHub()
RestartHub stops the hub's notesd and starts it again on its data.
func (*World) Settle ¶
Settle heals every link and waits for a quiet point: no device has anything to push, and each has pulled all the hub's log holds.
func (*World) SettleOnline ¶
SettleOnline waits for a quiet point of the devices whose links are up, leaving cut links cut.
func (*World) Snapshot ¶
Snapshot returns a copy of device d's vault files, for AddDevice to join with later: an older copy of the vault.
func (*World) Status ¶
func (w *World) Status(d *Node) (api.SyncStatus, error)
Status returns device d's sync status.
func (*World) Token ¶
Token returns a new token for content a script writes. It counts as written once a write that holds it succeeds.
func (*World) Write ¶
Write makes the note at p on device d hold content, through notesd: a write with the base it reads first, or a create when there is no note at p.
func (*World) WriteDisk ¶
WriteDisk writes content at p on device d's disk, as another program would, and has notesd index it.