@@ -1783,149 +1783,6 @@ public async Task Http2_SendOverConnectionWindowSizeWithoutExplicitFlush_ClientS
17831783 }
17841784 }
17851785
1786- public static IEnumerable < object [ ] > KeepAliveTestDataSource ( )
1787- {
1788- yield return new object [ ] { Timeout . InfiniteTimeSpan , HttpKeepAlivePingPolicy . Always , false } ;
1789- yield return new object [ ] { TimeSpan . FromSeconds ( 1 ) , HttpKeepAlivePingPolicy . WithActiveRequests , false } ;
1790- yield return new object [ ] { TimeSpan . FromSeconds ( 1 ) , HttpKeepAlivePingPolicy . Always , false } ;
1791- yield return new object [ ] { TimeSpan . FromSeconds ( 1 ) , HttpKeepAlivePingPolicy . WithActiveRequests , true } ;
1792- }
1793-
1794- [ OuterLoop ( "Significant delay." ) ]
1795- [ MemberData ( nameof ( KeepAliveTestDataSource ) ) ]
1796- [ ConditionalTheory ( nameof ( SupportsAlpn ) ) ]
1797- [ ActiveIssue ( "https://github.com/dotnet/runtime/issues/41929" ) ]
1798- public void Http2_PingKeepAlive ( TimeSpan keepAlivePingDelay , HttpKeepAlivePingPolicy keepAlivePingPolicy , bool expectRequestFail )
1799- {
1800- RemoteExecutor . Invoke ( RunTest , keepAlivePingDelay . Ticks . ToString ( ) , keepAlivePingPolicy . ToString ( ) , expectRequestFail . ToString ( ) ) . Dispose ( ) ;
1801-
1802- static async Task RunTest ( string keepAlivePingDelayString , string keepAlivePingPolicyString , string expectRequestFailString )
1803- {
1804- // We should refactor this test so it can react to RTT PINGs.
1805- // For now, avoid interference by disabling them:
1806- AppContext . SetSwitch ( "System.Net.SocketsHttpHandler.Http2FlowControl.DisableDynamicWindowSizing" , true ) ;
1807-
1808- bool expectRequestFail = bool . Parse ( expectRequestFailString ) ;
1809- TimeSpan keepAlivePingDelay = TimeSpan . FromTicks ( long . Parse ( keepAlivePingDelayString ) ) ;
1810- HttpKeepAlivePingPolicy keepAlivePingPolicy = Enum . Parse < HttpKeepAlivePingPolicy > ( keepAlivePingPolicyString ) ;
1811-
1812- TimeSpan pingTimeout = TimeSpan . FromSeconds ( 5 ) ;
1813- // Simulate failure by delaying the pong, otherwise send it immediately.
1814- TimeSpan pongDelay = expectRequestFail ? pingTimeout * 2 : TimeSpan . Zero ;
1815- // Pings are send only if KeepAlivePingDelay is not infinite.
1816- bool expectStreamPing = keepAlivePingDelay != Timeout . InfiniteTimeSpan ;
1817- // Pings (regardless ongoing communication) are send only if sending is on and policy is set to always.
1818- bool expectPingWithoutStream = expectStreamPing && keepAlivePingPolicy == HttpKeepAlivePingPolicy . Always ;
1819-
1820- TaskCompletionSource serverFinished = new TaskCompletionSource ( ) ;
1821-
1822- await Http2LoopbackServer . CreateClientAndServerAsync (
1823- async uri =>
1824- {
1825- SocketsHttpHandler handler = new SocketsHttpHandler ( )
1826- {
1827- KeepAlivePingTimeout = pingTimeout ,
1828- KeepAlivePingPolicy = keepAlivePingPolicy ,
1829- KeepAlivePingDelay = keepAlivePingDelay
1830- } ;
1831- handler . SslOptions . RemoteCertificateValidationCallback = delegate { return true ; } ;
1832-
1833- using HttpClient client = new HttpClient ( handler ) ;
1834- client . DefaultRequestVersion = HttpVersion . Version20 ;
1835-
1836- // Warmup request to create connection.
1837- await client . GetStringAsync ( uri ) ;
1838- // Request under the test scope.
1839- if ( expectRequestFail )
1840- {
1841- await Assert . ThrowsAsync < HttpRequestException > ( ( ) => client . GetStringAsync ( uri ) ) ;
1842- // As stream is closed we don't want to continue with sending data.
1843- return ;
1844- }
1845- else
1846- {
1847- await client . GetStringAsync ( uri ) ;
1848- }
1849-
1850- // Let connection live until server finishes.
1851- try
1852- {
1853- await serverFinished . Task . WaitAsync ( pingTimeout * 3 ) ;
1854- }
1855- catch ( TimeoutException ) { }
1856- } ,
1857- async server =>
1858- {
1859- using Http2LoopbackConnection connection = await server . EstablishConnectionAsync ( ) ;
1860-
1861- Task < PingFrame > receivePingTask = expectStreamPing ? connection . ExpectPingFrameAsync ( ) : null ;
1862-
1863- // Warmup the connection.
1864- int streamId1 = await connection . ReadRequestHeaderAsync ( ) ;
1865- await connection . SendDefaultResponseAsync ( streamId1 ) ;
1866-
1867- // Request under the test scope.
1868- int streamId2 = await connection . ReadRequestHeaderAsync ( ) ;
1869-
1870- // Test ping with active stream.
1871- if ( ! expectStreamPing )
1872- {
1873- await Assert . ThrowsAsync < OperationCanceledException > ( ( ) => connection . ReadPingAsync ( pingTimeout ) ) ;
1874- }
1875- else
1876- {
1877- PingFrame ping ;
1878- if ( receivePingTask != null && receivePingTask . IsCompleted )
1879- {
1880- ping = await receivePingTask ;
1881- }
1882- else
1883- {
1884- ping = await connection . ReadPingAsync ( pingTimeout ) ;
1885- }
1886- if ( pongDelay > TimeSpan . Zero )
1887- {
1888- await Task . Delay ( pongDelay ) ;
1889- }
1890-
1891- await connection . SendPingAckAsync ( ping . Data ) ;
1892- }
1893-
1894- // Send response and close the stream.
1895- if ( expectRequestFail )
1896- {
1897- await Assert . ThrowsAsync < IOException > ( ( ) => connection . SendDefaultResponseAsync ( streamId2 ) ) ;
1898- // As stream is closed we don't want to continue with sending data.
1899- return ;
1900- }
1901- await connection . SendDefaultResponseAsync ( streamId2 ) ;
1902- // Test ping with no active stream.
1903- if ( expectPingWithoutStream )
1904- {
1905- PingFrame ping = await connection . ReadPingAsync ( pingTimeout ) ;
1906- await connection . SendPingAckAsync ( ping . Data ) ;
1907- }
1908- else
1909- {
1910- // If the pings were recently coming, just give the connection time to clear up streams
1911- // and still accept one stray ping.
1912- if ( expectStreamPing )
1913- {
1914- try
1915- {
1916- await connection . ReadPingAsync ( pingTimeout ) ;
1917- }
1918- catch ( OperationCanceledException ) { } // if it failed once, it will fail again
1919- }
1920- await Assert . ThrowsAsync < OperationCanceledException > ( ( ) => connection . ReadPingAsync ( pingTimeout ) ) ;
1921- }
1922- serverFinished . SetResult ( ) ;
1923- await connection . WaitForClientDisconnectAsync ( true ) ;
1924- } ,
1925- new Http2Options ( ) { EnableTransparentPingResponse = false } ) ;
1926- }
1927- }
1928-
19291786 [ OuterLoop ( "Uses Task.Delay" ) ]
19301787 [ ConditionalFact ( nameof ( SupportsAlpn ) ) ]
19311788 public async Task Http2_MaxConcurrentStreams_LimitEnforced ( )
0 commit comments