-
-
Notifications
You must be signed in to change notification settings - Fork 214
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
Feature: Please provide support for Bad responses. #343
Comments
What kind of bad responses do you need? |
I was referring to the bad responses described as: EMPTY_RESPONSE: Return a completely empty response. |
Something like: server
.Given(Request.Create().WithPath("/x")
.RespondWith(Response.Create()
.WithBody("OK")
.WithFault(Faults.EMPTY_RESPONSE, 0.1)
); This will return an empty response 1 on 10 times. This code will always return an empty response... server
.Given(Request.Create().WithPath("/x")
.RespondWith(Response.Create()
.WithFault(Faults.EMPTY_RESPONSE)
); Is this an idea? |
Yea, that would be cool. |
About :
|
I agree with you that sending 200 OK and closing connection is enough. |
@grzegorz-wolszczak |
@grzegorz-wolszczak Can you please test this preview and report back your findings? |
Hi Stef |
How should I test new library ? What new Api was introduced to handle cases like: I was trying to find some methods on IResponseBuilder interface but I did not see anything that would map to the responses I've described in my feature request. I tried to grep your git commit history by the issue number (#343) but also could not find any. In which commit (or commits) did you introduce changes for this issue? I will look into it and figure out the rest. |
1] 2] 3a] 3b] {
"Guid": "a51b78ac-1300-4125-aa97-d48953deef77",
"Priority": 0,
"Request": {
"Path": {
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "/fault",
"IgnoreCase": false
}
]
},
"Body": {}
},
"Response": {
"StatusCode": 200,
"BodyAsJson": {
"x": "x"
},
"Fault": { "Type": "RANDOM_DATA_THEN_CLOSE", "Percentage": 0.999999 },
"UseTransformer": false,
"Headers": {
"Content-Type": "application/json"
}
}
} |
Ok, now i See what the problem was, I have chosen wrong nuget version. So I've tested but for FaultType.MALFORMED_RESPONSE_CHUNK when request GET I got: and body
I guess this is intended ? Also what about 'most interesting' fault type , which is CONNECTION_RESET_BY_PEER ? There was no enum value for it. Apart from that, everything is great :) |
About malformed response , this should not throw a 500. |
I found the issue. Please try MyGet : WireMock.Net.1.0.32-ci-12060 |
The code I used was (simplified version I found on your's project wiki): using System;
using Newtonsoft.Json;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;
using WireMock.Server;
namespace TestingWireMock
{
class Program
{
static void Main(string[] args)
{
int port;
if (args.Length == 0 || !int.TryParse(args[0], out port))
port = 18080;
var server = FluentMockServer.Start(port);
Console.WriteLine("FluentMockServer running at {0}", string.Join(",", server.Ports));
server
.Given(Request.Create().WithPath(u => u.Contains("x")).UsingGet())
.RespondWith(Response.Create()
.WithStatusCode(200)
.WithHeader("Content-Type", "application/json")
.WithBody(@"{ ""result"": ""/x with FUNC 200""}"));
server
.Given(Request.Create().WithPath("/*").UsingGet())
.RespondWith(Response.Create().WithFault(FaultType.MALFORMED_RESPONSE_CHUNK));
Console.WriteLine("Press any key to stop the server");
Console.ReadKey();
Console.WriteLine("Displaying all requests");
var allRequests = server.LogEntries;
Console.WriteLine(JsonConvert.SerializeObject(allRequests, Formatting.Indented));
Console.WriteLine("Press any key to quit");
Console.ReadKey();
}
}
} I've used nuget version: WireMock.Net.1.0.32-ci-12002.nupkg |
Thanks. |
WireMock.Net.1.0.32-ci-12060 works. From what I can understand in http://wiremock.org/docs/simulating-faults/ in 'Bad responses' section. |
1] There is a difference. 2] RANDOM_DATA_THEN_CLOSE should not write any header. However, maybe the default header is 200. |
@grzegorz-wolszczak Does my comment make sense? |
With MALFORMED_RESPONSE_CHUNK it makes sense. |
With the current code and setup, I don't think I can really generate random data (TCP packet) instead of an HTTP message. But I will investigate. |
I understand that this might be very difficult or event impossible. Probably Kestrel does not allow of such low-level packet manipulation. If so I would remove the RANDOM_DATA_THEN_CLOSE from the solution utill you figure out how to achieve it. Apart from that , the rest of your code brings new value to WireMock library so I would merge it. |
Merged to master and a new NuGet will be released shortly. |
Hi.
I can see that WireMock-Net already supports delayed responses, but
it would be even more cool if WireMock-Net supported simulating bad responses as in
http://wiremock.org/docs/simulating-faults/
The text was updated successfully, but these errors were encountered: