Fix flaky test `TestHTTPTimeout` caused by precision problem.
Signed-off-by: Zhang Wei <zhangwei555@huawei.com>
| ... | ... |
@@ -47,14 +47,14 @@ func testHTTPTimeout(t *testing.T, timeout, epsilon time.Duration) {
|
| 47 | 47 |
t.Fatalf("The request should be canceled %v", err)
|
| 48 | 48 |
} |
| 49 | 49 |
elapsed := time.Now().Sub(begin) |
| 50 |
- if elapsed < timeout || elapsed > timeout+epsilon {
|
|
| 50 |
+ if elapsed < timeout-epsilon || elapsed > timeout+epsilon {
|
|
| 51 | 51 |
t.Fatalf("elapsed time: got %v, expected %v (epsilon=%v)",
|
| 52 | 52 |
elapsed, timeout, epsilon) |
| 53 | 53 |
} |
| 54 | 54 |
} |
| 55 | 55 |
|
| 56 | 56 |
func TestHTTPTimeout(t *testing.T) {
|
| 57 |
- testHTTPTimeout(t, 5*time.Second, 1*time.Second) |
|
| 57 |
+ testHTTPTimeout(t, 5*time.Second, 500*time.Millisecond) |
|
| 58 | 58 |
} |
| 59 | 59 |
|
| 60 | 60 |
func TestFailedConnection(t *testing.T) {
|