Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 753459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:53:59+00:00 2026-05-14T14:53:59+00:00

I have a client program based on LibCurl. I have run into a situation

  • 0

I have a client program based on LibCurl. I have run into a situation where on some occasions a program on the server runs longer than the configured IIS timeout. IIS then terminates the program and returns a 502 error status to the client.

I have added code to the client to capture this issue. Now, I need to find a way to prove that the change will work.

I haven’t been able to reliably reproduce the issue, so don’t have a good test case.

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:53:59+00:00Added an answer on May 14, 2026 at 2:53 pm

    This shows you, in a very simple way, how to embed a worker process in an NUnit fixture.

    You can then serve up as many errors as you like.

    Here is a sample fixture:

    using System.Net;
    using NUnit.Framework;
    
    namespace Salient.Excerpts
    {
        [TestFixture]
        public class WebHostServerFixture : WebHostServer
        {
            [TestFixtureSetUp]
            public void TestFixtureSetUp()
            {
                StartServer(@"..\..\..\..\TestSite");
    
                // is the equivalent of
                // StartServer(@"..\..\..\..\TestSite",
                // GetAvailablePort(8000, 10000, IPAddress.Loopback, true), "/", "localhost");
            }
            [TestFixtureTearDown]
            public void TestFixtureTearDown()
            {
                StopServer();
            }
    
            [Test]
            public void Test()
            {
                // while a reference to the web app under test is not necessary,
                // if you do add a reference to this test project you may F5 debug your tests.
                // if you debug this test you will break in Default.aspx.cs
                string html = new WebClient().DownloadString(NormalizeUri("Default.aspx"));
            }
        }
    }
    

    And here is the server:

    // Project: Salient
    // http://salient.codeplex.com
    // Date: April 16 2010
    
    using System;
    using System.Collections.Generic;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Net.NetworkInformation;
    using System.Threading;
    using Microsoft.VisualStudio.WebHost;
    
    namespace Salient.Excerpts
    {
        /// <summary>
        /// A general purpose Microsoft.VisualStudio.WebHost.Server test fixture.
        /// WebHost.Server is the core of the Visual Studio Development Server (WebDev.WebServer).
        ///
        /// This server is run in-process and may be used in F5 debugging.
        /// </summary>
        /// <remarks>
        /// If you are adding this source code to a new project, You will need to
        /// manually add a reference to WebDev.WebHost.dll to your project. It cannot
        /// be added from within Visual Studio.
        ///
        /// Please see the Readme.txt accompanying this code for details.
        /// </remarks>
        /// NOTE: code from various namespaces/classes in the Salient project have been merged into this
        /// single class for this post in the interest of brevity
        public class WebHostServer
        {
            private Server _server;
    
            public string ApplicationPath { get; private set; }
    
            public string HostName { get; private set; }
    
            public int Port { get; private set; }
    
            public string VirtualPath { get; private set; }
    
            public string RootUrl
            {
                get { return string.Format(CultureInfo.InvariantCulture, "http://{0}:{1}{2}", HostName, Port, VirtualPath); }
            }
    
            /// <summary>
            /// Combine the RootUrl of the running web application with the relative url specified.
            /// </summary>
            public virtual Uri NormalizeUri(string relativeUrl)
            {
                return new Uri(RootUrl + relativeUrl);
            }
    
            /// <summary>
            /// Will start "localhost" on first available port in the range 8000-10000 with vpath "/"
            /// </summary>
            /// <param name="applicationPath"></param>
            public void StartServer(string applicationPath)
            {
                StartServer(applicationPath, GetAvailablePort(8000, 10000, IPAddress.Loopback, true), "/", "localhost");
            }
    
            /// <summary>
            /// </summary>
            /// <param name="applicationPath">Physical path to application.</param>
            /// <param name="port">Port to listen on.</param>
            /// <param name="virtualPath">Optional. defaults to "/"</param>
            /// <param name="hostName">Optional. Is used to construct RootUrl. Defaults to "localhost"</param>
            public void StartServer(string applicationPath, int port, string virtualPath, string hostName)
            {
                if (_server != null)
                {
                    throw new InvalidOperationException("Server already started");
                }
    
                // WebHost.Server will not run on any other IP
                IPAddress ipAddress = IPAddress.Loopback;
    
                if(!IsPortAvailable(ipAddress, port))
                {
                    throw new Exception(string.Format("Port {0} is in use.", port));
                }
    
                applicationPath = Path.GetFullPath(applicationPath);
    
                virtualPath = String.Format("/{0}/", (virtualPath ?? string.Empty).Trim('/')).Replace("//", "/");
    
                _server = new Server(port, virtualPath, applicationPath, false, false);
                _server.Start();
    
                ApplicationPath = applicationPath;
                Port = port;
                VirtualPath = virtualPath;
                HostName = string.IsNullOrEmpty(hostName) ? "localhost" : hostName;
            }
    
            /// <summary>
            /// Stops the server.
            /// </summary>
            public void StopServer()
            {
                if (_server != null)
                {
                    _server.Stop();
                    _server = null;
                    // allow some time to release the port
                    Thread.Sleep(100);
                }
            }
    
            public void Dispose()
            {
                StopServer();
            }
    
    
           /// <summary>
            /// Gently polls specified IP:Port to determine if it is available.
            /// </summary>
            /// <param name="ipAddress"></param>
            /// <param name="port"></param>
            public static bool IsPortAvailable(IPAddress ipAddress, int port)
            {
                bool portAvailable = false;
    
                for (int i = 0; i < 5; i++)
                {
                    portAvailable = GetAvailablePort(port, port, ipAddress, true) == port;
                    if (portAvailable)
                    {
                        break;
                    }
                    // be a little patient and wait for the port if necessary,
                    // the previous occupant may have just vacated
                    Thread.Sleep(100);
                }
                return portAvailable;
            }
    
            /// <summary>
            /// Returns first available port on the specified IP address.
            /// The port scan excludes ports that are open on ANY loopback adapter.
            ///
            /// If the address upon which a port is requested is an 'ANY' address all
            /// ports that are open on ANY IP are excluded.
            /// </summary>
            /// <param name="rangeStart"></param>
            /// <param name="rangeEnd"></param>
            /// <param name="ip">The IP address upon which to search for available port.</param>
            /// <param name="includeIdlePorts">If true includes ports in TIME_WAIT state in results.
            /// TIME_WAIT state is typically cool down period for recently released ports.</param>
            /// <returns></returns>
            public static int GetAvailablePort(int rangeStart, int rangeEnd, IPAddress ip, bool includeIdlePorts)
            {
                IPGlobalProperties ipProps = IPGlobalProperties.GetIPGlobalProperties();
    
                // if the ip we want a port on is an 'any' or loopback port we need to exclude all ports that are active on any IP
                Func<IPAddress, bool> isIpAnyOrLoopBack = i => IPAddress.Any.Equals(i) ||
                                                               IPAddress.IPv6Any.Equals(i) ||
                                                               IPAddress.Loopback.Equals(i) ||
                                                               IPAddress.IPv6Loopback.
                                                                   Equals(i);
                // get all active ports on specified IP.
                List<ushort> excludedPorts = new List<ushort>();
    
                // if a port is open on an 'any' or 'loopback' interface then include it in the excludedPorts
                excludedPorts.AddRange(from n in ipProps.GetActiveTcpConnections()
                                       where
                                           n.LocalEndPoint.Port >= rangeStart &&
                                           n.LocalEndPoint.Port <= rangeEnd && (
                                           isIpAnyOrLoopBack(ip) || n.LocalEndPoint.Address.Equals(ip) ||
                                            isIpAnyOrLoopBack(n.LocalEndPoint.Address)) &&
                                            (!includeIdlePorts || n.State != TcpState.TimeWait)
                                       select (ushort)n.LocalEndPoint.Port);
    
                excludedPorts.AddRange(from n in ipProps.GetActiveTcpListeners()
                                       where n.Port >= rangeStart && n.Port <= rangeEnd && (
                                       isIpAnyOrLoopBack(ip) || n.Address.Equals(ip) || isIpAnyOrLoopBack(n.Address))
                                       select (ushort)n.Port);
    
                excludedPorts.AddRange(from n in ipProps.GetActiveUdpListeners()
                                       where n.Port >= rangeStart && n.Port <= rangeEnd && (
                                       isIpAnyOrLoopBack(ip) || n.Address.Equals(ip) || isIpAnyOrLoopBack(n.Address))
                                       select (ushort)n.Port);
    
                excludedPorts.Sort();
    
                for (int port = rangeStart; port <= rangeEnd; port++)
                {
                    if (!excludedPorts.Contains((ushort)port))
                    {
                        return port;
                    }
                }
    
                return 0;
            }
        }
    }
    

    One caveat:

    NOTE: The Microsoft.VisualStudio.WebHost namespace is contained in the file WebDev.WebHost.dll. This file is in the GAC but it is not possible to add a reference to this assembly from within Visual Studio.

    To add a reference you will need to open your .csproj file in a text editor and add the reference manually.

    Look for the ItemGroup that contains the project references and add the following element:

    <Reference Include="WebDev.WebHost, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=x86">
      <Private>False</Private>
    </Reference> 
    

    Reference: http://www.codeproject.com/KB/aspnet/test-with-vs-devserver-2.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 434k
  • Answers 434k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First, and most important - all Spring beans are managed… May 15, 2026 at 3:17 pm
  • Editorial Team
    Editorial Team added an answer I haven't used this particular one, but this CheckThreadViolationRepaintManager should… May 15, 2026 at 3:17 pm
  • Editorial Team
    Editorial Team added an answer Yes: disable Tools\Options\Text Editor\your language here\Enable single click URL navigation… May 15, 2026 at 3:17 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.