From 4f150b06e5d5417a56d089709c9462fb99b56d3b Mon Sep 17 00:00:00 2001 From: sharat Date: Tue, 30 Aug 2016 00:30:48 +0530 Subject: [PATCH] store: added missing test case scenerio for scan of de-queued entries Test case added to check err handing for replaced entries. #6255 --- store/event_test.go | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/store/event_test.go b/store/event_test.go index 073a162e6..ba3c06c66 100644 --- a/store/event_test.go +++ b/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.