浏览代码

queries will only be attempted once if there is only 1 host available

Chris Bannister 9 年之前
父节点
当前提交
f011beaa02
共有 2 个文件被更改,包括 14 次插入2 次删除
  1. 2 2
      conn_test.go
  2. 12 0
      policies_test.go

+ 2 - 2
conn_test.go

@@ -187,8 +187,8 @@ func TestQueryRetry(t *testing.T) {
 		t.Fatalf("expected requests %v to match query attemps %v", requests, attempts)
 	}
 
-	//Minus 1 from the requests variable since there is the initial query attempt
-	if requests-1 != int64(rt.NumRetries) {
+	// the query will only be attempted once, but is being retried
+	if requests != int64(rt.NumRetries) {
 		t.Fatalf("failed to retry the query %v time(s). Query executed %v times", rt.NumRetries, requests-1)
 	}
 }

+ 12 - 0
policies_test.go

@@ -241,3 +241,15 @@ func TestCOWList_Add(t *testing.T) {
 		}
 	}
 }
+
+func TestSimpleRetryPolicy(t *testing.T) {
+	q := &Query{}
+	rt := &SimpleRetryPolicy{NumRetries: 2}
+	if !rt.Attempt(q) {
+		t.Fatal("should allow retry after 0 attempts")
+	}
+	q.attempts = 5
+	if rt.Attempt(q) {
+		t.Fatal("should not allow retry after passing threshold")
+	}
+}