mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #1131 from bcwaldon/1129
etcdserver: init time.Time only if Expiration > 0
This commit is contained in:
commit
ceab948831
@ -241,12 +241,20 @@ func (s *EtcdServer) sync(timeout time.Duration) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getExpirationTime(r *pb.Request) time.Time {
|
||||||
|
var t time.Time
|
||||||
|
if r.Expiration != 0 {
|
||||||
|
t = time.Unix(0, r.Expiration)
|
||||||
|
}
|
||||||
|
return t
|
||||||
|
}
|
||||||
|
|
||||||
// apply interprets r as a call to store.X and returns an Response interpreted from store.Event
|
// apply interprets r as a call to store.X and returns an Response interpreted from store.Event
|
||||||
func (s *EtcdServer) apply(r pb.Request) Response {
|
func (s *EtcdServer) apply(r pb.Request) Response {
|
||||||
f := func(ev *store.Event, err error) Response {
|
f := func(ev *store.Event, err error) Response {
|
||||||
return Response{Event: ev, err: err}
|
return Response{Event: ev, err: err}
|
||||||
}
|
}
|
||||||
expr := time.Unix(0, r.Expiration)
|
expr := getExpirationTime(&r)
|
||||||
switch r.Method {
|
switch r.Method {
|
||||||
case "POST":
|
case "POST":
|
||||||
return f(s.Store.Create(r.Path, r.Dir, r.Val, true, expr))
|
return f(s.Store.Create(r.Path, r.Dir, r.Val, true, expr))
|
||||||
|
@ -16,6 +16,33 @@ import (
|
|||||||
"github.com/coreos/etcd/third_party/code.google.com/p/go.net/context"
|
"github.com/coreos/etcd/third_party/code.google.com/p/go.net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestGetExpirationTime(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
r pb.Request
|
||||||
|
want time.Time
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
pb.Request{Expiration: 0},
|
||||||
|
time.Time{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pb.Request{Expiration: 60000},
|
||||||
|
time.Unix(0, 60000),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pb.Request{Expiration: -60000},
|
||||||
|
time.Unix(0, -60000),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, tt := range tests {
|
||||||
|
got := getExpirationTime(&tt.r)
|
||||||
|
if !reflect.DeepEqual(tt.want, got) {
|
||||||
|
t.Errorf("#%d: incorrect expiration time: want=%v got=%v", i, tt.want, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestDoLocalAction tests requests which do not need to go through raft to be applied,
|
// TestDoLocalAction tests requests which do not need to go through raft to be applied,
|
||||||
// and are served through local data.
|
// and are served through local data.
|
||||||
func TestDoLocalAction(t *testing.T) {
|
func TestDoLocalAction(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user