From faeb730ebe9da6b084c9594eb96d6654db2589ba Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Sat, 7 Oct 2023 17:31:50 -0400 Subject: [PATCH] Penultimate ValueTask conversion --- .../Components/InstanceManager.cs | 7 ++++--- .../Components/Repository/Repository.cs | 3 +++ .../Controllers/HomeController.cs | 7 +++---- .../Controllers/LimitedStreamResult.cs | 2 +- .../Database/DatabaseContextFactory.cs | 2 +- .../Database/IDatabaseContextFactory.cs | 2 +- .../IO/BufferedFileStreamProvider.cs | 4 ++-- .../IO/IFileStreamProvider.cs | 4 ++-- .../IO/ISeekableFileStreamProvider.cs | 4 ++-- .../IO/RequestFileStreamProvider.cs | 2 +- src/Tgstation.Server.Host/Jobs/IJobManager.cs | 8 ++++---- src/Tgstation.Server.Host/Jobs/JobService.cs | 17 +++++++++-------- .../Security/AuthenticationContextFactory.cs | 2 +- .../Security/IAuthenticationContextFactory.cs | 4 ++-- .../Security/ISystemIdentityFactory.cs | 4 ++-- .../Security/ITokenFactory.cs | 4 ++-- .../Security/OAuth/GenericOAuthValidator.cs | 8 ++++---- .../Security/OAuth/GitHubOAuthValidator.cs | 8 ++++---- .../Security/OAuth/IOAuthProviders.cs | 7 ++----- .../Security/OAuth/IOAuthValidator.cs | 9 ++++----- .../Security/OAuth/OAuthProviders.cs | 12 ++++-------- .../Security/TokenFactory.cs | 2 +- .../Transfer/FileUploadProvider.cs | 4 ++-- .../Chat/Providers/TestDiscordProvider.cs | 2 +- .../Chat/Providers/TestIrcProvider.cs | 2 +- .../IO/TestRequestFileStreamProvider.cs | 6 +++--- .../Swarm/TestableSwarmNode.cs | 2 +- .../CachingFileDownloader.cs | 2 +- 28 files changed, 68 insertions(+), 72 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/InstanceManager.cs b/src/Tgstation.Server.Host/Components/InstanceManager.cs index f15847d80d..eeae580d05 100644 --- a/src/Tgstation.Server.Host/Components/InstanceManager.cs +++ b/src/Tgstation.Server.Host/Components/InstanceManager.cs @@ -11,6 +11,7 @@ using Microsoft.Extensions.Options; using Tgstation.Server.Api.Models; using Tgstation.Server.Common; +using Tgstation.Server.Common.Extensions; using Tgstation.Server.Host.Components.Interop; using Tgstation.Server.Host.Components.Interop.Bridge; using Tgstation.Server.Host.Configuration; @@ -274,7 +275,7 @@ namespace Tgstation.Server.Host.Components logger.LogDebug("Reverting instance {instanceId}'s path to {oldPath} in the DB...", instance.Id, oldPath); // DCT: Operation must always run - await databaseContextFactory.UseContext2(db => + await databaseContextFactory.UseContextTaskReturn(db => { var targetInstance = new Models.Instance { @@ -342,7 +343,7 @@ namespace Tgstation.Server.Host.Components await container.OnZeroReferences.WaitAsync(cancellationToken); // we are the one responsible for cancelling his jobs - var tasks = new List(); + var tasks = new List>(); await databaseContextFactory.UseContext( async db => { @@ -359,7 +360,7 @@ namespace Tgstation.Server.Host.Components tasks.Add(jobService.CancelJob(job, user, true, cancellationToken)); }); - await Task.WhenAll(tasks); + await ValueTaskExtensions.WhenAll(tasks); } catch { diff --git a/src/Tgstation.Server.Host/Components/Repository/Repository.cs b/src/Tgstation.Server.Host/Components/Repository/Repository.cs index a7dc248692..928d873ae4 100644 --- a/src/Tgstation.Server.Host/Components/Repository/Repository.cs +++ b/src/Tgstation.Server.Host/Components/Repository/Repository.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using LibGit2Sharp; using LibGit2Sharp.Handlers; + using Microsoft.Extensions.Logging; using Tgstation.Server.Api.Models; @@ -20,6 +21,7 @@ using Tgstation.Server.Host.Jobs; namespace Tgstation.Server.Host.Components.Repository { /// +#pragma warning disable CA1506 // TODO: Decomplexify sealed class Repository : IRepository { /// @@ -1131,4 +1133,5 @@ namespace Tgstation.Server.Host.Components.Repository return !cancellationToken.IsCancellationRequested; }; } +#pragma warning restore CA1506 } diff --git a/src/Tgstation.Server.Host/Controllers/HomeController.cs b/src/Tgstation.Server.Host/Controllers/HomeController.cs index a0be005e9e..8aa6d3d03b 100644 --- a/src/Tgstation.Server.Host/Controllers/HomeController.cs +++ b/src/Tgstation.Server.Host/Controllers/HomeController.cs @@ -145,16 +145,15 @@ namespace Tgstation.Server.Host.Controllers /// /// Main page of the . /// - /// The for the operation. /// - /// A resuting in the containing of the if a properly authenticated API request, the web control panel if on a browser and enabled, otherwise. + /// The containing of the if a properly authenticated API request, the web control panel if on a browser and enabled, otherwise. /// /// retrieved successfully. [HttpGet] [AllowAnonymous] [ProducesResponseType(typeof(ServerInformationResponse), 200)] #pragma warning disable CA1506 - public async ValueTask Home(CancellationToken cancellationToken) + public IActionResult Home() { if (controlPanelConfiguration.Enable) Response.Headers.Add( @@ -201,7 +200,7 @@ namespace Tgstation.Server.Host.Controllers ValidInstancePaths = generalConfiguration.ValidInstancePaths, WindowsHost = platformIdentifier.IsWindows, SwarmServers = swarmService.GetSwarmServers(), - OAuthProviderInfos = await oAuthProviders.ProviderInfos(cancellationToken), + OAuthProviderInfos = oAuthProviders.ProviderInfos(), UpdateInProgress = serverControl.UpdateInProgress, }); } diff --git a/src/Tgstation.Server.Host/Controllers/LimitedStreamResult.cs b/src/Tgstation.Server.Host/Controllers/LimitedStreamResult.cs index 1917b53b17..734a1731a6 100644 --- a/src/Tgstation.Server.Host/Controllers/LimitedStreamResult.cs +++ b/src/Tgstation.Server.Host/Controllers/LimitedStreamResult.cs @@ -48,6 +48,6 @@ namespace Tgstation.Server.Host.Controllers } /// - public Task GetResult(CancellationToken cancellationToken) => Task.FromResult(stream); + public ValueTask GetResult(CancellationToken cancellationToken) => ValueTask.FromResult(stream); } } diff --git a/src/Tgstation.Server.Host/Database/DatabaseContextFactory.cs b/src/Tgstation.Server.Host/Database/DatabaseContextFactory.cs index 367b9f030f..b04e32858b 100644 --- a/src/Tgstation.Server.Host/Database/DatabaseContextFactory.cs +++ b/src/Tgstation.Server.Host/Database/DatabaseContextFactory.cs @@ -35,7 +35,7 @@ namespace Tgstation.Server.Host.Database } /// - public async ValueTask UseContext2(Func operation) + public async ValueTask UseContextTaskReturn(Func operation) { ArgumentNullException.ThrowIfNull(operation); diff --git a/src/Tgstation.Server.Host/Database/IDatabaseContextFactory.cs b/src/Tgstation.Server.Host/Database/IDatabaseContextFactory.cs index 228d34f498..4004c873c0 100644 --- a/src/Tgstation.Server.Host/Database/IDatabaseContextFactory.cs +++ b/src/Tgstation.Server.Host/Database/IDatabaseContextFactory.cs @@ -20,6 +20,6 @@ namespace Tgstation.Server.Host.Database /// /// The operation to run. /// A representing the running . - ValueTask UseContext2(Func operation); + ValueTask UseContextTaskReturn(Func operation); } } diff --git a/src/Tgstation.Server.Host/IO/BufferedFileStreamProvider.cs b/src/Tgstation.Server.Host/IO/BufferedFileStreamProvider.cs index a31e076fb2..bf578ac7d4 100644 --- a/src/Tgstation.Server.Host/IO/BufferedFileStreamProvider.cs +++ b/src/Tgstation.Server.Host/IO/BufferedFileStreamProvider.cs @@ -77,14 +77,14 @@ namespace Tgstation.Server.Host.IO } /// - public async Task GetResult(CancellationToken cancellationToken) + public async ValueTask GetResult(CancellationToken cancellationToken) { var (sharedStream, _) = await GetResultInternal(cancellationToken); return sharedStream; } /// - public async Task GetOwnedResult(CancellationToken cancellationToken) + public async ValueTask GetOwnedResult(CancellationToken cancellationToken) { var (sharedStream, length) = await GetResultInternal(cancellationToken); return new MemoryStream(sharedStream.GetBuffer(), 0, (int)length, false, true); diff --git a/src/Tgstation.Server.Host/IO/IFileStreamProvider.cs b/src/Tgstation.Server.Host/IO/IFileStreamProvider.cs index 0660f878e4..e27f779314 100644 --- a/src/Tgstation.Server.Host/IO/IFileStreamProvider.cs +++ b/src/Tgstation.Server.Host/IO/IFileStreamProvider.cs @@ -14,8 +14,8 @@ namespace Tgstation.Server.Host.IO /// Gets the provided . May be called multiple times, though cancelling any may cause all calls to be cancelled. All calls yield the same reference. /// /// The for the operation. - /// A resulting in the provided on success, if it could not be provided. + /// A resulting in the provided on success, if it could not be provided. /// The resulting is owned by the and is short lived unless otherwise specified. It should be buffered if it needs use outside the lifetime of the . - Task GetResult(CancellationToken cancellationToken); + ValueTask GetResult(CancellationToken cancellationToken); } } diff --git a/src/Tgstation.Server.Host/IO/ISeekableFileStreamProvider.cs b/src/Tgstation.Server.Host/IO/ISeekableFileStreamProvider.cs index b9e204008d..7a6b76eb0d 100644 --- a/src/Tgstation.Server.Host/IO/ISeekableFileStreamProvider.cs +++ b/src/Tgstation.Server.Host/IO/ISeekableFileStreamProvider.cs @@ -18,7 +18,7 @@ namespace Tgstation.Server.Host.IO /// Gets the provided . May be called multiple times, though cancelling any may cause all calls to be cancelled. /// /// The for the operation. - /// A resulting in the provided on success, if it could not be provided. - Task GetOwnedResult(CancellationToken cancellationToken); + /// A resulting in the provided on success, if it could not be provided. + ValueTask GetOwnedResult(CancellationToken cancellationToken); } } diff --git a/src/Tgstation.Server.Host/IO/RequestFileStreamProvider.cs b/src/Tgstation.Server.Host/IO/RequestFileStreamProvider.cs index 3404a508eb..c0c100cfcf 100644 --- a/src/Tgstation.Server.Host/IO/RequestFileStreamProvider.cs +++ b/src/Tgstation.Server.Host/IO/RequestFileStreamProvider.cs @@ -90,7 +90,7 @@ namespace Tgstation.Server.Host.IO } /// - public async Task GetResult(CancellationToken cancellationToken) + public async ValueTask GetResult(CancellationToken cancellationToken) { if (disposed) throw new ObjectDisposedException(nameof(RequestFileStreamProvider)); diff --git a/src/Tgstation.Server.Host/Jobs/IJobManager.cs b/src/Tgstation.Server.Host/Jobs/IJobManager.cs index 4741406a16..716059f314 100644 --- a/src/Tgstation.Server.Host/Jobs/IJobManager.cs +++ b/src/Tgstation.Server.Host/Jobs/IJobManager.cs @@ -33,8 +33,8 @@ namespace Tgstation.Server.Host.Jobs /// The to cancel the . If the TGS user will be used. /// A that will cancel the . /// The for the operation. - /// A representing the . - Task WaitForJobCompletion(Job job, User canceller, CancellationToken jobCancellationToken, CancellationToken cancellationToken); + /// A representing the . + ValueTask WaitForJobCompletion(Job job, User canceller, CancellationToken jobCancellationToken, CancellationToken cancellationToken); /// /// Cancels a give . @@ -43,7 +43,7 @@ namespace Tgstation.Server.Host.Jobs /// The who cancelled the . If the TGS user will be used. /// If the operation should wait until the job exits before completing. /// The for the operation. - /// A resulting in the updated if it was cancelled, if it couldn't be found. - Task CancelJob(Job job, User user, bool blocking, CancellationToken cancellationToken); + /// A resulting in the updated if it was cancelled, if it couldn't be found. + ValueTask CancelJob(Job job, User user, bool blocking, CancellationToken cancellationToken); } } diff --git a/src/Tgstation.Server.Host/Jobs/JobService.cs b/src/Tgstation.Server.Host/Jobs/JobService.cs index e68b9a1333..363a8eed28 100644 --- a/src/Tgstation.Server.Host/Jobs/JobService.cs +++ b/src/Tgstation.Server.Host/Jobs/JobService.cs @@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Serilog.Context; using Tgstation.Server.Api.Models.Response; +using Tgstation.Server.Common.Extensions; using Tgstation.Server.Host.Components; using Tgstation.Server.Host.Database; using Tgstation.Server.Host.Extensions; @@ -172,9 +173,9 @@ namespace Tgstation.Server.Host.Jobs .AsTask(); /// - public async Task StopAsync(CancellationToken cancellationToken) + public Task StopAsync(CancellationToken cancellationToken) { - List> joinTasks; + List> joinTasks; lock (addCancelLock) lock (synchronizationLock) { @@ -190,11 +191,11 @@ namespace Tgstation.Server.Host.Jobs .ToList(); } - await Task.WhenAll(joinTasks); + return ValueTaskExtensions.WhenAll(joinTasks).AsTask(); } /// - public async Task CancelJob(Job job, User user, bool blocking, CancellationToken cancellationToken) + public async ValueTask CancelJob(Job job, User user, bool blocking, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(job); @@ -248,7 +249,7 @@ namespace Tgstation.Server.Host.Jobs } /// - public async Task WaitForJobCompletion(Job job, User canceller, CancellationToken jobCancellationToken, CancellationToken cancellationToken) + public async ValueTask WaitForJobCompletion(Job job, User canceller, CancellationToken jobCancellationToken, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(job); @@ -268,12 +269,12 @@ namespace Tgstation.Server.Host.Jobs if (noMoreJobsShouldStart && !handler.Started) await Extensions.TaskExtensions.InfiniteTask.WaitAsync(cancellationToken); - Task cancelTask = null; + ValueTask? cancelTask = null; using (jobCancellationToken.Register(() => cancelTask = CancelJob(job, canceller, true, cancellationToken))) await handler.Wait(cancellationToken); - if (cancelTask != null) - await cancelTask; + if (cancelTask.HasValue) + await cancelTask.Value; } /// diff --git a/src/Tgstation.Server.Host/Security/AuthenticationContextFactory.cs b/src/Tgstation.Server.Host/Security/AuthenticationContextFactory.cs index 51a51ad85b..7288dc00cf 100644 --- a/src/Tgstation.Server.Host/Security/AuthenticationContextFactory.cs +++ b/src/Tgstation.Server.Host/Security/AuthenticationContextFactory.cs @@ -62,7 +62,7 @@ namespace Tgstation.Server.Host.Security public void Dispose() => CurrentAuthenticationContext?.Dispose(); /// - public async Task CreateAuthenticationContext(long userId, long? instanceId, DateTimeOffset validAfter, CancellationToken cancellationToken) + public async ValueTask CreateAuthenticationContext(long userId, long? instanceId, DateTimeOffset validAfter, CancellationToken cancellationToken) { if (CurrentAuthenticationContext != null) throw new InvalidOperationException("Authentication context has already been loaded"); diff --git a/src/Tgstation.Server.Host/Security/IAuthenticationContextFactory.cs b/src/Tgstation.Server.Host/Security/IAuthenticationContextFactory.cs index d74d9529c6..9017765615 100644 --- a/src/Tgstation.Server.Host/Security/IAuthenticationContextFactory.cs +++ b/src/Tgstation.Server.Host/Security/IAuthenticationContextFactory.cs @@ -21,7 +21,7 @@ namespace Tgstation.Server.Host.Security /// The of the operation. /// The the resulting 's password must be valid after. /// The for the operation. - /// A representing the running operation. - Task CreateAuthenticationContext(long userId, long? instanceId, DateTimeOffset validAfter, CancellationToken cancellationToken); + /// A representing the running operation. + ValueTask CreateAuthenticationContext(long userId, long? instanceId, DateTimeOffset validAfter, CancellationToken cancellationToken); } } diff --git a/src/Tgstation.Server.Host/Security/ISystemIdentityFactory.cs b/src/Tgstation.Server.Host/Security/ISystemIdentityFactory.cs index 0a8f187429..2568861e53 100644 --- a/src/Tgstation.Server.Host/Security/ISystemIdentityFactory.cs +++ b/src/Tgstation.Server.Host/Security/ISystemIdentityFactory.cs @@ -21,7 +21,7 @@ namespace Tgstation.Server.Host.Security /// /// The user to create a for. /// The for the operation. - /// A new or if the has no . + /// A resulting in a new based on the given or if the has no . Task CreateSystemIdentity(User user, CancellationToken cancellationToken); /// @@ -30,7 +30,7 @@ namespace Tgstation.Server.Host.Security /// The username of the user. /// The password of the user. /// The for the operation. - /// A new . + /// A resulting in a new based on the given credentials. Task CreateSystemIdentity(string username, string password, CancellationToken cancellationToken); } } diff --git a/src/Tgstation.Server.Host/Security/ITokenFactory.cs b/src/Tgstation.Server.Host/Security/ITokenFactory.cs index 28e9273b46..6df27f813f 100644 --- a/src/Tgstation.Server.Host/Security/ITokenFactory.cs +++ b/src/Tgstation.Server.Host/Security/ITokenFactory.cs @@ -23,7 +23,7 @@ namespace Tgstation.Server.Host.Security /// The to create the token for. Must have the field available. /// Whether or not this is an OAuth login. /// The for the operation. - /// A resulting in a new . - Task CreateToken(Models.User user, bool oAuth, CancellationToken cancellationToken); + /// A resulting in a new . + ValueTask CreateToken(Models.User user, bool oAuth, CancellationToken cancellationToken); } } diff --git a/src/Tgstation.Server.Host/Security/OAuth/GenericOAuthValidator.cs b/src/Tgstation.Server.Host/Security/OAuth/GenericOAuthValidator.cs index 35c597bfce..8606d0921d 100644 --- a/src/Tgstation.Server.Host/Security/OAuth/GenericOAuthValidator.cs +++ b/src/Tgstation.Server.Host/Security/OAuth/GenericOAuthValidator.cs @@ -80,7 +80,7 @@ namespace Tgstation.Server.Host.Security.OAuth } /// - public async Task ValidateResponseCode(string code, CancellationToken cancellationToken) + public async ValueTask ValidateResponseCode(string code, CancellationToken cancellationToken) { using var httpClient = CreateHttpClient(); string tokenResponsePayload = null; @@ -140,13 +140,13 @@ namespace Tgstation.Server.Host.Security.OAuth } /// - public Task GetProviderInfo(CancellationToken cancellationToken) => Task.FromResult( - new OAuthProviderInfo + public OAuthProviderInfo GetProviderInfo() + => new () { ClientId = OAuthConfiguration.ClientId, RedirectUri = OAuthConfiguration.RedirectUrl, ServerUrl = OAuthConfiguration.ServerUrl, - }); + }; /// /// Decode the token payload . diff --git a/src/Tgstation.Server.Host/Security/OAuth/GitHubOAuthValidator.cs b/src/Tgstation.Server.Host/Security/OAuth/GitHubOAuthValidator.cs index ae19b252ca..f53fe8137c 100644 --- a/src/Tgstation.Server.Host/Security/OAuth/GitHubOAuthValidator.cs +++ b/src/Tgstation.Server.Host/Security/OAuth/GitHubOAuthValidator.cs @@ -52,7 +52,7 @@ namespace Tgstation.Server.Host.Security.OAuth } /// - public async Task ValidateResponseCode(string code, CancellationToken cancellationToken) + public async ValueTask ValidateResponseCode(string code, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(code); @@ -84,11 +84,11 @@ namespace Tgstation.Server.Host.Security.OAuth } /// - public Task GetProviderInfo(CancellationToken cancellationToken) => Task.FromResult( - new OAuthProviderInfo + public OAuthProviderInfo GetProviderInfo() + => new () { ClientId = oAuthConfiguration.ClientId, RedirectUri = oAuthConfiguration.RedirectUrl, - }); + }; } } diff --git a/src/Tgstation.Server.Host/Security/OAuth/IOAuthProviders.cs b/src/Tgstation.Server.Host/Security/OAuth/IOAuthProviders.cs index 4ea0ce2f14..c8b8a7b161 100644 --- a/src/Tgstation.Server.Host/Security/OAuth/IOAuthProviders.cs +++ b/src/Tgstation.Server.Host/Security/OAuth/IOAuthProviders.cs @@ -1,6 +1,4 @@ using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; using Tgstation.Server.Api.Models; @@ -21,8 +19,7 @@ namespace Tgstation.Server.Host.Security.OAuth /// /// Gets a of the provider client IDs. /// - /// The for the operation. - /// A resulting in a anew of the active s. - Task> ProviderInfos(CancellationToken cancellationToken); + /// A new of the active s. + Dictionary ProviderInfos(); } } diff --git a/src/Tgstation.Server.Host/Security/OAuth/IOAuthValidator.cs b/src/Tgstation.Server.Host/Security/OAuth/IOAuthValidator.cs index bd3b25e968..7f3ca57287 100644 --- a/src/Tgstation.Server.Host/Security/OAuth/IOAuthValidator.cs +++ b/src/Tgstation.Server.Host/Security/OAuth/IOAuthValidator.cs @@ -18,16 +18,15 @@ namespace Tgstation.Server.Host.Security.OAuth /// /// Gets the of validator. /// - /// The for the operation. - /// A resulting in the client ID of the validator on success, on failure. - Task GetProviderInfo(CancellationToken cancellationToken); + /// The client ID of the validator on success, on failure. + OAuthProviderInfo GetProviderInfo(); /// /// Validate a given OAuth response . /// /// The OAuth response string from web application. /// The for the operation. - /// A resulting in if authentication failed, if a rate limit occurred, and the validated otherwise. - Task ValidateResponseCode(string code, CancellationToken cancellationToken); + /// A resulting in if authentication failed, if a rate limit occurred, and the validated otherwise. + ValueTask ValidateResponseCode(string code, CancellationToken cancellationToken); } } diff --git a/src/Tgstation.Server.Host/Security/OAuth/OAuthProviders.cs b/src/Tgstation.Server.Host/Security/OAuth/OAuthProviders.cs index 05458a4c07..7a562668ee 100644 --- a/src/Tgstation.Server.Host/Security/OAuth/OAuthProviders.cs +++ b/src/Tgstation.Server.Host/Security/OAuth/OAuthProviders.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Threading; -using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -85,19 +83,17 @@ namespace Tgstation.Server.Host.Security.OAuth public IOAuthValidator GetValidator(OAuthProvider oAuthProvider) => validators.FirstOrDefault(x => x.Provider == oAuthProvider); /// - public async Task> ProviderInfos(CancellationToken cancellationToken) + public Dictionary ProviderInfos() { var providersAndTasks = validators.ToDictionary( x => x.Provider, - x => x.GetProviderInfo(cancellationToken)); - - await Task.WhenAll(providersAndTasks.Values); + x => x.GetProviderInfo()); return providersAndTasks - .Where(x => x.Value.Result != null) + .Where(x => x.Value != null) .ToDictionary( x => x.Key, - x => x.Value.Result); + x => x.Value); } } } diff --git a/src/Tgstation.Server.Host/Security/TokenFactory.cs b/src/Tgstation.Server.Host/Security/TokenFactory.cs index cc5ff8a270..81a96876f6 100644 --- a/src/Tgstation.Server.Host/Security/TokenFactory.cs +++ b/src/Tgstation.Server.Host/Security/TokenFactory.cs @@ -104,7 +104,7 @@ namespace Tgstation.Server.Host.Security } /// - public async Task CreateToken(Models.User user, bool oAuth, CancellationToken cancellationToken) + public async ValueTask CreateToken(Models.User user, bool oAuth, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(user); diff --git a/src/Tgstation.Server.Host/Transfer/FileUploadProvider.cs b/src/Tgstation.Server.Host/Transfer/FileUploadProvider.cs index 69286cc52c..9fe8250da5 100644 --- a/src/Tgstation.Server.Host/Transfer/FileUploadProvider.cs +++ b/src/Tgstation.Server.Host/Transfer/FileUploadProvider.cs @@ -66,7 +66,7 @@ namespace Tgstation.Server.Host.Transfer } /// - public async Task GetResult(CancellationToken cancellationToken) + public async ValueTask GetResult(CancellationToken cancellationToken) { using (cancellationToken.Register(() => streamTcs.TrySetCanceled(cancellationToken))) using (ticketExpiryCts.Token.Register(() => streamTcs.TrySetResult(null))) @@ -88,7 +88,7 @@ namespace Tgstation.Server.Host.Transfer /// The containing uploaded data. /// The for the operation. /// A resulting in , otherwise. - public async Task Completion(Stream stream, CancellationToken cancellationToken) + public async ValueTask Completion(Stream stream, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(stream); diff --git a/tests/Tgstation.Server.Host.Tests/Components/Chat/Providers/TestDiscordProvider.cs b/tests/Tgstation.Server.Host.Tests/Components/Chat/Providers/TestDiscordProvider.cs index db7ee0b40b..3943d05231 100644 --- a/tests/Tgstation.Server.Host.Tests/Components/Chat/Providers/TestDiscordProvider.cs +++ b/tests/Tgstation.Server.Host.Tests/Components/Chat/Providers/TestDiscordProvider.cs @@ -39,7 +39,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers.Tests .Returns(ValueTask.CompletedTask); mockSetup .Setup(x => x.WaitForJobCompletion(It.IsNotNull(), It.IsAny(), It.IsAny(), It.IsAny())) - .Returns(Task.CompletedTask); + .Returns(ValueTask.CompletedTask); mockJobManager = mockSetup.Object; } diff --git a/tests/Tgstation.Server.Host.Tests/Components/Chat/Providers/TestIrcProvider.cs b/tests/Tgstation.Server.Host.Tests/Components/Chat/Providers/TestIrcProvider.cs index 7bf2518628..80a5e40b66 100644 --- a/tests/Tgstation.Server.Host.Tests/Components/Chat/Providers/TestIrcProvider.cs +++ b/tests/Tgstation.Server.Host.Tests/Components/Chat/Providers/TestIrcProvider.cs @@ -76,7 +76,7 @@ namespace Tgstation.Server.Host.Components.Chat.Providers.Tests .Returns(ValueTask.CompletedTask); mockSetup .Setup(x => x.WaitForJobCompletion(It.IsNotNull(), It.IsAny(), It.IsAny(), It.IsAny())) - .Returns(Task.CompletedTask); + .Returns(ValueTask.CompletedTask); var mockJobManager = mockSetup.Object; await using var provider = new IrcProvider(mockJobManager, new AsyncDelayer(), loggerFactory.CreateLogger(), Mock.Of(), new ChatBot { diff --git a/tests/Tgstation.Server.Host.Tests/IO/TestRequestFileStreamProvider.cs b/tests/Tgstation.Server.Host.Tests/IO/TestRequestFileStreamProvider.cs index 638fa965c5..a950ee6b9f 100644 --- a/tests/Tgstation.Server.Host.Tests/IO/TestRequestFileStreamProvider.cs +++ b/tests/Tgstation.Server.Host.Tests/IO/TestRequestFileStreamProvider.cs @@ -133,9 +133,9 @@ namespace Tgstation.Server.Host.IO.Tests cts2.Cancel(); - await Assert.ThrowsExceptionAsync(() => task1); - await Assert.ThrowsExceptionAsync(() => task2); - await Assert.ThrowsExceptionAsync(() => task3); + await Assert.ThrowsExceptionAsync(() => task1.AsTask()); + await Assert.ThrowsExceptionAsync(() => task2.AsTask()); + await Assert.ThrowsExceptionAsync(() => task3.AsTask()); mockHttpClient.VerifyAll(); } diff --git a/tests/Tgstation.Server.Host.Tests/Swarm/TestableSwarmNode.cs b/tests/Tgstation.Server.Host.Tests/Swarm/TestableSwarmNode.cs index 0021948045..31b39a83c2 100644 --- a/tests/Tgstation.Server.Host.Tests/Swarm/TestableSwarmNode.cs +++ b/tests/Tgstation.Server.Host.Tests/Swarm/TestableSwarmNode.cs @@ -98,7 +98,7 @@ namespace Tgstation.Server.Host.Swarm.Tests .Setup(x => x.UseContext(It.IsNotNull>())) .Callback>((func) => func(mockDatabaseContext)); mockDBContextFactory - .Setup(x => x.UseContext2(It.IsNotNull>())) + .Setup(x => x.UseContextTaskReturn(It.IsNotNull>())) .Callback>((func) => func(mockDatabaseContext)); var mockHttpClientFactory = new Mock(); diff --git a/tests/Tgstation.Server.Tests/CachingFileDownloader.cs b/tests/Tgstation.Server.Tests/CachingFileDownloader.cs index 1ed2b172b7..17dcbbfaf5 100644 --- a/tests/Tgstation.Server.Tests/CachingFileDownloader.cs +++ b/tests/Tgstation.Server.Tests/CachingFileDownloader.cs @@ -130,7 +130,7 @@ namespace Tgstation.Server.Tests public ValueTask DisposeAsync() => ValueTask.CompletedTask; - public async Task GetResult(CancellationToken cancellationToken) + public async ValueTask GetResult(CancellationToken cancellationToken) => await CacheFile(logger, url, bearerToken, null, cancellationToken); }