Documentation
¶
Overview ¶
Package changes is how tb waits for the screen to change: the one rule for what a device event says about the screen (News), and the wait between two reads of the screen that rests on it (Watch), with its silence safety net. The runner's waits (lookups, waits for an element to go) and the session's `tb watch` share it, so they keep that rule alike (issues #285, #288).
Index ¶
Constants ¶
const RestlessAfter = 400 * time.Millisecond
RestlessAfter: when the UI keeps changing without ever going quiet (a ticker, a countdown), a wait reads anyway after this long, then again at most this often.
Variables ¶
var ErrLost = errors.New("lost the connection to the device agent")
ErrLost: the device's events ended (its agent connection dropped).
Functions ¶
func News ¶
News: e reports a change after the read at seq, so the screen may differ from that read. It is the one test of what an event says about the screen. An event for seq or earlier says nothing new: the settle of a change already read (iOS's agent sends one once the change tb read goes quiet), one buffered before the read, one about something else. Only news proves the device is reporting the screen (issue #285).
func SilentAfter ¶
SilentAfter is the first gap of the silence safety net, for a device that does not report a change during a wait (an app whose changes the platform does not report; iOS's embedded Safari view, whose page is drawn by another process): after this long without news, the screen is read again (see Watch). 1.5 s; TB_SILENT_MS overrides, read once; 0 disables. It is the one place this setting lives: callers pass it to Subscribe.
Types ¶
type Watch ¶
type Watch struct {
// contains filtered or unexported fields
}
Watch is how a wait that re-reads the screen until it shows something waits between reads: it wakes the wait when the screen may differ from its last read, and it holds the wait's silence safety net. Every such wait goes through it, so they keep one rule: only news (see News) proves the device is reporting the screen. An event without news changes nothing here: it neither wakes the wait (a re-read would only find the screen already read) nor touches the net.
func Subscribe ¶
Subscribe starts watching src's events for one wait; Stop ends it. Subscribe before the first read, so no change after it is missed. silentAfter is the net's first gap (0: no net). With backoff (a lookup), the gap doubles once and stays at twice silentAfter while the device reports nothing; without, the screen is re-read every silentAfter throughout.
The cap (issue #96): uncapped, the gaps went 1.5, 3, 6, 12, 24 s, so on a screen that stays silent (iOS's embedded Safari view while its page loads: another process) a page that loaded 30 s into a 45 s wait was only read at the deadline. Capped, content is read at most 3 s after it appears, for one read every 3 s while the screen stays silent: a read takes 20 to 50 ms on an iOS simulator and 13 to 60 ms on an Android emulator (bench/results), and the next gap starts only once a read has ended, so even a slow read on a busy runner (4 s, issue #92) does not pile up. A screen that reports its changes never waits on this.
func (*Watch) Wait ¶
func (w *Watch) Wait(ctx context.Context, seq int64, deadline time.Time, early bool) (silent time.Duration, err error)
Wait blocks until the screen may differ from the read at seq, or the deadline. With early (a positive lookup's first wait), it returns on the first change; otherwise it waits for the change to settle, or RestlessAfter, so as not to take a snapshot for every frame. silent > 0 says that no news came for that long: the screen may have changed unreported, and the caller reads it afresh. It returns ErrLost when the device's events end, and the context's error when it ends.
The net is armed for the whole wait and is disarmed only by news, which also guarantees a wake (a "settled" at once, anything else within RestlessAfter): a wait can never be left with neither. Nor can events without news put the net off: it counts from the start of the wait, not from the last event, so a device that keeps repeating them (a settle, a change in a process in the background) cannot hold it off. A sliding window would: a device that repeats such events faster than the gap would hold the net off forever.