fakeinotify

package
v1.9.21 Latest Latest
Warning

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

Go to latest
Published: May 20, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package fakeinotify provides a controllable filesystem event source for tests that exercise hook-status-watcher overflow / fallback paths (TEST-PLAN.md J2 regression, TUI-TEST-PLAN.md §6.2 fakeInotify).

The harness exposes an EventSource interface mirroring the subset of *fsnotify.Watcher production code consumes (Events / Errors / Close). Production refactor — injecting the source into StatusFileWatcher — is a prerequisite for Phase 1 watcher tests but lives outside this PR.

Usage:

f := fakeinotify.New(t)
defer f.Close()
f.Publish("/h/abc.json", fsnotify.Create)
f.SimulateOverflow(100) // kernel queue overflow
// Wire f as the EventSource for StatusFileWatcher under test.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventSource

type EventSource interface {
	Events() <-chan fsnotify.Event
	Errors() <-chan error
	Close() error
}

EventSource is the seam that production code (e.g. StatusFileWatcher) should depend on instead of *fsnotify.Watcher. Both Fake and a thin adapter around *fsnotify.Watcher satisfy it.

type Fake

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

Fake is a controllable EventSource. Concurrent Publish / DropAfter / Close are safe.

func New

func New(t *testing.T) *Fake

New returns a fresh Fake with reasonable channel buffers (256 events, 16 errors). The test's t handle is retained for cleanup registration.

func (*Fake) Close

func (f *Fake) Close() error

Close shuts down both channels. Idempotent.

func (*Fake) DropAfter

func (f *Fake) DropAfter(n int)

DropAfter sets the maximum number of subsequent Publish calls that will reach the Events channel; further Publish calls become drops. Pass -1 to disable the cap. Pass 0 to drop everything from now on.

func (*Fake) Dropped

func (f *Fake) Dropped() int

Dropped returns the cumulative number of events that were not delivered (either because of DropAfter or buffer exhaustion).

func (*Fake) Errors

func (f *Fake) Errors() <-chan error

Errors returns the channel a watcher under test should read errors from.

func (*Fake) Events

func (f *Fake) Events() <-chan fsnotify.Event

Events returns the channel a watcher under test should read from.

func (*Fake) Publish

func (f *Fake) Publish(name string, op fsnotify.Op)

Publish delivers a synthetic event. Events past DropAfter's threshold are silently dropped and counted (see Dropped).

func (*Fake) PublishError

func (f *Fake) PublishError(err error)

PublishError delivers a synthetic error to the Errors channel.

func (*Fake) SimulateOverflow

func (f *Fake) SimulateOverflow(n int)

SimulateOverflow models the kernel inotify-queue overflow scenario: it counts n events as dropped and emits a single fsnotify.ErrEventOverflow on the Errors channel — matching what fsnotify itself surfaces when the kernel reports IN_Q_OVERFLOW.

Tests assert that the watcher activates its disk-poll fallback after observing this signal (J2 regression).

Jump to

Keyboard shortcuts

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