2

My problem is for how do i test a Webrequest timeout . My C# code is making a SOAP service call to a 3rd party vendor whose code i do not have . When their service goes down , most of my application URLs also go down as well.

So I thought of adding a timeout ; and read this blog as well which was helpful , but what would be the best way to test my code ?

Adjusting HttpWebRequest Connection Timeout in C#

HungryProgrammer
  • 165
  • 1
  • 2
  • 11

3 Answers3

2

I had the same problem and solved it using https://httpstat.us/

In my case I needed a 60 secs timeout so I made my request to https://httpstat.us/200?sleep=120000 and it worked.

Posted in case it is useful for anyone.

Cheers.

achecopar
  • 421
  • 1
  • 11
  • 20
0

Try connecting to an existing internet address but without using a standard port - a port where no service is running. This way the firewall should drop the packet and you should receive a timeout.

Eg. Use one of the big internet players but instead of port 80 (http) or 443 (https) use 354

dsdel
  • 1,042
  • 1
  • 8
  • 11
  • Tried with https://google.com:354 and it throws an error saying nobody is listening, what am I doing wrong? – achecopar Apr 15 '20 at 19:08
0

You can build a wrapper around the third part call and use the interface to mock your calls made to the third party so that you can return what you are expecting.

Fancy5g
  • 99
  • 4