Skip to content

Commit d5bb33e

Browse files
committed
additional lock file test
1 parent 629ea06 commit d5bb33e

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

internal/stack/lock.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ func (e *LockError) Unwrap() error { return e.Err }
2121

2222
// LockTimeout is how long Lock() will wait for the exclusive lock before
2323
// giving up. With the lock held only during file writes (milliseconds),
24-
// this timeout primarily guards against stuck or orphaned lock files.
24+
// this timeout primarily guards against a hung process holding the lock.
2525
const LockTimeout = 5 * time.Second
2626

2727
// lockRetryInterval is the sleep between non-blocking lock attempts.
2828
const lockRetryInterval = 100 * time.Millisecond
2929

3030
// FileLock provides an exclusive advisory lock on the stack file to prevent
31-
// concurrent Load-Modify-Save races between multiple gh-stack processes.
31+
// concurrent writes between multiple gh-stack processes.
3232
type FileLock struct {
3333
f *os.File
3434
}

internal/stack/lock_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package stack
22

33
import (
44
"fmt"
5+
"os"
6+
"path/filepath"
57
"sync"
68
"testing"
79
"time"
@@ -123,6 +125,9 @@ func TestLock_FileLeftOnDisk(t *testing.T) {
123125
lock.Unlock()
124126

125127
// Lock file should still exist after unlock (no os.Remove race).
128+
_, err = os.Stat(filepath.Join(dir, lockFileName))
129+
require.NoError(t, err, "lock file should remain on disk after unlock")
130+
126131
lock2, err := Lock(dir)
127132
require.NoError(t, err, "should be able to re-lock after unlock")
128133
lock2.Unlock()

0 commit comments

Comments
 (0)