Skip to content
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
123c6e8
chore: Ocelot.Configuration.Creator.IHttpHandlerOptionsCreator => Upd…
henriqueholtz Sep 28, 2024
07c024c
chore: Getting rid of ".Result" (using "GetAwaiter().GetResult()" ins…
henriqueholtz Sep 28, 2024
cc37929
test: Getting rid of ".Result" (using "GetAwaiter().GetResult()" inst…
henriqueholtz Sep 28, 2024
d5bc104
chore: Benchmarks => Turning "await app.UseOcelot()" instead of of "a…
henriqueholtz Sep 28, 2024
9b9ec8c
test: Turning "await app.UseOcelot()" instead of of "app.UseOcelot().…
henriqueholtz Sep 28, 2024
fae4354
test: Ocelot.IntegrationTests.AdministrationTests => Turning methods …
henriqueholtz Oct 1, 2024
877814c
perf: Ocelot.UnitTests => Getting rid of "GetAwaiter().GetResult" and…
henriqueholtz Oct 1, 2024
4c06622
test: Ocelot.AcceptanceTests => turning methods as async as possible
henriqueholtz Oct 2, 2024
f095153
test: Fixing the test "should_return_response_200_with_simple_url_whe…
henriqueholtz Oct 2, 2024
2031123
test: Fixing tests from "ConsulConfigurationInConsulTests" + async/aw…
henriqueholtz Oct 2, 2024
551d1b7
test: Fixing some tests after merging
henriqueholtz Oct 5, 2024
ebd5dcb
test: Ocelot.AcceptanceTests => Using asyn/await instead of ".GetAwai…
henriqueholtz Oct 9, 2024
d82f37a
test: Returning the task directly instead of awaiting for it when it'…
henriqueholtz Oct 9, 2024
e708509
test: Undo moving the function "Steps.ThenTheStatusCodeShouldBe(HttpS…
henriqueholtz Oct 9, 2024
4f1ddd1
test: Removing with no usage function "Steps.GivenOcelotIsRunningWith…
henriqueholtz Oct 10, 2024
59bd034
test: Creating method "UntilAsync" and using it to get rid some ".Get…
henriqueholtz Oct 10, 2024
2abdbbf
chore: Reverting renaming (removing the suffix "Async")
henriqueholtz Oct 11, 2024
11c1459
chore: (2th) Reverting renaming (removing the suffix "Async")
henriqueholtz Oct 11, 2024
9bd1214
test: Bringing back the slash I removed with no reason
henriqueholtz Oct 11, 2024
59c3551
chore: Trying to revert fake changes of "test/Ocelot.AcceptanceTests/…
henriqueholtz Oct 12, 2024
63fc393
chore: Undone fake changes
henriqueholtz Oct 12, 2024
61d5436
chore: Undone useless renamed methods
henriqueholtz Oct 12, 2024
056831f
chore: removing unecessary "await task" and just returning it
henriqueholtz Oct 12, 2024
9a6eab8
chore: Undone fake changes "AggregateTests"
henriqueholtz Oct 12, 2024
1cc02f1
chore: FileConfigurationFluentValidatorTests => Undo rename method "W…
henriqueholtz Oct 12, 2024
cb21556
chore: test/Ocelot.AcceptanceTests/AggregateTests => reverting fake c…
henriqueholtz Oct 12, 2024
8343c38
chore: test/Ocelot.UnitTests/CacheManager/OutputCacheMiddlewareRealCa…
henriqueholtz Oct 13, 2024
687a250
test: test/Ocelot.UnitTests/CacheManager/OutputCacheMiddlewareRealCac…
henriqueholtz Oct 13, 2024
9629a94
perf: src/Ocelot.Provider.Consul/Consul => Using async/await instead …
henriqueholtz Oct 13, 2024
b6c3d82
chore: test/Ocelot.UnitTests/CacheManager/OutputCacheMiddlewareRealCa…
henriqueholtz Oct 13, 2024
a38f733
Revert "chore: test/Ocelot.UnitTests/CacheManager/OutputCacheMiddlewa…
henriqueholtz Oct 13, 2024
0c1b38b
Revert "test: test/Ocelot.UnitTests/CacheManager/OutputCacheMiddlewar…
henriqueholtz Oct 13, 2024
6896aaf
test: test/Ocelot.UnitTests/CacheManager/OutputCacheMiddlewareRealCac…
henriqueholtz Oct 13, 2024
a9659ed
perf: ConsulFileConfigurationPollerOption.GetDelay => Removing useles…
henriqueholtz Oct 13, 2024
480ba72
chore: Ocelot.UnitTests.Configuration.FileConfigurationSetterTests =>…
henriqueholtz Oct 15, 2024
3655677
Revert "chore: Ocelot.UnitTests.Configuration.FileConfigurationSetter…
henriqueholtz Oct 15, 2024
b11b8ee
Fix build errors
raman-m Oct 16, 2024
a851098
EOL: test/Ocelot.AcceptanceTests/AggregateTests.cs
raman-m Oct 16, 2024
5ea8c89
code review by @raman-m
raman-m Oct 16, 2024
efd5a31
EOL: test/Ocelot.AcceptanceTests/Steps.cs
raman-m Oct 16, 2024
16e495f
Fix build
raman-m Oct 16, 2024
8061814
EOL: test/Ocelot.IntegrationTests/CacheManagerTests.cs
raman-m Oct 16, 2024
5c03c96
EOL: test/Ocelot.IntegrationTests/HeaderTests.cs
raman-m Oct 16, 2024
943d9bb
EOL: test/Ocelot.UnitTests/Configuration/Validation/FileConfiguration…
raman-m Oct 16, 2024
93331c7
EOL: test/Ocelot.UnitTests/Requester/HttpRequesterMiddlewareTests.cs
raman-m Oct 16, 2024
cc4a920
EOL: test/Ocelot.UnitTests/Security/SecurityMiddlewareTests.cs
raman-m Oct 16, 2024
8b10792
Revert the code to read `ValueTask.Result` if completed.
raman-m Oct 16, 2024
6ff1011
Sync call of the async method inside of sync context.
raman-m Oct 16, 2024
5376507
Add docs for Dev Best Practices
raman-m Oct 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/Ocelot.Provider.Consul/Consul.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ public virtual async Task<List<Service>> GetAsync()
var nodesTask = _consul.Catalog.Nodes();

await Task.WhenAll(entriesTask, nodesTask);

var entries = entriesTask.Result.Response ?? Array.Empty<ServiceEntry>();
var nodes = nodesTask.Result.Response ?? Array.Empty<Node>();
var entries = (await entriesTask).Response ?? Array.Empty<ServiceEntry>();
var nodes = (await nodesTask).Response ?? Array.Empty<Node>();
if (entries.Length == 0)
{
_logger.LogWarning(() => $"{nameof(Consul)} Provider: No service entries found for '{_configuration.KeyOfServiceInConsul}' service!");
Expand Down
2 changes: 1 addition & 1 deletion src/Ocelot.Provider.Consul/PollConsul.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Task<List<Service>> GetAsync()
try
{
_logger.LogInformation(() => $"Retrieving new client information for service: {ServiceName}...");
_services = _consulServiceDiscoveryProvider.GetAsync().Result;
_services = _consulServiceDiscoveryProvider.GetAsync().GetAwaiter().GetResult();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we are within a lock statement, we must adhere to writing only synchronous code. I agree with the change, however...
@ggnaegi, what would occur if we eliminate the lock? Due to the need for precise time capturing, we must prevent other threads from executing because the method modifies the class member _lastUpdateTime on line 59. It appears it's not feasible to convert this method into truly asynchronous, correct?

Copy link
Member

@raman-m raman-m Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an issue!.. We will tackle the issue of lock statements versus synchronous task calls in the future.

return Task.FromResult(_services);
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ namespace Ocelot.Configuration.Creator
/// </summary>
public interface IHttpHandlerOptionsCreator
{
HttpHandlerOptions Create(FileHttpHandlerOptions fileRoute);
HttpHandlerOptions Create(FileHttpHandlerOptions options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private int GetDelay()
{
var delay = 1000;

var fileConfig = Task.Run(async () => await _fileConfigurationRepository.Get()).Result;
var fileConfig = _fileConfigurationRepository.Get().GetAwaiter().GetResult();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have this sync version in the interface:


Why not to add async version to the interface?
After that we can make private and public methods as true async → Task<int> DelayAsync { get; }

Suggested change
var fileConfig = _fileConfigurationRepository.Get().GetAwaiter().GetResult();
var fileConfig = await _fileConfigurationRepository.Get();

Optional goal is using Task.Delay, if applicable.

Copy link
Member

@raman-m raman-m Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expression has been revised to execute synchronously within the synchronous int GetDelay() method.
The proposed suggestion for refactoring is beyond the scope of this pull request. We will refactor the interface in future.
TODO added in commit 6ff1011 ✔️

if (fileConfig?.Data?.GlobalConfiguration?.ServiceDiscoveryProvider != null &&
!fileConfig.IsError &&
fileConfig.Data.GlobalConfiguration.ServiceDiscoveryProvider.PollingInterval > 0)
Expand Down
2 changes: 1 addition & 1 deletion src/Ocelot/Request/Mapper/StreamHttpContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static async Task CopyAsync(Stream input, Stream output, long announcedC
if (zeroByteReadTask.IsCompletedSuccessfully)
{
// Consume the ValueTask's result in case it is backed by an IValueTaskSource
_ = zeroByteReadTask.Result;
_ = zeroByteReadTask.GetAwaiter().GetResult();
}
else
{
Expand Down
Loading