Commit 2322f6fe authored by Juan Batiz-Benet's avatar Juan Batiz-Benet

dht/query: err return NotFound case

When some queries finished, but we got no result, it should
be a simple NotFoundError. Only when every single query ended
in error do we externalize those to the client, in case
something major is going wrong
parent 9d6207f8
......@@ -49,6 +49,10 @@ func TestGetFailures(t *testing.T) {
// u.POut("Timout Test\n")
ctx1, _ := context.WithTimeout(context.Background(), 200*time.Millisecond)
if _, err := d.GetValue(ctx1, u.Key("test")); err != nil {
if merr, ok := err.(u.MultiErr); ok && len(merr) > 0 {
err = merr[0]
}
if err != context.DeadlineExceeded {
t.Fatal("Got different error than we expected", err)
}
......@@ -86,6 +90,9 @@ func TestGetFailures(t *testing.T) {
ctx2, _ := context.WithTimeout(context.Background(), 20*time.Second)
_, err = d.GetValue(ctx2, u.Key("test"))
if err != nil {
if merr, ok := err.(u.MultiErr); ok && len(merr) > 0 {
err = merr[0]
}
if err != routing.ErrNotFound {
t.Fatalf("Expected ErrNotFound, got: %s", err)
}
......@@ -202,6 +209,9 @@ func TestNotFound(t *testing.T) {
v, err := d.GetValue(ctx, u.Key("hello"))
log.Debugf("get value got %v", v)
if err != nil {
if merr, ok := err.(u.MultiErr); ok && len(merr) > 0 {
err = merr[0]
}
switch err {
case routing.ErrNotFound:
//Success!
......
......@@ -62,7 +62,7 @@ type dhtQueryRunner struct {
peersRemaining todoctr.Counter // peersToQuery + currently processing
result *dhtQueryResult // query result
errs []error // result errors. maybe should be a map[peer.ID]error
errs u.MultiErr // result errors. maybe should be a map[peer.ID]error
rateLimit chan struct{} // processing semaphore
log eventlog.EventLogger
......@@ -122,8 +122,12 @@ func (r *dhtQueryRunner) Run(peers []peer.ID) (*dhtQueryResult, error) {
r.RLock()
defer r.RUnlock()
if len(r.errs) > 0 {
err = r.errs[0] // take the first?
err = routing.ErrNotFound
// if every query to every peer failed, something must be very wrong.
if len(r.errs) > 0 && len(r.errs) == r.peersSeen.Size() {
log.Debugf("query errs: %s", r.errs)
err = r.errs[0]
}
case <-r.cg.Closed():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment