Browse Source

Merge pull request #6298 from sinsharat/master

store: added missing test case scenerio for scan of de-queued entries
Xiang Li 9 years ago
parent
commit
f4c30425c0
1 changed files with 25 additions and 1 deletions
  1. 25 1
      store/event_test.go

+ 25 - 1
store/event_test.go

@@ -14,7 +14,11 @@
 
 package store
 
-import "testing"
+import (
+	"testing"
+
+	etcdErr "github.com/coreos/etcd/error"
+)
 
 // TestEventQueue tests a queue with capacity = 100
 // Add 200 events into that queue, and test if the
@@ -86,6 +90,26 @@ func TestScanHistory(t *testing.T) {
 	}
 }
 
+func TestEventIndexHistoryCleared(t *testing.T) {
+	eh := newEventHistory(5)
+
+	// Add
+	eh.addEvent(newEvent(Create, "/foo", 1, 1))
+	eh.addEvent(newEvent(Create, "/foo/bar", 2, 2))
+	eh.addEvent(newEvent(Create, "/foo/foo", 3, 3))
+	eh.addEvent(newEvent(Create, "/foo/bar/bar", 4, 4))
+	eh.addEvent(newEvent(Create, "/foo/foo/foo", 5, 5))
+
+	// Add a new event which will replace/de-queue the first entry
+	eh.addEvent(newEvent(Create, "/foo/bar/bar/bar", 6, 6))
+
+	// test for the event which has been replaced.
+	_, err := eh.scan("/foo", false, 1)
+	if err == nil || err.ErrorCode != etcdErr.EcodeEventIndexCleared {
+		t.Fatalf("scan error cleared index should return err with %d got (%v)", etcdErr.EcodeEventIndexCleared, err)
+	}
+}
+
 // TestFullEventQueue tests a queue with capacity = 10
 // Add 1000 events into that queue, and test if scanning
 // works still for previous events.