github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/libkb/flock_test.go (about)

     1  // Copyright 2015 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package libkb
     5  
     6  import (
     7  	"os"
     8  	"path/filepath"
     9  	"testing"
    10  )
    11  
    12  func 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  }