Merge pull request #123416 from pacoxu/fix-flaky-ut
fix flaky ut in TestCause contexthelper_test
This commit is contained in:
		@@ -47,13 +47,13 @@ func TestCause(t *testing.T) {
 | 
				
			|||||||
	}{
 | 
						}{
 | 
				
			||||||
		"nothing": {
 | 
							"nothing": {
 | 
				
			||||||
			parentCtx: context.Background(),
 | 
								parentCtx: context.Background(),
 | 
				
			||||||
			timeout:   5 * time.Millisecond,
 | 
								timeout:   10 * time.Millisecond,
 | 
				
			||||||
			sleep:     time.Millisecond,
 | 
								sleep:     time.Millisecond,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
		"timeout": {
 | 
							"timeout": {
 | 
				
			||||||
			parentCtx:   context.Background(),
 | 
								parentCtx:   context.Background(),
 | 
				
			||||||
			timeout:     time.Millisecond,
 | 
								timeout:     time.Millisecond,
 | 
				
			||||||
			sleep:       5 * time.Millisecond,
 | 
								sleep:       10 * time.Millisecond,
 | 
				
			||||||
			expectErr:   context.Canceled,
 | 
								expectErr:   context.Canceled,
 | 
				
			||||||
			expectCause: canceledError(timeoutCause),
 | 
								expectCause: canceledError(timeoutCause),
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
@@ -64,7 +64,7 @@ func TestCause(t *testing.T) {
 | 
				
			|||||||
				return ctx
 | 
									return ctx
 | 
				
			||||||
			}(),
 | 
								}(),
 | 
				
			||||||
			timeout:     time.Millisecond,
 | 
								timeout:     time.Millisecond,
 | 
				
			||||||
			sleep:       5 * time.Millisecond,
 | 
								sleep:       10 * time.Millisecond,
 | 
				
			||||||
			expectErr:   context.Canceled,
 | 
								expectErr:   context.Canceled,
 | 
				
			||||||
			expectCause: context.Canceled,
 | 
								expectCause: context.Canceled,
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
@@ -112,7 +112,7 @@ func TestCause(t *testing.T) {
 | 
				
			|||||||
			if tt.expectDeadline != 0 {
 | 
								if tt.expectDeadline != 0 {
 | 
				
			||||||
				actualDeadline, ok := ctx.Deadline()
 | 
									actualDeadline, ok := ctx.Deadline()
 | 
				
			||||||
				if assert.True(t, ok, "should have had a deadline") {
 | 
									if assert.True(t, ok, "should have had a deadline") {
 | 
				
			||||||
					assert.InDelta(t, time.Until(actualDeadline), tt.expectDeadline, float64(time.Second), "remaining time till Deadline()")
 | 
										assert.InDelta(t, time.Until(actualDeadline), tt.expectDeadline, float64(5*time.Second), "remaining time till Deadline()")
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			time.Sleep(tt.sleep)
 | 
								time.Sleep(tt.sleep)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user