-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from azr/release_failed_flock
Release failed flock
- Loading branch information
Showing
4 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package flock | ||
|
||
import ( | ||
"io/ioutil" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func Test(t *testing.T) { | ||
tmpFileFh, err := ioutil.TempFile(os.TempDir(), "go-flock-") | ||
tmpFileFh.Close() | ||
tmpFile := tmpFileFh.Name() | ||
os.Remove(tmpFile) | ||
|
||
lock := New(tmpFile) | ||
locked, err := lock.TryLock() | ||
if locked == false || err != nil { | ||
t.Fatalf("failed to lock: locked: %t, err: %v", locked, err) | ||
} | ||
|
||
newLock := New(tmpFile) | ||
locked, err = newLock.TryLock() | ||
if locked != false || err != nil { | ||
t.Fatalf("should have failed locking: locked: %t, err: %v", locked, err) | ||
} | ||
|
||
if newLock.fh != nil { | ||
t.Fatal("file handle should have been released and be nil") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters