[ARVADOS] updated: cca1529c082c2111636f9ae60601f22afdfe73ae

git at public.curoverse.com git at public.curoverse.com
Mon Aug 25 10:42:57 EDT 2014


Summary of changes:
 services/keepstore/keepstore_test.go   |  9 +++++----
 services/keepstore/volume.go           | 26 +++++++++++++++++++-------
 services/keepstore/volume_unix_test.go |  4 ++++
 3 files changed, 28 insertions(+), 11 deletions(-)

       via  cca1529c082c2111636f9ae60601f22afdfe73ae (commit)
      from  c15f086483884fb21d04ceac0ea8bd96308051bd (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit cca1529c082c2111636f9ae60601f22afdfe73ae
Author: Tim Pierce <twp at curoverse.com>
Date:   Mon Aug 25 10:40:28 2014 -0400

    3448: update tests with "untouchable" volumes
    
    Added a "Touchable" flag to MockVolume, so that we can test that
    PutBlock does the right thing when Touch fails.  Previous code was using
    volume.Bad as an attempt to test this, but that short-circuited the Put
    request before it ever attempted to call Touch.
    
    Added TODOs with more testing improvements we can make as time permits.

diff --git a/services/keepstore/keepstore_test.go b/services/keepstore/keepstore_test.go
index 2b7e411..686f502 100644
--- a/services/keepstore/keepstore_test.go
+++ b/services/keepstore/keepstore_test.go
@@ -266,12 +266,13 @@ func TestPutBlockTouchFails(t *testing.T) {
 		t.Fatalf("vols[0].Mtime(%s): %s\n", TEST_HASH, err)
 	}
 
-	// Mark the volume bad and call PutBlock.
-	vols[0].(*MockVolume).Bad = true
+	// vols[0].Touch will fail on the next call, so the volume
+	// manager will store a copy on vols[1] instead.
+	vols[0].(*MockVolume).Touchable = false
 	if err := PutBlock(TEST_BLOCK, TEST_HASH); err != nil {
 		t.Fatalf("PutBlock: %v", err)
 	}
-	vols[0].(*MockVolume).Bad = false
+	vols[0].(*MockVolume).Touchable = true
 
 	// Now the mtime on the block on vols[0] should be unchanged, and
 	// there should be a copy of the block on vols[1].
@@ -280,7 +281,7 @@ func TestPutBlockTouchFails(t *testing.T) {
 		t.Fatalf("vols[0].Mtime(%s): %s\n", TEST_HASH, err)
 	}
 	if !new_mtime.Equal(old_mtime) {
-		t.Errorf("bad block mtimes do not match:\nold_mtime = %v\nnew_mtime = %v\n",
+		t.Errorf("mtime was changed on vols[0]:\nold_mtime = %v\nnew_mtime = %v\n",
 			old_mtime, new_mtime)
 	}
 	result, err := vols[1].Get(TEST_HASH)
diff --git a/services/keepstore/volume.go b/services/keepstore/volume.go
index 6fb1a1e..e7683ee 100644
--- a/services/keepstore/volume.go
+++ b/services/keepstore/volume.go
@@ -28,17 +28,29 @@ type Volume interface {
 // If the Bad field is true, this volume should return an error
 // on all writes and puts.
 //
+// The Touchable field signifies whether the Touch method will
+// succeed.  Defaults to true.  Note that Bad and Touchable are
+// independent: a MockVolume may be set up so that Put fails but Touch
+// works or vice versa.
+//
+// TODO(twp): rename Bad to something more descriptive, e.g. Writable,
+// and make sure that the tests that rely on it are testing the right
+// thing.  We may need to simulate Writable, Touchable and Corrupt
+// volumes in different ways.
+//
 type MockVolume struct {
 	Store      map[string][]byte
 	Timestamps map[string]time.Time
 	Bad        bool
+	Touchable  bool
 }
 
 func CreateMockVolume() *MockVolume {
 	return &MockVolume{
-		make(map[string][]byte),
-		make(map[string]time.Time),
-		false,
+		Store:      make(map[string][]byte),
+		Timestamps: make(map[string]time.Time),
+		Bad:        false,
+		Touchable:  true,
 	}
 }
 
@@ -60,11 +72,11 @@ func (v *MockVolume) Put(loc string, block []byte) error {
 }
 
 func (v *MockVolume) Touch(loc string) error {
-	if v.Bad {
-		return errors.New("Bad volume")
+	if v.Touchable {
+		v.Timestamps[loc] = time.Now()
+		return nil
 	}
-	v.Timestamps[loc] = time.Now()
-	return nil
+	return errors.New("Touch failed")
 }
 
 func (v *MockVolume) Mtime(loc string) (time.Time, error) {
diff --git a/services/keepstore/volume_unix_test.go b/services/keepstore/volume_unix_test.go
index 7a1c06c..d6aeac6 100644
--- a/services/keepstore/volume_unix_test.go
+++ b/services/keepstore/volume_unix_test.go
@@ -119,7 +119,11 @@ func TestPutTouch(t *testing.T) {
 	}
 	// Sleep for 1s, then put the block again.  The volume
 	// should report a more recent mtime.
+	//
 	// TODO(twp): this would be better handled with a mock Time object.
+	// Alternatively, set the mtime manually to some moment in the past
+	// (maybe a v.SetMtime method?)
+	//
 	time.Sleep(time.Second)
 	if err := v.Put(TEST_HASH, TEST_BLOCK); err != nil {
 		t.Error(err)

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list