public LdClientBigSegmentsTest(ITestOutputHelper testOutput) : base(testOutput)
        {
            _testData = TestData.DataSource();

            _user       = User.WithKey("userkey");
            _bigSegment = new SegmentBuilder("segmentkey")
                          .Unbounded(true)
                          .Generation(1)
                          .Build();
            _flag = new FeatureFlagBuilder("flagkey")
                    .On(true)
                    .Variations(LdValue.Of(false), LdValue.Of(true))
                    .FallthroughVariation(0)
                    .Rules(
                new RuleBuilder().Variation(1).Clauses(
                    ClauseBuilder.ShouldMatchSegment(_bigSegment.Key)
                    ).Build()
                )
                    .Build();
            _testData.UsePreconfiguredFlag(_flag);
            _testData.UsePreconfiguredSegment(_bigSegment);

            _storeMock    = new MockBigSegmentStore();
            _storeFactory = _storeMock.AsSingletonFactory();
            _storeMock.SetupMetadataReturns(new StoreMetadata {
                LastUpToDate = UnixMillisecondTime.Now
            });
        }
Пример #2
0
        public void BigSegmentStoreStatusProviderSendsStatusUpdates()
        {
            var storeMock    = new MockBigSegmentStore();
            var storeFactory = storeMock.AsSingletonFactory();

            storeMock.SetupMetadataReturns(
                new BigSegmentStoreTypes.StoreMetadata {
                LastUpToDate = UnixMillisecondTime.Now
            });

            var config = BasicConfig()
                         .BigSegments(
                Components.BigSegments(storeFactory).StatusPollInterval(TimeSpan.FromMilliseconds(10))
                )
                         .Build();

            using (var client = new LdClient(config))
            {
                var status1 = client.BigSegmentStoreStatusProvider.Status;
                Assert.True(status1.Available);

                var statuses = new EventSink <BigSegmentStoreStatus>();
                client.BigSegmentStoreStatusProvider.StatusChanged += statuses.Add;

                storeMock.SetupMetadataThrows(new Exception("sorry"));

                var status2 = statuses.ExpectValue();
                if (status2.Available)
                {
                    // depending on timing, we might or might not receive an initial update of Available = true
                    status2 = statuses.ExpectValue();
                    Assert.False(status2.Available);
                }
            }
        }