Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(929)

Unified Diff: mmutex/cmd/mmutex/exclusive_test.go

Issue 2990863002: Implement the 'shared' subcommand for mmutex (Closed)
Patch Set: Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mmutex/cmd/mmutex/exclusive.go ('k') | mmutex/cmd/mmutex/main.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mmutex/cmd/mmutex/exclusive_test.go
diff --git a/mmutex/cmd/mmutex/exclusive_test.go b/mmutex/cmd/mmutex/exclusive_test.go
index f32e68004cd68d113e3175b646cef2f5b5b4f02f..8f129d1e26cfb6322aae32a7c3cc07b5cdf2edc8 100644
--- a/mmutex/cmd/mmutex/exclusive_test.go
+++ b/mmutex/cmd/mmutex/exclusive_test.go
@@ -28,8 +28,8 @@ import (
. "github.com/luci/luci-go/common/testing/assertions"
)
-func TestMain(t *testing.T) {
- Convey("RunExclusive executes the command", t, func(c C) {
+func TestExclusive(t *testing.T) {
+ Convey("RunExclusive executes the command", t, func() {
var tempDir string
var err error
@@ -41,9 +41,9 @@ func TestMain(t *testing.T) {
testFilePath := filepath.Join(tempDir, "test")
var command []string
if runtime.GOOS == "windows" {
- command = []string{"cmd", "/c", "copy", "NUL", testFilePath}
+ command = createCommand([]string{"copy", "NUL", testFilePath})
} else {
- command = []string{"touch", testFilePath}
+ command = createCommand([]string{"touch", testFilePath})
}
So(RunExclusive(command, 0, 0), ShouldBeNil)
@@ -52,11 +52,11 @@ func TestMain(t *testing.T) {
So(err, ShouldBeNil)
})
- Convey("RunExclusive returns error from the command", t, func(c C) {
+ Convey("RunExclusive returns error from the command", t, func() {
So(RunExclusive([]string{"nonexistent_command"}, 0, 0), ShouldErrLike, "executable file not found")
})
- Convey("RunExclusive times out if lock isn't released", t, func(c C) {
+ Convey("RunExclusive times out if exclusive lock isn't released", t, func() {
var handle fslock.Handle
var err error
@@ -68,7 +68,19 @@ func TestMain(t *testing.T) {
So(RunExclusive([]string{"echo", "should_fail"}, 0, 0), ShouldErrLike, "fslock: lock is held")
})
- Convey("RunExclusive respects timeout", t, func(c C) {
+ Convey("RunExclusive times out if shared lock isn't released", t, func() {
+ var handle fslock.Handle
+ var err error
+
+ if handle, err = fslock.LockShared(LockFilePath); err != nil {
+ panic(err)
+ }
+ defer handle.Unlock()
+
+ So(RunExclusive(createCommand([]string{"echo", "should_fail"}), 0, 0), ShouldErrLike, "fslock: lock is held")
+ })
+
+ Convey("RunExclusive respects timeout", t, func() {
var handle fslock.Handle
var err error
@@ -78,7 +90,18 @@ func TestMain(t *testing.T) {
defer handle.Unlock()
start := time.Now()
- RunExclusive([]string{"echo", "should_fail"}, 5*time.Millisecond, 0)
+ RunExclusive(createCommand([]string{"echo", "should_succeed"}), 5*time.Millisecond, 0)
So(time.Now(), ShouldHappenOnOrAfter, start.Add(5*time.Millisecond))
})
+
+ // TODO(charliea): Add a test to ensure that a drain file is created when RunExclusive() is called.
+
+ // TODO(charliea): Add a test to ensure that RunExclusive() uses the $CHOPS_SERVICE_LOCK environment
+ // variable to determine the directory for the lock and drain files.
+
+ // TODO(charliea): Add a test to ensure that RunExclusive() just acts as a passthrough if
+ // the $CHOPS_SERVICE_LOCK directory isn't set.
+
+ // TODO(charliea): Add a test to ensure that RunExclusive() just acts as a passthrough if
+ // the $CHOPS_SERVICE_LOCK directory doesn't exist.
}
« no previous file with comments | « mmutex/cmd/mmutex/exclusive.go ('k') | mmutex/cmd/mmutex/main.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698