Commit 48653614 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 9cd975ce
...@@ -49,6 +49,10 @@ func TestGetFailures(t *testing.T) { ...@@ -49,6 +49,10 @@ func TestGetFailures(t *testing.T) {
// u.POut("Timout Test\n") // u.POut("Timout Test\n")
ctx1, _ := context.WithTimeout(context.Background(), 200*time.Millisecond) ctx1, _ := context.WithTimeout(context.Background(), 200*time.Millisecond)
if _, err := d.GetValue(ctx1, u.Key("test")); err != nil { 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 { if err != context.DeadlineExceeded {
t.Fatal("Got different error than we expected", err) t.Fatal("Got different error than we expected", err)
} }
...@@ -86,6 +90,9 @@ func TestGetFailures(t *testing.T) { ...@@ -86,6 +90,9 @@ func TestGetFailures(t *testing.T) {
ctx2, _ := context.WithTimeout(context.Background(), 20*time.Second) ctx2, _ := context.WithTimeout(context.Background(), 20*time.Second)
_, err = d.GetValue(ctx2, u.Key("test")) _, err = d.GetValue(ctx2, u.Key("test"))
if err != nil { if err != nil {
if merr, ok := err.(u.MultiErr); ok && len(merr) > 0 {
err = merr[0]
}
if err != routing.ErrNotFound { if err != routing.ErrNotFound {
t.Fatalf("Expected ErrNotFound, got: %s", err) t.Fatalf("Expected ErrNotFound, got: %s", err)
} }
...@@ -202,6 +209,9 @@ func TestNotFound(t *testing.T) { ...@@ -202,6 +209,9 @@ func TestNotFound(t *testing.T) {
v, err := d.GetValue(ctx, u.Key("hello")) v, err := d.GetValue(ctx, u.Key("hello"))
log.Debugf("get value got %v", v) log.Debugf("get value got %v", v)
if err != nil { if err != nil {
if merr, ok := err.(u.MultiErr); ok && len(merr) > 0 {
err = merr[0]
}
switch err { switch err {
case routing.ErrNotFound: case routing.ErrNotFound:
//Success! //Success!
......
...@@ -62,7 +62,7 @@ type dhtQueryRunner struct { ...@@ -62,7 +62,7 @@ type dhtQueryRunner struct {
peersRemaining todoctr.Counter // peersToQuery + currently processing peersRemaining todoctr.Counter // peersToQuery + currently processing
result *dhtQueryResult // query result 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 rateLimit chan struct{} // processing semaphore
log eventlog.EventLogger log eventlog.EventLogger
...@@ -122,8 +122,12 @@ func (r *dhtQueryRunner) Run(peers []peer.ID) (*dhtQueryResult, error) { ...@@ -122,8 +122,12 @@ func (r *dhtQueryRunner) Run(peers []peer.ID) (*dhtQueryResult, error) {
r.RLock() r.RLock()
defer r.RUnlock() defer r.RUnlock()
if len(r.errs) > 0 { err = routing.ErrNotFound
err = r.errs[0] // take the first?
// 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(): 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