<commit_before>﻿using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using AI;
using FunctionalTestUtils;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Xunit;
using Xunit.Abstractions;

namespace WebApi20.FuncTests
{
    public class MultipleWebHostsTests : TelemetryTestsBase
    {
        private const string assemblyName = "WebApi20.FunctionalTests20";
        private const string requestPath = "/api/dependency";
        
        public MultipleWebHostsTests(ITestOutputHelper output) : base(output)
        {
        }

        [Fact]
        public void TwoWebHostsCreatedSequentially()
        {
            using (var server1 = new InProcessServer(assemblyName, this.output))
            {
                this.ExecuteRequest(server1.BaseHost + requestPath);
                var telemetry = server1.Listener.ReceiveItems(TestListenerTimeoutInMs);
                this.DebugTelemetryItems(telemetry);

                Assert.Single(telemetry.Where(t => t is TelemetryItem<RequestData>));
                Assert.Single(telemetry.Where(IsServiceDependencyCall));
                Assert.DoesNotContain(telemetry, t => t is TelemetryItem<ExceptionData>);

                var request = telemetry.Single(t => t is TelemetryItem<RequestData>);
                Assert.Equal("200", ((TelemetryItem<RequestData>)request).data.baseData.responseCode);
            }

            using (var server2 = new InProcessServer(assemblyName, this.output))
            {
                this.ExecuteRequest(server2.BaseHost + requestPath);
                var telemetry = server2.Listener.ReceiveItems(TestListenerTimeoutInMs);
                this.DebugTelemetryItems(telemetry);

                Assert.Single(telemetry.Where(t => t is TelemetryItem<RequestData>));
                Assert.Single(telemetry.Where(IsServiceDependencyCall));
                Assert.DoesNotContain(telemetry, t => t is TelemetryItem<ExceptionData>);

                var request = telemetry.Single(t => t is TelemetryItem<RequestData>);
                Assert.Equal("200", ((TelemetryItem<RequestData>)request).data.baseData.responseCode);
            }
        }

        [Fact]
        public void TwoWebHostsCreatedInParallel()
        {
            using (var server1 = new InProcessServer(assemblyName, this.output))
            using (var server2 = new InProcessServer(assemblyName, this.output))
            {
                this.ExecuteRequest(server1.BaseHost + requestPath);
                this.ExecuteRequest(server2.BaseHost + requestPath);

                var telemetry1 = server1.Listener.ReceiveItems(TestListenerTimeoutInMs);
                var telemetry2 = server2.Listener.ReceiveItems(TestListenerTimeoutInMs);

                this.output.WriteLine("~~telemetry1~~");
                this.DebugTelemetryItems(telemetry1);
                this.output.WriteLine("~~telemetry2~~");
                this.DebugTelemetryItems(telemetry2);

                // we don't know which host reported requests
                Assert.True(2 == telemetry1.Count(t => t is TelemetryItem<RequestData>) ||
                            2 == telemetry2.Count(t => t is TelemetryItem<RequestData>));

                // we don't know which host reported dependencies
                Assert.True(2 == telemetry1.Count(IsServiceDependencyCall) ||
                            2 == telemetry2.Count(IsServiceDependencyCall));
<commit_msg>revert<commit_after>﻿using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using AI;
using FunctionalTestUtils;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Xunit;
using Xunit.Abstractions;

namespace WebApi20.FuncTests
{
    public class MultipleWebHostsTests : TelemetryTestsBase
    {
        private const string assemblyName = "WebApi20.FunctionalTests20";
        private const string requestPath = "/api/dependency";
        
        public MultipleWebHostsTests(ITestOutputHelper output) : base(output)
        {
        }

        [Fact(Skip = "Re-Enable once DependencyTrackingModule is updated to latest DiagnosticSource.")]
        public void TwoWebHostsCreatedSequentially()
        {
            using (var server1 = new InProcessServer(assemblyName, this.output))
            {
                this.ExecuteRequest(server1.BaseHost + requestPath);
                var telemetry = server1.Listener.ReceiveItems(TestListenerTimeoutInMs);
                this.DebugTelemetryItems(telemetry);

                Assert.Single(telemetry.Where(t => t is TelemetryItem<RequestData>));
                Assert.Single(telemetry.Where(IsServiceDependencyCall));
                Assert.DoesNotContain(telemetry, t => t is TelemetryItem<ExceptionData>);

                var request = telemetry.Single(t => t is TelemetryItem<RequestData>);
                Assert.Equal("200", ((TelemetryItem<RequestData>)request).data.baseData.responseCode);
            }

            using (var server2 = new InProcessServer(assemblyName, this.output))
            {
                this.ExecuteRequest(server2.BaseHost + requestPath);
                var telemetry = server2.Listener.ReceiveItems(TestListenerTimeoutInMs);
                this.DebugTelemetryItems(telemetry);

                Assert.Single(telemetry.Where(t => t is TelemetryItem<RequestData>));
                Assert.Single(telemetry.Where(IsServiceDependencyCall));
                Assert.DoesNotContain(telemetry, t => t is TelemetryItem<ExceptionData>);

                var request = telemetry.Single(t => t is TelemetryItem<RequestData>);
                Assert.Equal("200", ((TelemetryItem<RequestData>)request).data.baseData.responseCode);
            }
        }

        [Fact(Skip = "Re-Enable once DependencyTrackingModule is updated to latest DiagnosticSource.")]
        public void TwoWebHostsCreatedInParallel()
        {
            using (var server1 = new InProcessServer(assemblyName, this.output))
            using (var server2 = new InProcessServer(assemblyName, this.output))
            {
                this.ExecuteRequest(server1.BaseHost + requestPath);
                this.ExecuteRequest(server2.BaseHost + requestPath);

                var telemetry1 = server1.Listener.ReceiveItems(TestListenerTimeoutInMs);
                var telemetry2 = server2.Listener.ReceiveItems(TestListenerTimeoutInMs);

                this.output.WriteLine("~~telemetry1~~");
                this.DebugTelemetryItems(telemetry1);
                this.output.WriteLine("~~telemetry2~~");
                this.DebugTelemetryItems(telemetry2);

                // we don't know which host reported requests
                Assert.True(2 == telemetry1.Count(t => t is TelemetryItem<RequestData>) ||
                            2 == telemetry2.Count(t => t is TelemetryItem<RequestData>));

                // we don't know which host reported dependencies
                Assert.True(2 == telemetry1.Count(IsServiceDependencyCall) ||
                            2 == telemetry2.Count(IsServiceDependencyCall));

{'fraction_non_alphanumeric': 0.09250175192711983, 'fraction_numerical': 0.010651716888577436, 'mean_word_length': 2.4826744753538312, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3021399', 'n_tokens_mistral': 1864, 'n_tokens_neox': 1751, 'n_words': 336}