| 1 | package agent |
| 2 | |
| 3 | import ( |
| 4 | "time" |
| 5 | |
| 6 | "reasonix/internal/store" |
| 7 | ) |
| 8 | |
| 9 | // SetSessionFileLockWaitForTest shortens the bounded cross-process save-lock |
| 10 | // wait so a test can drive the lock-held path without the full window. |
| 11 | // Restore with the returned function. Production must leave the defaults. |
| 12 | func SetSessionFileLockWaitForTest(wait, poll time.Duration) (restore func()) { |
| 13 | prevWait, prevPoll := sessionFileLockWait, sessionFileLockPollInterval |
| 14 | sessionFileLockWait, sessionFileLockPollInterval = wait, poll |
| 15 | return func() { |
| 16 | sessionFileLockWait, sessionFileLockPollInterval = prevWait, prevPoll |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | // HoldSessionFileLockForTest takes the session's compatibility save lock the |
| 21 | // way another process would, so saves in this process time out on it. |
| 22 | func HoldSessionFileLockForTest(path string) (release func(), err error) { |
| 23 | lock, err := tryTakeSessionLockFile(store.SessionLockFile(path)) |
| 24 | if err != nil { |
| 25 | return nil, err |
| 26 | } |
| 27 | return lock.Unlock, nil |
| 28 | } |
| 29 |