mirror of
https://github.com/cloudflare/cloudflared.git
synced 2026-08-07 07:14:57 +00:00
Revert "TUN-10621: Propagate max wait timeout"
This reverts merge request !1859
This commit is contained in:
committed by
João "Pisco" Fernandes
parent
86fccede6d
commit
43bfec0bcd
+5
-45
@@ -30,8 +30,8 @@ func TestPipeBidirectionalFinishOneSideTimeout(t *testing.T) {
|
||||
|
||||
func TestPipeBidirectionalClosingWriteBothSidesAlsoExists(t *testing.T) {
|
||||
fun := func(upstream, downstream *mockedStream) {
|
||||
_ = downstream.CloseWrite()
|
||||
_ = upstream.CloseWrite()
|
||||
downstream.CloseWrite()
|
||||
upstream.CloseWrite()
|
||||
|
||||
downstream.writeToReader("abc")
|
||||
upstream.writeToReader("abc")
|
||||
@@ -42,7 +42,7 @@ func TestPipeBidirectionalClosingWriteBothSidesAlsoExists(t *testing.T) {
|
||||
|
||||
func TestPipeBidirectionalClosingWriteSingleSideAlsoExists(t *testing.T) {
|
||||
fun := func(upstream, downstream *mockedStream) {
|
||||
_ = downstream.CloseWrite()
|
||||
downstream.CloseWrite()
|
||||
|
||||
downstream.writeToReader("abc")
|
||||
upstream.writeToReader("abc")
|
||||
@@ -51,46 +51,6 @@ func TestPipeBidirectionalClosingWriteSingleSideAlsoExists(t *testing.T) {
|
||||
testPipeBidirectionalUnblocking(t, fun, time.Millisecond*200, true)
|
||||
}
|
||||
|
||||
// TestPipeBidirectionalReturnsWhenBothSidesFinish verifies that
|
||||
// PipeBidirectional returns as soon as both stream directions finish, without
|
||||
// waiting for the full timeout grace period to expire. This guards against a
|
||||
// regression where the second-stream wait would block for the whole timeout
|
||||
// even when the result is already available.
|
||||
func TestPipeBidirectionalReturnsWhenBothSidesFinish(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const (
|
||||
timeout = time.Second * 5
|
||||
maxWallTime = time.Millisecond * 500
|
||||
)
|
||||
|
||||
logger := zerolog.Nop()
|
||||
downstream := newMockedStream()
|
||||
upstream := newMockedStream()
|
||||
|
||||
resultCh := make(chan error, 1)
|
||||
go func() {
|
||||
resultCh <- PipeBidirectional(downstream, upstream, timeout, &logger)
|
||||
}()
|
||||
|
||||
// Close both reader sides so both stream directions reach EOF promptly.
|
||||
downstream.closeReader()
|
||||
upstream.closeReader()
|
||||
|
||||
start := time.Now()
|
||||
select {
|
||||
case err := <-resultCh:
|
||||
elapsed := time.Since(start)
|
||||
require.NoError(t, err)
|
||||
require.Less(t, elapsed, maxWallTime,
|
||||
"PipeBidirectional should return as soon as both streams finish, not after the full %s timeout (took %s)",
|
||||
timeout, elapsed,
|
||||
)
|
||||
case <-time.After(timeout):
|
||||
require.Fail(t, "PipeBidirectional did not return before the timeout expired")
|
||||
}
|
||||
}
|
||||
|
||||
func testPipeBidirectionalUnblocking(t *testing.T, afterFun func(*mockedStream, *mockedStream), timeout time.Duration, expectTimeout bool) {
|
||||
logger := zerolog.Nop()
|
||||
|
||||
@@ -107,9 +67,9 @@ func testPipeBidirectionalUnblocking(t *testing.T, afterFun func(*mockedStream,
|
||||
select {
|
||||
case err := <-resultCh:
|
||||
if expectTimeout {
|
||||
require.Error(t, err)
|
||||
require.NotNil(t, err)
|
||||
} else {
|
||||
require.NoError(t, err)
|
||||
require.Nil(t, err)
|
||||
}
|
||||
|
||||
case <-time.After(timeout * 2):
|
||||
|
||||
Reference in New Issue
Block a user