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 18, 2023
1 parent 93446d0 commit 185b49b
Show file tree
Hide file tree
Showing 3 changed files with 51 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; internal set; }
public bool CanCache { get; protected set; }
public bool CanCacheAggressively { get; protected set; }
public string SelectedNodeTag { get; protected set; }
Expand Down
5 changes: 5 additions & 0 deletions src/Raven.Client/Http/RequestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,9 @@ 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);
if (DefaultTimeout.HasValue)
command.Timeout = new[] { DefaultTimeout, command.Timeout }.Max();

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

Expand Down Expand Up @@ -992,6 +995,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 @@ -2365,6 +2369,7 @@ internal TestingStuff(RequestExecutor requestExecutor)
internal int[] NodeSelectorFailures => _requestExecutor._nodeSelector.NodeSelectorFailures;
internal ConcurrentDictionary<ServerNode, Lazy<NodeStatus>> FailedNodesTimers => _requestExecutor._failedNodesTimers;
internal (int Index, ServerNode Node) PreferredNode => _requestExecutor._nodeSelector.GetPreferredNode();
internal Action DelayRequest => () => Thread.Sleep(18000);
}
}
}
45 changes: 45 additions & 0 deletions test/SlowTests/Issues/RavenDB_19900.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;
using System;
using Raven.Client.Http;
using Tests.Infrastructure;


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

[Fact]
public async Task UpdateTopologyTimeoutBehaviourShouldBeAccordingToConfiguration()
{
var timeout1 = TimeSpan.FromSeconds(20);
using (var store = GetDocumentStore())
{
var executor = store.GetRequestExecutor();

// delaying response should result in UpdateTopology timeout
var testingStuff = executor.ForTestingPurposesOnly();
var e = await Assert.ThrowsAsync<TimeoutException>(async () => await UpdateTopology());
Assert.Contains("failed with timeout after 00:00:15", e.ToString());

// increasing the general timeout should let UpdateTopology() to be executed
store.SetRequestTimeout(timeout1);
await UpdateTopology();

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

}
}

0 comments on commit 185b49b

Please sign in to comment.