public void LibraryTests_LibraryCleansUpInputWhileStopping()

in src/LibraryTest/Library/LibraryTests.cs [262:305]


        public void LibraryTests_LibraryCleansUpInputWhileStopping()
        {
            // ARRANGE
            int port = Common.GetPort();

            var config = $@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<Configuration>
    <Host>0.0.0.0</Host>
    <Port>{port}</Port>
    <InstrumentationKey>[SPECIFY INSTRUMENTATION KEY HERE]</InstrumentationKey>
    <LiveMetricsStreamAuthenticationApiKey></LiveMetricsStreamAuthenticationApiKey>
    <AdaptiveSampling Enabled=""true"">
      <MaxEventsPerSecond>%ISTIO_MIXER_PLUGIN_AI_ADAPTIVE_SAMPLING_EVENTS_LIMIT%</MaxEventsPerSecond>
      <!--Telemetry items other than events are counted together-->
      <MaxOtherItemsPerSecond>%ISTIO_MIXER_PLUGIN_AI_ADAPTIVE_SAMPLING_LIMIT%</MaxOtherItemsPerSecond>
    </AdaptiveSampling>
</Configuration>
";

            var lib = new Library(config);
            lib.Run();

            var client = new TcpClient("localhost", port);
            
            Common.AssertIsTrueEventually(() => client.Connected, LongTimeout);

            // ACT
            lib.Stop();

            // ASSERT
            // check which ports are in use (listened on)
            client = null;
            
            try
            {
                client = new TcpClient("localhost", port);
            }
            catch (Exception)
            {
                // swallow
            }

            Assert.IsNull(client);
        }