コード例 #1
0
        public void ClientRetriesConnectionInStreamingModeWithNonFatalError()
        {
            var failThenSucceedHandler = Handlers.Sequential(Error503Response, ValidStreamingResponse);

            using (var streamServer = HttpServer.Start(failThenSucceedHandler))
            {
                var config = BasicConfig()
                             .DataSource(Components.StreamingDataSource())
                             .ServiceEndpoints(Components.ServiceEndpoints().Streaming(streamServer.Uri))
                             .StartWaitTime(TimeSpan.FromSeconds(5))
                             .Build();

                using (var client = new LdClient(config))
                {
                    Assert.True(client.Initialized);
                    Assert.Equal(DataSourceState.Valid, client.DataSourceStatusProvider.Status.State);

                    var value = client.BoolVariation(AlwaysTrueFlag.Key, BasicUser, false);
                    Assert.True(value);

                    var request1 = streamServer.Recorder.RequireRequest();
                    var request2 = streamServer.Recorder.RequireRequest();
                    Assert.Equal(BasicSdkKey, request1.Headers.Get("Authorization"));
                    Assert.Equal(BasicSdkKey, request2.Headers.Get("Authorization"));

                    Assert.NotEmpty(LogCapture.GetMessages().Where(
                                        m => m.Level == Logging.LogLevel.Warn && m.Text.Contains("error 503") &&
                                        m.Text.Contains("will retry")));
                    Assert.Empty(LogCapture.GetMessages().Where(m => m.Level == Logging.LogLevel.Error));
                }
            }
        }
コード例 #2
0
        internal static void VerifyCapturedOutput(LogLevel outputLevel,
                                                  LogLevel enableLevel, string logName, LogCapture capture)
        {
            var messages = capture.GetMessages();
            var strings  = capture.GetMessageStrings();

            if (enableLevel > outputLevel)
            {
                Assert.Empty(messages);
                Assert.Empty(strings);
            }
            else
            {
                var expectedMessages = new List <LogCapture.Message>
                {
                    new LogCapture.Message(logName, outputLevel, SimpleMessage),
                    new LogCapture.Message(logName, outputLevel, MessageFormat1Result),
                    new LogCapture.Message(logName, outputLevel, MessageFormat2Result),
                    new LogCapture.Message(logName, outputLevel, MessageFormat3Result)
                };
                var prefix = string.IsNullOrEmpty(logName) ?
                             outputLevel.Uppercase() + ": " :
                             "[" + logName + "] " + outputLevel.Uppercase() + ": ";
                var expectedStrings = new List <string>
                {
                    prefix + SimpleMessage,
                    prefix + MessageFormat1Result,
                    prefix + MessageFormat2Result,
                    prefix + MessageFormat3Result
                };
                Assert.Equal(expectedMessages, messages);
                Assert.Equal(expectedStrings, strings);
            }
        }
コード例 #3
0
        public void ClientFailsToStartInStreamingModeWith401Error()
        {
            using (var streamServer = HttpServer.Start(Error401Response))
            {
                var config = BasicConfig()
                             .DataSource(Components.StreamingDataSource())
                             .ServiceEndpoints(Components.ServiceEndpoints().Streaming(streamServer.Uri))
                             .StartWaitTime(TimeSpan.FromSeconds(5))
                             .Build();

                using (var client = new LdClient(config))
                {
                    Assert.False(client.Initialized);
                    Assert.Equal(DataSourceState.Off, client.DataSourceStatusProvider.Status.State);

                    var value = client.BoolVariation(AlwaysTrueFlag.Key, BasicUser, false);
                    Assert.False(value);

                    var request = streamServer.Recorder.RequireRequest();
                    Assert.Equal(BasicSdkKey, request.Headers.Get("Authorization"));

                    Assert.NotEmpty(LogCapture.GetMessages().Where(
                                        m => m.Level == Logging.LogLevel.Error && m.Text.Contains("error 401") &&
                                        m.Text.Contains("giving up permanently")));
                }
            }
        }
コード例 #4
0
        public void ClientStartupMessage()
        {
            var config = BasicConfig().Build();

            using (var client = new LdClient(config))
            {
                AssertLogMessage(true, LogLevel.Info,
                                 "Starting LaunchDarkly client " + AssemblyVersions.GetAssemblyVersionStringForType(typeof(LdClient)));
                Assert.All(LogCapture.GetMessages(), m => m.LoggerName.StartsWith(LogNames.DefaultBase));
            }
        }
コード例 #5
0
        public void CanCustomizeBaseLoggerName()
        {
            var customLoggerName = "abcdef";
            var config           = BasicConfig()
                                   .Logging(Components.Logging(TestLogging).BaseLoggerName(customLoggerName))
                                   .Build();

            using (var client = new LdClient(config))
            {
                Assert.All(LogCapture.GetMessages(), m => m.LoggerName.StartsWith(customLoggerName));
            }
        }
コード例 #6
0
        public void OutageTimeoutLogging()
        {
            var outageTimeout = TimeSpan.FromMilliseconds(100);

            var updates = new DataSourceUpdatesImpl(
                store,
                dataStoreStatusProvider,
                BasicTaskExecutor,
                TestLogger,
                outageTimeout
                );

            // simulate an outage
            updates.UpdateStatus(DataSourceState.Interrupted, DataSourceStatus.ErrorInfo.FromHttpError(500));

            // but recover from it immediately
            updates.UpdateStatus(DataSourceState.Valid, null);

            // wait until the timeout would have elapsed - no special message should be logged
            Thread.Sleep(outageTimeout.Add(TimeSpan.FromMilliseconds(50)));

            // simulate another outage
            updates.UpdateStatus(DataSourceState.Interrupted, DataSourceStatus.ErrorInfo.FromHttpError(501));
            updates.UpdateStatus(DataSourceState.Interrupted, DataSourceStatus.ErrorInfo.FromHttpError(502));
            updates.UpdateStatus(DataSourceState.Interrupted,
                                 DataSourceStatus.ErrorInfo.FromException(new IOException("x")));
            updates.UpdateStatus(DataSourceState.Interrupted, DataSourceStatus.ErrorInfo.FromHttpError(501));

            Thread.Sleep(outageTimeout);
            AssertEventually(TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(50), () =>
            {
                var messages = LogCapture.GetMessages().Where(m => m.Level == LogLevel.Error).ToList();
                if (messages.Count == 1)
                {
                    var m = messages[0];
                    if (m.LoggerName == ".DataSource" &&
                        m.Text.Contains("NETWORK_ERROR (1 time)") &&
                        m.Text.Contains("ERROR_RESPONSE(501) (2 times)") &&
                        m.Text.Contains("ERROR_RESPONSE(502) (1 time)"))
                    {
                        return(true);
                    }
                }
                return(false);
            }
                             );
        }
コード例 #7
0
        public void ClientStartsInStreamingMode()
        {
            using (var streamServer = HttpServer.Start(ValidStreamingResponse))
            {
                var config = BasicConfig()
                             .DataSource(Components.StreamingDataSource())
                             .ServiceEndpoints(Components.ServiceEndpoints().Streaming(streamServer.Uri))
                             .StartWaitTime(TimeSpan.FromSeconds(5))
                             .Build();

                using (var client = new LdClient(config))
                {
                    VerifyClientStartedAndHasExpectedData(client, streamServer);

                    Assert.Empty(LogCapture.GetMessages().Where(m => m.Level == Logging.LogLevel.Warn));
                    Assert.Empty(LogCapture.GetMessages().Where(m => m.Level == Logging.LogLevel.Error));
                }
            }
        }
コード例 #8
0
        public void ClientStartsInPollingMode()
        {
            using (var pollServer = HttpServer.Start(ValidPollingResponse))
            {
                var config = BasicConfig()
                             .DataSource(Components.PollingDataSource())
                             .ServiceEndpoints(Components.ServiceEndpoints().Polling(pollServer.Uri))
                             .StartWaitTime(TimeSpan.FromSeconds(5))
                             .Build();

                using (var client = new LdClient(config))
                {
                    VerifyClientStartedAndHasExpectedData(client, pollServer);

                    Assert.NotEmpty(LogCapture.GetMessages().Where(
                                        m => m.Level == Logging.LogLevel.Warn &&
                                        m.Text.Contains("You should only disable the streaming API if instructed to do so")));
                    Assert.Empty(LogCapture.GetMessages().Where(m => m.Level == Logging.LogLevel.Error));
                }
            }
        }