mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 06:23:17 -10:00
Lock waits: - Tests record the label of each lock's wait that had none, the lock held as by another devvm and the wait ended by a cancel, a deadline failing one that shows nothing rather than hanging: git_lock_waiting (TestGitLockWaits; .git protection's Serial is gitSerial, so a test can reach it), packages_waiting and rebuilds_waiting (TestImageLocksWait), ubuntu_pin_waiting (TestPinOriginWaits), custom_secrets_waiting (TestYoursLockWaits) and forwarder_waiting (TestForwardsLockWaits). - A test build's locks panic on a nil platform.Waiting (platform.CheckWaiting, which the root's run calls in every test build beside state.CheckLockOrder), so the CLI tests and e2e catch a nil wait the structure test can't see, such as a zero agentlogin.File's; a msg.Waiting given a nil status shows nothing and stays review only. msg.Waiting with no status gives a wait that shows nothing, never nil; platform.NoWait is the Waiting of a lock that never waits (the build port's record, which passed nil), and the status-lines rule holds it to statusSites as it does nil (TestCheckWaiting, TestWaiting, the rule's NoWait case). - forbidigo refuses syscall.Flock and unix.Flock outside internal/platform, internal/proxy/rotate.go, the stubs and tests (testdata/lint, both). - TestLockFileWaiting runs in a synctest bubble and checks the wait shows while held, not before (its counters under a mutex, which the race detector needs, as only the file's lock orders them). Status lines: - TestCommandStatusLines runs the setters too: devvm ports LIST and ports add, size --cpus, network open, allowlist, transparent off and on, learn and allow, git-protect off and on, ssh-agent off. It found devvm ports on a running VM starting its forwarder again (ssh and a command in the VM) with no status line; that step now shows ports_restarting. The folder named twice: - vm_folder_unreadable's why was the open's error, the folder's path in it; folderUnreadable gives the system's reason alone when the error is about the folder itself (TestUnreadableFolder checks the whole message). - platform.OpenNoLinks and StatFolder return a link on the path as an fs.PathError about the folder too (ErrLinkOnPath still matches), so that case names it once as well (TestStatFolderUnique). Docs: Contributing's CLI page (status lines) and structure page, the codebase-standards guards; CHANGELOG (devvm ports' status line). Co-Authored-By: Claude Opus 5.5 <[email protected]>
39 lines
1.8 KiB
Go
39 lines
1.8 KiB
Go
package platform
|
|
|
|
import "sync/atomic"
|
|
|
|
// Waiting is what a wait for a lock shows (LockFile, LockFileShared,
|
|
// LockDir): it's called once, when another process holds the lock, never
|
|
// when it's free, and the func it returns once the wait ends, with the
|
|
// lock got or not. Each caller with a terminal passes a status line of
|
|
// its own, a label that says what it waits for (msg.Waiting), so a
|
|
// terminal never looks hung while devvm waits for another devvm. A
|
|
// process with no terminal passes a Waiting all the same, whose status
|
|
// line draws nothing. NoWait shows nothing, only for a lock that never
|
|
// waits, such as one on a file just made, and the structure test's
|
|
// status-lines rule holds it, and nil, to its list; a test build panics
|
|
// on nil (CheckWaiting).
|
|
type Waiting func() (end func())
|
|
|
|
// NoWait is the Waiting of a lock that never waits, such as one on a file
|
|
// just made, which no other process has: it shows nothing.
|
|
func NoWait() (end func()) { return func() {} }
|
|
|
|
// waitingChecked is whether a lock taken with a nil Waiting panics
|
|
// (CheckWaiting).
|
|
var waitingChecked atomic.Bool
|
|
|
|
// CheckWaiting makes every lock this process takes from then on panic on
|
|
// a nil Waiting, which would show nothing while another devvm holds the
|
|
// lock: test builds' runs do (internal/cli's Overrides), so the CLI tests
|
|
// and the end-to-end tests catch one that the structure test's
|
|
// status-lines rule can't see, such as a zero agentlogin.File's.
|
|
func CheckWaiting() { waitingChecked.Store(true) }
|
|
|
|
// checkWaiting panics on a nil waiting once CheckWaiting was called.
|
|
func checkWaiting(waiting Waiting) {
|
|
if waiting == nil && waitingChecked.Load() {
|
|
panic("platform: a lock's Waiting is nil, so its wait would show nothing: pass msg.Waiting's, or NoWait for a lock that never waits")
|
|
}
|
|
}
|