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

Unified Diff: mmutex/cmd/mmutex/shared_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/shared.go ('k') | mmutex/cmd/mmutex/test_helpers.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mmutex/cmd/mmutex/shared_test.go
diff --git a/mmutex/cmd/mmutex/exclusive_test.go b/mmutex/cmd/mmutex/shared_test.go
similarity index 51%
copy from mmutex/cmd/mmutex/exclusive_test.go
copy to mmutex/cmd/mmutex/shared_test.go
index f32e68004cd68d113e3175b646cef2f5b5b4f02f..2ef0f828ac5b71a75c4b7934a823d54225d672bc 100644
--- a/mmutex/cmd/mmutex/exclusive_test.go
+++ b/mmutex/cmd/mmutex/shared_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 TestShared(t *testing.T) {
+ Convey("RunShared executes the command", t, func() {
var tempDir string
var err error
@@ -41,22 +41,22 @@ 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)
+ So(RunShared(command, 0, 0), ShouldBeNil)
_, err = os.Stat(testFilePath)
So(err, ShouldBeNil)
})
- Convey("RunExclusive returns error from the command", t, func(c C) {
- So(RunExclusive([]string{"nonexistent_command"}, 0, 0), ShouldErrLike, "executable file not found")
+ Convey("RunShared returns error from the command", t, func() {
+ So(RunShared([]string{"nonexistent_command"}, 0, 0), ShouldErrLike, "executable file not found")
})
- Convey("RunExclusive times out if lock isn't released", t, func(c C) {
+ Convey("RunShared times out if an exclusive lock isn't released", t, func() {
var handle fslock.Handle
var err error
@@ -65,20 +65,32 @@ func TestMain(t *testing.T) {
}
defer handle.Unlock()
- So(RunExclusive([]string{"echo", "should_fail"}, 0, 0), ShouldErrLike, "fslock: lock is held")
+ start := time.Now()
+ So(RunShared([]string{"echo", "should_fail"}, 5*time.Millisecond, 0), ShouldErrLike, "fslock: lock is held")
+ So(time.Now(), ShouldHappenOnOrAfter, start.Add(5*time.Millisecond))
})
- Convey("RunExclusive respects timeout", t, func(c C) {
+ Convey("RunShared executes the command if shared lock already held", t, func() {
var handle fslock.Handle
var err error
- if handle, err = fslock.Lock(LockFilePath); err != nil {
+ if handle, err = fslock.LockShared(LockFilePath); err != nil {
panic(err)
}
defer handle.Unlock()
- start := time.Now()
- RunExclusive([]string{"echo", "should_fail"}, 5*time.Millisecond, 0)
- So(time.Now(), ShouldHappenOnOrAfter, start.Add(5*time.Millisecond))
+ So(RunShared(createCommand([]string{"echo", "should_succeed"}), 0, 0), ShouldBeNil)
})
+
+ // TODO(charliea): Add a test to ensure that RunShared() treats the presence of a drain file the
+ // same as a held lock.
+
+ // TODO(charliea): Add a test to ensure that RunShared() 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 RunShared() just acts as a passthrough if
+ // the $CHOPS_SERVICE_LOCK directory isn't set.
+
+ // TODO(charliea): Add a test to ensure that RunShared() just acts as a passthrough if
+ // the $CHOPS_SERVICE_LOCK directory doesn't exist.
}
« no previous file with comments | « mmutex/cmd/mmutex/shared.go ('k') | mmutex/cmd/mmutex/test_helpers.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698