1// Copyright 2015 Keybase, Inc. All rights reserved. Use of
2// this source code is governed by the included BSD license.
3
4package libkb
5
6import (
7	"os"
8	"path/filepath"
9	"testing"
10)
11
12func TestLockPIDFile(t *testing.T) {
13	name := filepath.Join(os.TempDir(), "TestLockPID")
14	g := MakeThinGlobalContextForTesting(t)
15	lock := NewLockPIDFile(g, name)
16	var err error
17	if err = lock.Lock(); err != nil {
18		t.Fatalf("LockPIDFile failed for %q: %v", name, err)
19	}
20	defer lock.Close()
21
22	lock2 := NewLockPIDFile(g, name)
23	if err = lock2.Lock(); err == nil {
24		t.Fatalf("Second LockPIDFile call succeeded.  It should have failed.")
25	}
26}
27