This repository was archived by the owner on Jul 9, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed
tests/Titanium.Web.Proxy.IntegrationTests Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Diagnostics ;
4
+ using System . Linq ;
5
+ using System . Net ;
6
+ using System . Net . Http ;
7
+ using System . Threading . Tasks ;
8
+ using Microsoft . AspNetCore . Http ;
9
+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
10
+ using Titanium . Web . Proxy . Models ;
11
+
12
+ namespace Titanium . Web . Proxy . IntegrationTests
13
+ {
14
+ [ TestClass ]
15
+ public class StressTests
16
+ {
17
+ [ TestMethod ]
18
+ [ Timeout ( 2 * 60 * 1000 ) ]
19
+ public async Task Stress_Test_With_One_Server_And_Many_Clients ( )
20
+ {
21
+ var rnd = new Random ( ) ;
22
+
23
+ var testSuite = new TestSuite ( ) ;
24
+
25
+ var server = testSuite . GetServer ( ) ;
26
+ server . HandleRequest ( ( context ) =>
27
+ {
28
+ return context . Response . WriteAsync ( "I am server. I received your greetings." ) ;
29
+ } ) ;
30
+
31
+ using var proxy = testSuite . GetProxy ( ) ;
32
+
33
+ var tasks = new List < Task > ( ) ;
34
+
35
+ //send 1000 requests to server
36
+ for ( int j = 0 ; j < 1000 ; j ++ )
37
+ {
38
+ var task = Task . Run ( async ( ) =>
39
+ {
40
+ using var client = testSuite . GetClient ( proxy ) ;
41
+
42
+ await client . PostAsync ( new Uri ( server . ListeningHttpsUrl ) ,
43
+ new StringContent ( "hello server. I am a client." ) ) ;
44
+ } ) ;
45
+
46
+ tasks . Add ( task ) ;
47
+ }
48
+
49
+ await Task . WhenAll ( tasks ) ;
50
+ }
51
+ }
52
+ }
You can’t perform that action at this time.
0 commit comments