Skip to content

Commit

Permalink
Fix cases of MultiServerClient not being able to handle GraphQL being…
Browse files Browse the repository at this point in the history
… disabled
  • Loading branch information
Cyberboss committed Oct 11, 2024
1 parent d3082b2 commit 772af9c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
9 changes: 7 additions & 2 deletions tests/Tgstation.Server.Tests/Live/MultiServerClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public MultiServerClient(IRestServerClient restServerClient, IGraphQLServerClien
public ValueTask DisposeAsync()
=> ValueTaskExtensions.WhenAll(
RestClient.DisposeAsync(),
GraphQLClient.DisposeAsync());
GraphQLClient?.DisposeAsync() ?? ValueTask.CompletedTask);

public ValueTask Execute(
Func<IRestServerClient, ValueTask> restAction,
Expand All @@ -48,6 +48,11 @@ public ValueTask Execute(
where TGraphQLResult : class
{
var restTask = restAction(RestClient);
if (!UseGraphQL)
{
return (await restTask, null);
}

var graphQLResult = await GraphQLClient.RunOperation(graphQLAction, cancellationToken);

graphQLResult.EnsureNoErrors();
Expand All @@ -60,6 +65,6 @@ public ValueTask Execute(
}

public ValueTask<IDisposable> Subscribe<TResultData>(Func<IGraphQLClient, IObservable<IOperationResult<TResultData>>> operationExecutor, IObserver<IOperationResult<TResultData>> observer, CancellationToken cancellationToken) where TResultData : class
=> GraphQLClient.Subscribe(operationExecutor, observer, cancellationToken);
=> GraphQLClient?.Subscribe(operationExecutor, observer, cancellationToken) ?? ValueTask.FromResult<IDisposable>(new CancellationTokenSource());
}
}
12 changes: 7 additions & 5 deletions tests/Tgstation.Server.Tests/Live/TestLiveServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1930,11 +1930,13 @@ async ValueTask<MultiServerClient> CreateClient(
password,
cancellationToken: cancellationToken);
using var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
graphQLClientTask = graphQLClientFactory.CreateFromLogin(
url,
username,
password,
cancellationToken: cts.Token);
graphQLClientTask = MultiServerClient.UseGraphQL
? graphQLClientFactory.CreateFromLogin(
url,
username,
password,
cancellationToken: cts.Token)
: ValueTask.FromResult<IAuthenticatedGraphQLServerClient>(null);

IRestServerClient restClient;
try
Expand Down
3 changes: 3 additions & 0 deletions tests/Tgstation.Server.Tests/Live/UsersTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ await ValueTaskExtensions.WhenAll(

await TestPagination(cancellationToken);

if (!MultiServerClient.UseGraphQL)
return;

Assert.IsFalse(observer.Completed);
Assert.AreEqual(0U, observer.ErrorCount);

Expand Down

0 comments on commit 772af9c

Please sign in to comment.