-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bump Halibut to fix a polling tentacle cooperative cancellation issue causing request to time out to quickly #695
Closed
nathanwoctopusdeploy
wants to merge
1
commit into
main
from
sast/bump-halibut-for-cooperative-cancellation-bug-fix
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
source/Octopus.Tentacle.Tests.Integration/PollingRequestAndResponseTimeouts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Halibut; | ||
using NUnit.Framework; | ||
using Octopus.Tentacle.CommonTestUtils.Builders; | ||
using Octopus.Tentacle.Contracts; | ||
using Octopus.Tentacle.Contracts.ClientServices; | ||
using Octopus.Tentacle.Tests.Integration.Support; | ||
using Octopus.Tentacle.Tests.Integration.Util; | ||
using Octopus.Tentacle.Tests.Integration.Util.Builders; | ||
using Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators; | ||
using Octopus.Tentacle.Tests.Integration.Util.Builders.Decorators.Proxies; | ||
|
||
namespace Octopus.Tentacle.Tests.Integration | ||
{ | ||
[IntegrationTestTimeout] | ||
public class PollingRequestAndResponseTimeouts : IntegrationTest | ||
{ | ||
[Test] | ||
[TentacleConfigurations(testListening: false)] | ||
public async Task WhenThePollingRequestQueueTimeoutIsReached_ForARequestThatHasNotBeenDequeuedByTentacle_TheRequestShouldTimeout(TentacleConfigurationTestCase tentacleConfigurationTestCase) | ||
{ | ||
await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() | ||
.WithRetriesDisabled() | ||
.WithPortForwarder() | ||
.WithServiceEndpointModifier(serviceEndpoint => | ||
{ | ||
serviceEndpoint.PollingRequestQueueTimeout = TimeSpan.FromSeconds(5); | ||
}) | ||
.WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() | ||
.RecordMethodUsages<IAsyncClientCapabilitiesServiceV2>(out var capabilitiesMethodUsages) | ||
.RecordMethodUsages(tentacleConfigurationTestCase, out var scriptServiceMethodUsages) | ||
.Build()) | ||
.Build(CancellationToken); | ||
|
||
// Stop the request from being dequeued by stopping the Tentacle from connecting | ||
clientTentacle.PortForwarder!.EnterKillNewAndExistingConnectionsMode(); | ||
|
||
var startScriptCommand = new LatestStartScriptCommandBuilder().WithScriptBody(new ScriptBuilder().Print("Script Executed")).Build(); | ||
|
||
(await AssertionExtensions.Should(() => clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, CancellationToken)).ThrowAsync<HalibutClientException>()) | ||
.And.Message.Should().Contain("A request was sent to a polling endpoint, but the polling endpoint did not collect the request within the allowed time (00:00:05), so the request timed out."); | ||
|
||
capabilitiesMethodUsages.ForGetCapabilitiesAsync().Completed.Should().Be(1); | ||
scriptServiceMethodUsages.ForStartScriptAsync().Completed.Should().Be(0, "Get Capabilities should have timed out and cancelled script execution"); | ||
} | ||
|
||
[Test] | ||
[TentacleConfigurations(testListening: false)] | ||
public async Task WhenThePollingRequestQueueTimeoutIsReached_ForARequestBeingProcessedByTentacle_AndTheResponseIsReceivedBeforeThePollingRequestMaximumMessageProcessingTimeoutIsReached_TheRequestShouldSucceed(TentacleConfigurationTestCase tentacleConfigurationTestCase) | ||
{ | ||
var pollingRequestQueueTimeout = TimeSpan.FromSeconds(5); | ||
var buffer = TimeSpan.FromSeconds(5); | ||
|
||
await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() | ||
.WithPortForwarder() | ||
.WithRetriesDisabled() | ||
.WithServiceEndpointModifier(serviceEndpoint => | ||
{ | ||
serviceEndpoint.PollingRequestQueueTimeout = pollingRequestQueueTimeout; | ||
serviceEndpoint.PollingRequestMaximumMessageProcessingTimeout = TimeSpan.FromHours(1); | ||
}) | ||
.WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() | ||
.RecordMethodUsages<IAsyncClientCapabilitiesServiceV2>(out var capabilitiesMethodUsages) | ||
.RecordMethodUsages(tentacleConfigurationTestCase, out var scriptServiceMethodUsages) | ||
.Build()) | ||
.Build(CancellationToken); | ||
|
||
// Ensure the script takes longer than the pollingRequestQueueTimeout but less than the PollingRequestMaximumMessageProcessingTimeout | ||
var scriptDuration = pollingRequestQueueTimeout + buffer; | ||
|
||
var startScriptCommand = new LatestStartScriptCommandBuilder().WithScriptBody(new ScriptBuilder() | ||
.Sleep(scriptDuration) | ||
.Print("Script Executed")) | ||
// Allow the Start Script call to take longer than the script being executed | ||
.WithDurationStartScriptCanWaitForScriptToFinish(scriptDuration * 2) | ||
.Build(); | ||
|
||
var (finalResponse, _) = await clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, CancellationToken); | ||
|
||
finalResponse.State.Should().Be(ProcessState.Complete); | ||
finalResponse.ExitCode.Should().Be(0); | ||
|
||
capabilitiesMethodUsages.ForGetCapabilitiesAsync().Completed.Should().Be(1); | ||
scriptServiceMethodUsages.ForStartScriptAsync().Completed.Should().Be(1); | ||
scriptServiceMethodUsages.ForGetStatusAsync().Completed.Should().Be(0, "The test should have allowed StartScript long enough to complete the script, ensuring it took longer than PollingRequestQueueTimeout"); | ||
scriptServiceMethodUsages.ForCompleteScriptAsync().Completed.Should().Be(1); | ||
} | ||
|
||
[Test] | ||
[TentacleConfigurations(testListening: false)] | ||
public async Task WhenThePollingRequestMaximumMessageProcessingTimeoutIsReached_ForARequestBeingProcessedByTentacle_TheRequestShouldTimeout(TentacleConfigurationTestCase tentacleConfigurationTestCase) | ||
{ | ||
var pollingRequestQueueTimeout = TimeSpan.FromSeconds(5); | ||
var pollingRequestMaximumMessageProcessingTimeout = TimeSpan.FromSeconds(10); | ||
var buffer = TimeSpan.FromSeconds(5); | ||
|
||
await using var clientTentacle = await tentacleConfigurationTestCase.CreateBuilder() | ||
.WithPortForwarder() | ||
.WithRetriesDisabled() | ||
.WithServiceEndpointModifier(serviceEndpoint => | ||
{ | ||
serviceEndpoint.PollingRequestQueueTimeout = pollingRequestQueueTimeout; | ||
serviceEndpoint.PollingRequestMaximumMessageProcessingTimeout = pollingRequestMaximumMessageProcessingTimeout; | ||
}) | ||
.WithTentacleServiceDecorator(new TentacleServiceDecoratorBuilder() | ||
.RecordMethodUsages<IAsyncClientCapabilitiesServiceV2>(out var capabilitiesMethodUsages) | ||
.RecordMethodUsages(tentacleConfigurationTestCase, out var scriptServiceMethodUsages) | ||
.Build()) | ||
.Build(CancellationToken); | ||
|
||
// Ensure the script takes longer than the pollingRequestQueueTimeout + pollingRequestMaximumMessageProcessingTimeout | ||
var scriptDuration = pollingRequestQueueTimeout + pollingRequestMaximumMessageProcessingTimeout + buffer + buffer; | ||
|
||
var startScriptCommand = new LatestStartScriptCommandBuilder().WithScriptBody(new ScriptBuilder() | ||
.Sleep(scriptDuration) | ||
.Print("Script Executed")) | ||
// Allow the Start Script call to take longer than the script being executed | ||
.WithDurationStartScriptCanWaitForScriptToFinish(scriptDuration * 2) | ||
.Build(); | ||
|
||
(await AssertionExtensions.Should(() => clientTentacle.TentacleClient.ExecuteScript(startScriptCommand, CancellationToken)).ThrowAsync<HalibutClientException>()) | ||
.And.Message.Should().Contain("A request was sent to a polling endpoint, the polling endpoint collected it but did not respond in the allowed time (00:00:10), so the request timed out."); | ||
|
||
capabilitiesMethodUsages.ForGetCapabilitiesAsync().Completed.Should().Be(1); | ||
scriptServiceMethodUsages.ForStartScriptAsync().Completed.Should().Be(1); | ||
scriptServiceMethodUsages.ForGetStatusAsync().Completed.Should().Be(0, "The test should have allowed StartScript long enough to cause the PollingRequestMaximumMessageProcessingTimeout to elapse"); | ||
scriptServiceMethodUsages.ForCancelScriptAsync().Completed.Should().Be(0); | ||
scriptServiceMethodUsages.ForCompleteScriptAsync().Completed.Should().Be(0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO - Update when OctopusDeploy/Halibut#558 merges