Skip to content

Commit

Permalink
Allows test overrides of Dialogflow retry delay (#292)
Browse files Browse the repository at this point in the history
The current retry delay of 30 seconds is causing a significant delay when running unit tests that exercise that retry delay. This change allows the delay duration to be overridden.
  • Loading branch information
rozele committed Mar 16, 2020
1 parent bd5819d commit 503d2c5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/NLU.DevOps.Dialogflow.Tests/DialogflowNLUTestClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ internal static class DialogflowNLUTestClientTests
{
private const double Epsilon = 1e-6;

private static TimeSpan originalThrottle;

[OneTimeSetUp]
public static void SetUp()
{
originalThrottle = DialogflowNLUTestClient.ThrottleQueryDelay;
DialogflowNLUTestClient.ThrottleQueryDelay = TimeSpan.FromMilliseconds(100);
}

[OneTimeTearDown]
public static void TearDown()
{
DialogflowNLUTestClient.ThrottleQueryDelay = originalThrottle;
}

[Test]
public static void ThrowsArgumentNull()
{
Expand Down
6 changes: 3 additions & 3 deletions src/NLU.DevOps.Dialogflow/DialogflowNLUTestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ internal sealed class DialogflowNLUTestClient : DefaultNLUTestClient
private const string DialogflowProjectIdConfigurationKey = "dialogflowProjectId";
private const string DialogflowSessionIdConfigurationKey = "dialogflowSessionId";

// Dialogflow typically limits the number of requests per minute, so setting a retry delay to 30 seconds.
private static readonly TimeSpan ThrottleQueryDelay = TimeSpan.FromSeconds(30);

private SessionsClient sessionsClient;

public DialogflowNLUTestClient(SessionsClient sessionsClient, IConfiguration configuration)
Expand All @@ -45,6 +42,9 @@ public DialogflowNLUTestClient(IConfiguration configuration)
this.Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
}

// Dialogflow typically limits the number of requests per minute, so setting a retry delay to 30 seconds.
internal static TimeSpan ThrottleQueryDelay { get; set; } = TimeSpan.FromSeconds(30);

private static ILogger Logger => LazyLogger.Value;

private static Lazy<ILogger> LazyLogger { get; } = new Lazy<ILogger>(() => ApplicationLogger.LoggerFactory.CreateLogger<DialogflowNLUTestClient>());
Expand Down

0 comments on commit 503d2c5

Please sign in to comment.