File tree Expand file tree Collapse file tree 3 files changed +48
-1
lines changed
GraphQL.Client.Tests.Common/Chat/Schema
GraphQL.Integration.Tests Expand file tree Collapse file tree 3 files changed +48
-1
lines changed Original file line number Diff line number Diff line change 1+ using System ;
12using System . Collections . Generic ;
23using System . Linq ;
4+ using System . Threading . Tasks ;
35using GraphQL . Types ;
46
57namespace GraphQL . Client . Tests . Common . Chat . Schema {
@@ -21,6 +23,13 @@ public ChatQuery(IChat chat) {
2123 context . Errors . Add ( new ExecutionError ( "this error contains extension fields" , TestExtensions ) ) ;
2224 return null ;
2325 } ) ;
26+
27+ Field < StringGraphType > ( )
28+ . Name ( "longRunning" )
29+ . ResolveAsync ( async context => {
30+ await Task . Delay ( TimeSpan . FromSeconds ( 5 ) ) ;
31+ return "finally returned" ;
32+ } ) ;
2433 }
2534 }
2635}
Original file line number Diff line number Diff line change 1+ using System ;
12using System . Net . Http ;
3+ using System . Threading ;
4+ using System . Threading . Tasks ;
5+ using FluentAssertions ;
26using GraphQL . Client . Abstractions ;
37using GraphQL . Client . Abstractions . Websocket ;
48using GraphQL . Client . Http ;
@@ -155,5 +159,22 @@ public async void PreprocessHttpRequestMessageIsCalled() {
155159 Assert . Equal ( "Luke" , response . Data . Human . Name ) ;
156160 }
157161 }
162+
163+ [ Fact ]
164+ public void PostRequestCanBeCancelled ( ) {
165+ var graphQLRequest = new GraphQLRequest ( @"
166+ query Long {
167+ longRunning
168+ }" ) ;
169+
170+ using ( var setup = WebHostHelpers . SetupTest < StartupChat > ( false , serializer ) ) {
171+ var cts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 1 ) ) ;
172+
173+ Func < Task > requestTask = ( ) => setup . Client . SendQueryAsync ( graphQLRequest , ( ) => new { longRunning = string . Empty } , cts . Token ) ;
174+ Action timeMeasurement = ( ) => requestTask . Should ( ) . Throw < TaskCanceledException > ( ) ;
175+
176+ timeMeasurement . ExecutionTime ( ) . Should ( ) . BeCloseTo ( TimeSpan . FromSeconds ( 2 ) , TimeSpan . FromMilliseconds ( 200 ) ) ;
177+ }
178+ }
158179 }
159180}
Original file line number Diff line number Diff line change 33using System . Diagnostics ;
44using System . Net . WebSockets ;
55using System . Threading ;
6+ using System . Threading . Tasks ;
67using FluentAssertions ;
78using GraphQL . Client . Abstractions ;
89using GraphQL . Client . Abstractions . Websocket ;
@@ -38,7 +39,6 @@ public async void AssertTestingHarness() {
3839 }
3940 }
4041
41-
4242 [ Fact ]
4343 public async void CanSendRequestViaWebsocket ( ) {
4444 var port = NetworkHelpers . GetFreeTcpPortNumber ( ) ;
@@ -51,6 +51,23 @@ public async void CanSendRequestViaWebsocket() {
5151 }
5252 }
5353
54+ [ Fact ]
55+ public void WebsocketRequestCanBeCancelled ( ) {
56+ var graphQLRequest = new GraphQLRequest ( @"
57+ query Long {
58+ longRunning
59+ }" ) ;
60+
61+ using ( var setup = WebHostHelpers . SetupTest < StartupChat > ( true , Serializer ) ) {
62+ var cts = new CancellationTokenSource ( TimeSpan . FromSeconds ( 1 ) ) ;
63+
64+ Func < Task > requestTask = ( ) => setup . Client . SendQueryAsync ( graphQLRequest , ( ) => new { longRunning = string . Empty } , cts . Token ) ;
65+ Action timeMeasurement = ( ) => requestTask . Should ( ) . Throw < TaskCanceledException > ( ) ;
66+
67+ timeMeasurement . ExecutionTime ( ) . Should ( ) . BeCloseTo ( TimeSpan . FromSeconds ( 2 ) , TimeSpan . FromMilliseconds ( 200 ) ) ;
68+ }
69+ }
70+
5471 [ Fact ]
5572 public async void CanHandleRequestErrorViaWebsocket ( ) {
5673 var port = NetworkHelpers . GetFreeTcpPortNumber ( ) ;
You can’t perform that action at this time.
0 commit comments