diff options
Diffstat (limited to 'internal/lock/lock_test.go')
| -rw-r--r-- | internal/lock/lock_test.go | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/internal/lock/lock_test.go b/internal/lock/lock_test.go index fca4d76..53ce5ca 100644 --- a/internal/lock/lock_test.go +++ b/internal/lock/lock_test.go @@ -122,3 +122,16 @@ func TestStaleLockIsTakenOver(t *testing.T) { t.Error("the takeover was not reported to the caller") } } + +// TestRunningRejectsPidsBeyondTheKernelsRange: a pid wider than 32 bits in a +// damaged lock file is cut to its low bits by kill(2), so without a range +// check it names some other process - here this very one - and a stale lock +// would never be taken over. +func TestRunningRejectsPidsBeyondTheKernelsRange(t *testing.T) { + if running(os.Getpid() + 1<<32) { + t.Error("running(pid + 2^32) is true: the pid was truncated to this process") + } + if !running(os.Getpid()) { + t.Error("running(own pid) is false") + } +} |
