Skip to content

Commit

Permalink
RavenDB-19900: added an option to modify the timeout of GetDatabaseTo…
Browse files Browse the repository at this point in the history
…pologyCommand
  • Loading branch information
TheGoldenPlatypus committed Jul 26, 2023
1 parent 4b67b2d commit b7a8afd
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Raven.Client/Http/RavenCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public abstract class RavenCommand<TResult>

public RavenCommandResponseType ResponseType { get; protected set; }

public TimeSpan? Timeout { get; protected set; }
public TimeSpan? Timeout { get; protected internal set; }
public bool CanCache { get; protected set; }
public bool CanCacheAggressively { get; protected set; }
public string SelectedNodeTag { get; protected set; }
Expand Down
10 changes: 10 additions & 0 deletions src/Raven.Client/Http/RequestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,11 @@ public virtual async Task<bool> UpdateTopologyAsync(UpdateTopologyParameters par
using (ContextPool.AllocateOperationContext(out JsonOperationContext context))
{
var command = new GetDatabaseTopologyCommand(parameters.DebugTag, Conventions.SendApplicationIdentifier ? parameters.ApplicationIdentifier : null);
ForTestingPurposes?.SetCommandTimeout?.Invoke(command);

if (DefaultTimeout.HasValue && DefaultTimeout.Value > command.Timeout)
command.Timeout = DefaultTimeout.Value;

await ExecuteAsync(parameters.Node, null, context, command, shouldRetry: false, sessionInfo: null, token: CancellationToken.None).ConfigureAwait(false);
var topology = command.Result;

Expand Down Expand Up @@ -995,6 +1000,7 @@ private async Task<HttpResponseMessage> SendRequestToServer<TResult>(
cts.CancelAfter(timeout.Value);
try
{
ForTestingPurposes?.DelayRequest?.Invoke();
return await SendAsync(chosenNode, command, sessionInfo, request, cts.Token).ConfigureAwait(false);
}
catch (OperationCanceledException e)
Expand Down Expand Up @@ -2404,6 +2410,10 @@ internal TestingStuff(RequestExecutor requestExecutor)
public Action<Task[]> ExecuteOnAllToFigureOutTheFastestOnBeforeWait;

internal Action<NodeSelector> OnBeforeScheduleSpeedTest;

internal Action DelayRequest;

internal Action<GetDatabaseTopologyCommand> SetCommandTimeout;
}
}
}
61 changes: 61 additions & 0 deletions test/SlowTests/Issues/RavenDB_19900.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using System;
using System.Threading;
using FastTests;
using Raven.Client.Http;


namespace SlowTests.Issues
{
public class RavenDB_19900 : RavenTestBase
{
public RavenDB_19900(ITestOutputHelper output) : base(output)
{
}

[Fact]
public async Task UpdateTopologyTimeoutBehaviourShouldBeAccordingToConfiguration()
{
var generalTimeout = TimeSpan.FromSeconds(3);
var customCommandTimeout = TimeSpan.FromSeconds(1);
var delay = 2000;

using (var store = GetDocumentStore())
{
var executor = store.GetRequestExecutor();

try
{
// delaying response should result in UpdateTopology timeout
executor.ForTestingPurposesOnly().DelayRequest = () => { Thread.Sleep(delay); };
executor.ForTestingPurposesOnly().SetCommandTimeout = (command) =>
{
command.Timeout = customCommandTimeout;
};
var e = await Assert.ThrowsAsync<TimeoutException>(async () => await UpdateTopology());
Assert.Contains("failed with timeout after 00:00:01", e.ToString());

// increasing the general timeout should let UpdateTopology() to be executed
using (store.SetRequestTimeout(generalTimeout))
{
await UpdateTopology();
}

async Task UpdateTopology()
{
var node = executor.GetPreferredNode().Result.Node;
var topologyUpdateCommand = new RequestExecutor.UpdateTopologyParameters(node);
await executor.UpdateTopologyAsync(topologyUpdateCommand);
}
}
finally
{
executor.ForTestingPurposes = null;
}
}
}
}
}

0 comments on commit b7a8afd

Please sign in to comment.