-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #590 from Particular/fix-hanging-callbacks-3
When actual response type does not match the expected type, callback tasks hang indefinitely
- Loading branch information
Showing
5 changed files
with
194 additions
and
3 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
...us.Callbacks.AcceptanceTests/When_controlmessage_response_does_not_match_expected_type.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,81 @@ | ||
namespace NServiceBus.Callbacks.AcceptanceTests | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AcceptanceTesting; | ||
using NUnit.Framework; | ||
|
||
public class When_controlmessage_response_does_not_match_expected_type : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public async Task Should_fail_the_request_task() | ||
{ | ||
Exception exception = null; | ||
Task requestTask = null; | ||
|
||
await Scenario.Define<Context>() | ||
.WithEndpoint<Replier>() | ||
.WithEndpoint<EndpointWithLocalCallback>(b => b.When(async (bus, ctx) => | ||
{ | ||
try | ||
{ | ||
requestTask = bus.Request<MyResponse>(new MyRequest()); | ||
|
||
await requestTask; | ||
} | ||
catch (Exception e) | ||
{ | ||
exception = e; | ||
} | ||
}).DoNotFailOnErrorMessages()) | ||
.Done(c => exception != null) | ||
.Run(); | ||
|
||
Assert.AreEqual(TaskStatus.Faulted, requestTask.Status); | ||
Assert.IsNotNull(exception); | ||
Assert.AreEqual(typeof(ArgumentException), exception.GetType()); | ||
} | ||
|
||
class Context : ScenarioContext | ||
{ | ||
} | ||
|
||
class Replier : EndpointConfigurationBuilder | ||
{ | ||
public Replier() | ||
{ | ||
EndpointSetup<DefaultServer>(c => c.EnableCallbacks(makesRequests: false)); | ||
} | ||
|
||
public class MyRequestHandler : IHandleMessages<MyRequest> | ||
{ | ||
public Task Handle(MyRequest message, IMessageHandlerContext context) | ||
{ | ||
return context.Reply(42); | ||
} | ||
} | ||
} | ||
|
||
class EndpointWithLocalCallback : EndpointConfigurationBuilder | ||
{ | ||
public EndpointWithLocalCallback() | ||
{ | ||
EndpointSetup<DefaultServer>(c => | ||
{ | ||
c.MakeInstanceUniquelyAddressable("1"); | ||
c.EnableCallbacks(); | ||
c.ConfigureTransport().Routing().RouteToEndpoint(typeof(MyRequest), typeof(Replier)); | ||
}); | ||
} | ||
} | ||
|
||
public class MyRequest : IMessage | ||
{ | ||
} | ||
|
||
public class MyResponse : IMessage | ||
{ | ||
} | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...erviceBus.Callbacks.AcceptanceTests/When_message_response_does_not_match_expected_type.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,85 @@ | ||
namespace NServiceBus.Callbacks.AcceptanceTests | ||
{ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using AcceptanceTesting; | ||
using NUnit.Framework; | ||
|
||
public class When_message_response_does_not_match_expected_type : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public async Task Should_fail_the_request_task() | ||
{ | ||
Exception exception = null; | ||
Task requestTask = null; | ||
|
||
await Scenario.Define<Context>() | ||
.WithEndpoint<Replier>() | ||
.WithEndpoint<EndpointWithLocalCallback>(b => b.When(async (bus, ctx) => | ||
{ | ||
try | ||
{ | ||
requestTask = bus.Request<MyResponse>(new MyRequest()); | ||
|
||
await requestTask; | ||
} | ||
catch (Exception e) | ||
{ | ||
exception = e; | ||
} | ||
}).DoNotFailOnErrorMessages()) | ||
.Done(c => exception != null) | ||
.Run(); | ||
|
||
Assert.AreEqual(TaskStatus.Faulted, requestTask.Status); | ||
Assert.IsNotNull(exception); | ||
Assert.AreEqual(typeof(InvalidCastException), exception.GetType()); | ||
} | ||
|
||
class Context : ScenarioContext | ||
{ | ||
} | ||
|
||
class Replier : EndpointConfigurationBuilder | ||
{ | ||
public Replier() | ||
{ | ||
EndpointSetup<DefaultServer>(); | ||
} | ||
|
||
public class MyRequestHandler : IHandleMessages<MyRequest> | ||
{ | ||
public Task Handle(MyRequest message, IMessageHandlerContext context) | ||
{ | ||
return context.Reply(new BadResponse()); | ||
} | ||
} | ||
} | ||
|
||
class EndpointWithLocalCallback : EndpointConfigurationBuilder | ||
{ | ||
public EndpointWithLocalCallback() | ||
{ | ||
EndpointSetup<DefaultServer>(c => | ||
{ | ||
c.MakeInstanceUniquelyAddressable("1"); | ||
c.EnableCallbacks(); | ||
c.ConfigureTransport().Routing().RouteToEndpoint(typeof(MyRequest), typeof(Replier)); | ||
}); | ||
} | ||
} | ||
|
||
public class MyRequest : IMessage | ||
{ | ||
} | ||
|
||
public class MyResponse : IMessage | ||
{ | ||
} | ||
|
||
public class BadResponse : IMessage | ||
{ | ||
} | ||
} | ||
} |
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
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
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