consul/state: fix for maxIndex and better tests
This commit is contained in:
parent
b0ae1c0967
commit
0171c2ba3d
|
@ -63,9 +63,8 @@ func (s *StateStore) maxIndex(tables ...string) uint64 {
|
|||
if err != nil {
|
||||
panic(fmt.Sprintf("unknown index: %s", table))
|
||||
}
|
||||
idx := ti.(*IndexEntry).Value
|
||||
if idx > lindex {
|
||||
lindex = idx
|
||||
if idx, ok := ti.(*IndexEntry); ok && idx.Value > lindex {
|
||||
lindex = idx.Value
|
||||
}
|
||||
}
|
||||
return lindex
|
||||
|
|
|
@ -1012,6 +1012,11 @@ func TestStateStore_KVSSetCAS(t *testing.T) {
|
|||
}
|
||||
tx.Abort()
|
||||
|
||||
// Index was not updated
|
||||
if idx := s.maxIndex("kvs"); idx != 0 {
|
||||
t.Fatalf("bad index: %d", idx)
|
||||
}
|
||||
|
||||
// Doing a CAS with a ModifyIndex of zero when no entry exists
|
||||
// performs the set and saves into the state store.
|
||||
entry = &structs.DirEntry{
|
||||
|
@ -1034,6 +1039,11 @@ func TestStateStore_KVSSetCAS(t *testing.T) {
|
|||
}
|
||||
tx.Abort()
|
||||
|
||||
// Index was updated
|
||||
if idx := s.maxIndex("kvs"); idx != 2 {
|
||||
t.Fatalf("bad index: %d", idx)
|
||||
}
|
||||
|
||||
// Doing a CAS with a ModifyIndex which does not match the current
|
||||
// index does not do anything.
|
||||
entry = &structs.DirEntry{
|
||||
|
@ -1060,4 +1070,9 @@ func TestStateStore_KVSSetCAS(t *testing.T) {
|
|||
result.ModifyIndex != 2 || string(result.Value) != "foo" {
|
||||
t.Fatalf("bad: %#v", result)
|
||||
}
|
||||
|
||||
// Index was not modified
|
||||
if idx := s.maxIndex("kvs"); idx != 2 {
|
||||
t.Fatalf("bad index: %d", idx)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue