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));
                }
            }
        }
        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")));
                }
            }
        }
        private static void VerifyClientStartedAndHasExpectedData(LdClient client, HttpServer server)
        {
            Assert.Equal(DataSourceState.Valid, client.DataSourceStatusProvider.Status.State);
            Assert.True(client.Initialized);

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

            Assert.True(value);

            var request = server.Recorder.RequireRequest();

            Assert.Equal(BasicSdkKey, request.Headers.Get("Authorization"));
        }
Exemple #4
0
        public void OfflineClientGetsFlagFromDataStore()
        {
            var dataStore = new InMemoryDataStore();

            TestUtils.UpsertFlag(dataStore,
                                 new FeatureFlagBuilder("key").OffWithValue(LdValue.Of(true)).Build());
            var config = BasicConfig()
                         .Offline(true)
                         .DataStore(dataStore.AsSingletonFactory())
                         .Build();

            using (var client = new LdClient(config))
            {
                Assert.True(client.BoolVariation("key", User.WithKey("user"), false));
            }
        }
        public void LddModeClientGetsFlagFromDataStore()
        {
            var dataStore = new InMemoryDataStore();

            TestUtils.UpsertFlag(dataStore,
                                 new FeatureFlagBuilder("key").OffWithValue(LdValue.Of(true)).Build());
            var config = Configuration.Builder(sdkKey)
                         .DataSource(Components.ExternalUpdatesOnly)
                         .DataStore(TestUtils.SpecificDataStore(dataStore))
                         .Logging(Components.Logging(testLogging))
                         .Build();

            using (var client = new LdClient(config))
            {
                Assert.True(client.BoolVariation("key", User.WithKey("user"), false));
            }
        }