[C#] WebClient timeout while doing unit tests

xwilarg's Avatar

xwilarg

19 Jul, 2018 07:29 PM

Hi,
I'm using AppVeyor to launch C# unit tests made with XUnit.
I had a few timeout in my code that I wasn't able to reproduce (the timeout is from a WebClient)
Then I saw here https://xunit.github.io/docs/running-tests-in-parallel that you can separate your unit tests in different class to make them run in parallel but since I did this I have even more timeout.
Here's a link to my appveyor.yml: https://github.com/Xwilarg/BooruSharp/blob/master/appveyor.yml
And here's the code of the unit tests: https://github.com/Xwilarg/BooruSharp/blob/master/BooruSharp.UnitTests/Program.cs

I don't think the problem is from my code because when I'm trying it myself I don't have any problem.
(And because I got even more time out since I separated the unit tests into many class)

So if someone would know why the problem occured I would really appreciate :)

Thanks in advance!

  1. Support Staff 1 Posted by Ilya Finkelshte... on 19 Jul, 2018 10:28 PM

    Ilya Finkelshteyn's Avatar

    Can you please send a link to the specific build which had this issue?

  2. 2 Posted by xwilarg on 19 Jul, 2018 11:03 PM

    xwilarg's Avatar
  3. Support Staff 3 Posted by Owen McDonnell on 20 Jul, 2018 03:34 PM

    Owen McDonnell's Avatar

    On my local machine I called a couple of the urls from your failing tests from a powershell WebClient and they returned quickly and without error, so i tried the same script on AppVeyor with one url and that also worked.
    So then, I cloned your repo locally, built and ran tests but hit the same WebClient timeout errors as your project does on AppVeyor.

    How are you running your tests locally? I see that xunit console runner is not part of your packages.config.

  4. 4 Posted by xwilarg on 20 Jul, 2018 04:51 PM

    xwilarg's Avatar

    XUnit is available at a NuGet package
    https://github.com/Xwilarg/BooruSharp/blob/master/BooruSharp.UnitTests/BooruSharp.UnitTests.csproj#L44
    Then I can just open Windows PowerShell and do:
    OpenCover.Console.exe -register:user -target:"xunit.console.x86.exe" -targetargs:".\BooruSharp.UnitTests\bin\Debug\BooruSharp.UnitTests.dll -noshadow" -filter:"+[BooruSharp*]* -[BooruSharp.UnitTests*]*" -output:".\MyProject_coverage.xml"
    (More informations here: https://github.com/codecov/example-csharp)

    But indeed, I think I should post in XUnit forums instead of here, since it's seam more related to XUnit.

  5. Support Staff 5 Posted by Owen McDonnell on 20 Jul, 2018 06:06 PM

    Owen McDonnell's Avatar

    Well, I did get the same errors when i ran the tests just with xunit console runner as well.
    I was not able to make the command you mentioned work. I got Target 'xunit.console.x86.exe' cannot be found - have you specified your arguments correctly? error.

  6. 6 Posted by xwilarg on 20 Jul, 2018 06:35 PM

    xwilarg's Avatar

    Oh, sorry, you need to do this to install xunit in your powershell: choco install xunit

  7. 7 Posted by xwilarg on 20 Jul, 2018 10:01 PM

    xwilarg's Avatar

    I found the solution of my problem.
    I'm not using a HttpClient instead of a WebClient and it's working perfectly.

  8. xwilarg closed this discussion on 20 Jul, 2018 10:01 PM.

  9. Owen McDonnell re-opened this discussion on 20 Jul, 2018 10:29 PM

  10. Support Staff 8 Posted by Owen McDonnell on 20 Jul, 2018 10:29 PM

    Owen McDonnell's Avatar

    Ah, of course. That got it to run.
    Yet I still get the same timeout errors. I've tested several other url's that cause errors in the tests and a web browser hits them fine.

  11. Support Staff 9 Posted by Owen McDonnell on 20 Jul, 2018 10:30 PM

    Owen McDonnell's Avatar

    Oh sorry, missed your last response.
    I was actually going to suggest using HttpWebRequest class next.
    Looks like you got it sorted anyway.

  12. Ilya Finkelshteyn closed this discussion on 20 Sep, 2018 09:00 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

Recent Discussions

23 Oct, 2018 10:37 PM
23 Oct, 2018 08:45 PM
23 Oct, 2018 07:48 PM
23 Oct, 2018 06:50 PM
23 Oct, 2018 06:06 PM