devlock

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 10 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 devlock gives one tb process at a time a device: an Android device or emulator, or an iOS simulator. Two runners on one device replace each other's on-device agent and drive the same screen: both fail in confusing ways. So every tb process that drives a device (`tb test` for the devices its run uses, the daemon for a `tb open` / `tb do` session) holds the device's lock, and a second one is told who has it instead of going ahead.

A lock is an flock(2) (LockFileEx on Windows) on a file per device in a machine-wide folder (~/.testbuddy/locks, or TB_LOCK_DIR): the system drops it when the holding process exits, however it exits, so a crashed or killed run never leaves a device locked. The file also holds who locked it (the command, pid, folder, start time), shown to whoever finds the device taken. Browsers need no lock: each run starts its own.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir() string

Dir is where the lock files are.

func Disabled

func Disabled() bool

Disabled: TB_NO_DEVICE_LOCK=1 turns locking off (every lock is granted, holding nothing).

Types

type Busy

type Busy struct {
	Serial string
	Owner  Owner
}

Busy is the error for a device another process holds.

func IsBusy

func IsBusy(err error) (*Busy, bool)

IsBusy reports whether err is (or wraps) a Busy.

func (*Busy) Error

func (e *Busy) Error() string

type Lock

type Lock struct {
	Serial string
	// contains filtered or unexported fields
}

Lock is a held device lock.

func Acquire

func Acquire(serial, what string, wait time.Duration) (*Lock, error)

Acquire takes the device's lock, waiting up to wait for its holder to let go (0: not at all). It checks again every poll: a lock held by another process sends no event when it goes.

func TryAcquire

func TryAcquire(serial, what string) (*Lock, error)

TryAcquire takes the device's lock at once, or returns a *Busy naming who holds it.

func (*Lock) Release

func (l *Lock) Release()

Release frees the device (also done by the system when the process exits).

type Owner

type Owner struct {
	PID     int       `json:"pid"`
	What    string    `json:"what"` // e.g. "tb test flows/login.yaml", "tb session alice"
	Dir     string    `json:"dir,omitempty"`
	Since   time.Time `json:"since"`
	Command string    `json:"command,omitempty"` // the holder's full command line
}

Owner says who holds a device.

func Holder

func Holder(serial string) Owner

Holder reads who holds (or last held) a device's lock. Only meaningful when TryAcquire just failed: a released lock's file keeps its last owner.

func (Owner) String

func (o Owner) String() string

Jump to

Keyboard shortcuts

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