Esempio n. 1
0
    private static void Run(bool httpSys, int concurrentRequests, int maxContentLength, Version[] httpVersions, int?connectionLifetime, int[] opIndices, string logPath, bool aspnetLog, bool listOps, int seed, int numParameters, double cancellationProbability)
    {
        // Handle command-line arguments.
        EventListener listener =
            logPath == null ? null :
            new HttpEventListener(logPath != "console" ? new StreamWriter(logPath)
        {
            AutoFlush = true
        } : null);

        if (listener == null)
        {
            // If no command-line requested logging, enable the user to press 'L' to enable logging to the console
            // during execution, so that it can be done just-in-time when something goes awry.
            new Thread(() =>
            {
                while (true)
                {
                    if (Console.ReadKey(intercept: true).Key == ConsoleKey.L)
                    {
                        listener = new HttpEventListener();
                        break;
                    }
                }
            })
            {
                IsBackground = true
            }.Start();
        }

        string       contentSource = string.Concat(Enumerable.Repeat("1234567890", maxContentLength / 10));
        const int    DisplayIntervalMilliseconds = 1000;
        const int    HttpsPort          = 5001;
        const string LocalhostName      = "localhost";
        string       serverUri          = $"https://{LocalhostName}:{HttpsPort}";
        int          maxRequestLineSize = -1;

        // Validation of a response message
        void ValidateResponse(HttpResponseMessage m, Version expectedVersion)
        {
            if (m.Version != expectedVersion)
            {
                throw new Exception($"Expected response version {expectedVersion}, got {m.Version}");
            }
        }

        void ValidateContent(string expectedContent, string actualContent, string details = null)
        {
            if (actualContent != expectedContent)
            {
                throw new Exception($"Expected response content \"{expectedContent}\", got \"{actualContent}\". {details}");
            }
        }

        // Set of operations that the client can select from to run.  Each item is a tuple of the operation's name
        // and the delegate to invoke for it, provided with the HttpClient instance on which to make the call and
        // returning asynchronously the retrieved response string from the server.  Individual operations can be
        // commented out from here to turn them off, or additional ones can be added.
        var clientOperations = new (string, Func <RequestContext, Task>)[]
Esempio n. 2
0
        public static void Main(string[] args)
        {
            using var listener = new HttpEventListener();

            RunOnlyServer();
        }