mirror of https://github.com/status-im/consul.git
submatview: fix a bug with Store.Get
When info.Timeout is 0, it should have no timeout. Previously it was using a 0 duration timeout which caused it to return without waiting. This bug was masked by using a timeout in the tests. Removing the timeout caused the tests to fail.
This commit is contained in:
parent
c5dc729dda
commit
59d201e148
|
@ -118,8 +118,11 @@ func (s *Store) Get(ctx context.Context, req Request) (Result, error) {
|
||||||
}
|
}
|
||||||
defer s.releaseEntry(key)
|
defer s.releaseEntry(key)
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(ctx, info.Timeout)
|
if info.Timeout > 0 {
|
||||||
|
var cancel context.CancelFunc
|
||||||
|
ctx, cancel = context.WithTimeout(ctx, info.Timeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
}
|
||||||
|
|
||||||
result, err := materializer.getFromView(ctx, info.MinIndex)
|
result, err := materializer.getFromView(ctx, info.MinIndex)
|
||||||
// context.DeadlineExceeded is translated to nil to match the timeout
|
// context.DeadlineExceeded is translated to nil to match the timeout
|
||||||
|
|
|
@ -160,7 +160,6 @@ func (r *fakeRequest) CacheInfo() cache.RequestInfo {
|
||||||
Key: key,
|
Key: key,
|
||||||
Token: "abcd",
|
Token: "abcd",
|
||||||
Datacenter: "dc1",
|
Datacenter: "dc1",
|
||||||
Timeout: 4 * time.Second,
|
|
||||||
MinIndex: r.index,
|
MinIndex: r.index,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue