Beispiel #1
0
        internal Request CreateRequest(InstrumentationOperation operation, Uri uri)
        {
            bool ReuseHandler()
            {
                if (operation.Type == InstrumentationOperationType.Primary)
                {
                    return(false);
                }

                switch (TestRunner.EffectiveType)
                {
                case HttpClientTestType.ReuseHandler:
                case HttpClientTestType.ReuseHandlerNoClose:
                case HttpClientTestType.ReuseHandlerChunked:
                case HttpClientTestType.ReuseHandlerGZip:
                    return(true);

                default:
                    return(false);
                }
            }

            if (!ReuseHandler())
            {
                return(new HttpClientRequest(
                           operation, this, uri));
            }

            var primaryRequest = (HttpClientRequest)TestRunner.PrimaryOperation.Request;

            return(new HttpClientRequest(
                       operation, this, primaryRequest, uri));
        }
Beispiel #2
0
 protected override async Task Destroy(TestContext ctx, CancellationToken cancellationToken)
 {
     currentOperation?.Dispose();
     currentOperation = null;
     queuedOperation?.Dispose();
     queuedOperation = null;
     await Server.Destroy(ctx, cancellationToken).ConfigureAwait(false);
 }
        public HttpClientRequest(
            InstrumentationOperation operation,
            HttpClientHandler handler,
            HttpClientRequest primaryRequest,
            Uri requestUri)
        {
            Operation  = operation;
            Parent     = handler;
            RequestUri = requestUri;

            Handler = primaryRequest.Handler;
            Client  = primaryRequest.Client;
        }
        public HttpClientRequest(
            InstrumentationOperation operation,
            HttpClientHandler handler,
            Uri requestUri)
        {
            Operation  = operation;
            Parent     = handler;
            RequestUri = requestUri;

            Provider = DependencyInjector.Get <IHttpClientProvider> ();
            Handler  = Provider.Create();
            Client   = Handler.CreateHttpClient();
        }
Beispiel #5
0
        public async Task Run(TestContext ctx, CancellationToken cancellationToken)
        {
            var me = $"{ME}.{nameof (Run)}()";

            ctx.LogDebug(2, $"{me}");

            var(handler, flags) = CreateHandler(ctx, true);

            ctx.LogDebug(2, $"{me}");

            currentOperation = CreateOperation(
                ctx, handler, InstrumentationOperationType.Primary, flags);

            currentOperation.Start(ctx, cancellationToken);

            try {
                await currentOperation.WaitForCompletion().ConfigureAwait(false);

                ctx.LogDebug(2, $"{me} operation done");
            } catch (Exception ex) {
                ctx.LogDebug(2, $"{me} operation failed: {ex.Message}");
                throw;
            }

            await RunSecondary(ctx, cancellationToken);

            if (QueuedOperation != null)
            {
                ctx.LogDebug(2, $"{me} waiting for queued operations.");
                try {
                    await QueuedOperation.WaitForCompletion().ConfigureAwait(false);

                    ctx.LogDebug(2, $"{me} done waiting for queued operations.");
                } catch (Exception ex) {
                    ctx.LogDebug(2, $"{me} waiting for queued operations failed: {ex.Message}.");
                    throw;
                }
            }

            Server.CloseAll();
        }