diff --git a/Splitio.Redis/Services/Client/Classes/RedisClient.cs b/Splitio.Redis/Services/Client/Classes/RedisClient.cs index 4cfc76ea..345a546d 100644 --- a/Splitio.Redis/Services/Client/Classes/RedisClient.cs +++ b/Splitio.Redis/Services/Client/Classes/RedisClient.cs @@ -9,6 +9,7 @@ using Splitio.Redis.Telemetry.Storages; using Splitio.Services.Cache.Interfaces; using Splitio.Services.Client.Classes; +using Splitio.Services.Common; using Splitio.Services.EngineEvaluator; using Splitio.Services.Evaluator; using Splitio.Services.Impressions.Classes; @@ -30,7 +31,8 @@ public class RedisClient : SplitClient private IFeatureFlagCacheConsumer _featureFlagCacheConsumer; private readonly new FallbackTreatmentCalculator _fallbackTreatmentCalculator; - public RedisClient(ConfigurationOptions config, string apiKey, FallbackTreatmentCalculator fallbackTreatmentCalculator) : base(apiKey, fallbackTreatmentCalculator) + public RedisClient(ConfigurationOptions config, string apiKey, FallbackTreatmentCalculator fallbackTreatmentCalculator, + EventsManager eventsManager) : base(apiKey, fallbackTreatmentCalculator, eventsManager) { _config = new RedisConfig(); _fallbackTreatmentCalculator = fallbackTreatmentCalculator; diff --git a/src/Splitio/Services/Cache/Classes/InMemoryReadinessGatesCache.cs b/src/Splitio/Services/Cache/Classes/InMemoryReadinessGatesCache.cs index d1d42e51..d3121456 100644 --- a/src/Splitio/Services/Cache/Classes/InMemoryReadinessGatesCache.cs +++ b/src/Splitio/Services/Cache/Classes/InMemoryReadinessGatesCache.cs @@ -1,4 +1,7 @@ -using Splitio.Services.Cache.Interfaces; +using Splitio.Domain; +using Splitio.Services.Cache.Interfaces; +using Splitio.Services.Common; +using System.Collections.Generic; using System.Threading; namespace Splitio.Services.Client.Classes @@ -7,6 +10,12 @@ public class InMemoryReadinessGatesCache : IStatusManager { private readonly CountdownEvent _sdkReady = new CountdownEvent(1); private readonly CountdownEvent _sdkDestroyed = new CountdownEvent(1); + private readonly EventsManager _eventsManager; + + public InMemoryReadinessGatesCache(EventsManager eventsManager) + { + _eventsManager = eventsManager; + } public bool IsReady() { @@ -21,6 +30,10 @@ public bool WaitUntilReady(int milliseconds) public void SetReady() { _sdkReady.Signal(); + _eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkReady, + new EventMetadata(new Dictionary()), + Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkReady, + _eventsManager)); } public void SetDestroy() diff --git a/src/Splitio/Services/Client/Classes/JSONFileClient.cs b/src/Splitio/Services/Client/Classes/JSONFileClient.cs index ebc40e1a..830f5a0f 100644 --- a/src/Splitio/Services/Client/Classes/JSONFileClient.cs +++ b/src/Splitio/Services/Client/Classes/JSONFileClient.cs @@ -25,6 +25,7 @@ public class JSONFileClient : SplitClient public JSONFileClient(string splitsFilePath, string segmentsFilePath, FallbackTreatmentCalculator fallbackTreatmentCalculator, + EventsManager eventsManager, ISegmentCache segmentCacheInstance = null, IFeatureFlagCache featureFlagCacheInstance = null, IImpressionsLog impressionsLog = null, @@ -33,9 +34,8 @@ public JSONFileClient(string splitsFilePath, ITrafficTypeValidator trafficTypeValidator = null, IImpressionsManager impressionsManager = null, IRuleBasedSegmentCache ruleBasedSegmentCache = null - ) : base("localhost", fallbackTreatmentCalculator) + ) : base("localhost", fallbackTreatmentCalculator, eventsManager) { - var eventsManager = new EventsManager(new EventsManagerConfig()); _segmentCache = segmentCacheInstance ?? new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var rbsCache = ruleBasedSegmentCache ?? new InMemoryRuleBasedSegmentCache(new ConcurrentDictionary(), eventsManager); diff --git a/src/Splitio/Services/Client/Classes/LocalhostClient.cs b/src/Splitio/Services/Client/Classes/LocalhostClient.cs index 1afea359..b22c5f07 100644 --- a/src/Splitio/Services/Client/Classes/LocalhostClient.cs +++ b/src/Splitio/Services/Client/Classes/LocalhostClient.cs @@ -28,7 +28,8 @@ public class LocalhostClient : SplitClient private readonly object _lock = new object(); - public LocalhostClient(ConfigurationOptions configurationOptions, FallbackTreatmentCalculator fallbackTreatmentCalculator) : base("localhost", fallbackTreatmentCalculator) + public LocalhostClient(ConfigurationOptions configurationOptions, FallbackTreatmentCalculator fallbackTreatmentCalculator, + EventsManager eventsManager) : base("localhost", fallbackTreatmentCalculator, eventsManager) { var configs = (LocalhostClientConfigurations)_configService.ReadConfig(configurationOptions, ConfigTypes.Localhost, _statusManager); @@ -47,7 +48,6 @@ public LocalhostClient(ConfigurationOptions configurationOptions, FallbackTreatm BuildFlagSetsFilter(new HashSet()); - var eventsManager = new EventsManager(new EventsManagerConfig()); var splits = _localhostFileService.ParseSplitFile(_fullPath); _featureFlagCache = new InMemorySplitCache(splits, _flagSetsFilter, eventsManager); diff --git a/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs b/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs index 33141a74..4cd7c08a 100644 --- a/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs +++ b/src/Splitio/Services/Client/Classes/SelfRefreshingClient.cs @@ -52,16 +52,17 @@ public class SelfRefreshingClient : SplitClient private IRuleBasedSegmentCache _ruleBasedSegmentCache; private IUpdater _ruleBasedSegmentUpdater; private readonly new FallbackTreatmentCalculator _fallbackTreatmentCalculator; - private EventsManager _eventsManager; + private readonly EventsManager _eventsManager; public SelfRefreshingClient(string apiKey, ConfigurationOptions config, - FallbackTreatmentCalculator fallbackTreatmentCalculator) : base(apiKey, fallbackTreatmentCalculator) + FallbackTreatmentCalculator fallbackTreatmentCalculator, + EventsManager eventsManager) : base(apiKey, fallbackTreatmentCalculator, eventsManager) { _config = (SelfRefreshingConfig)_configService.ReadConfig(config, ConfigTypes.InMemory); _fallbackTreatmentCalculator = fallbackTreatmentCalculator; + _eventsManager = eventsManager; BuildFlagSetsFilter(_config.FlagSetsFilter); - BuildEventsManager(); BuildSplitCache(); BuildSegmentCache(); BuildRuleBasedSegmentCache(); @@ -90,10 +91,6 @@ public SelfRefreshingClient(string apiKey, ConfigurationOptions config, } #region Private Methods - private void BuildEventsManager() - { - _eventsManager = new EventsManager(new EventsManagerConfig()); - } private void BuildSplitCache() { _featureFlagCache = new InMemorySplitCache(new ConcurrentDictionary(_config.ConcurrencyLevel, InitialCapacity), _flagSetsFilter, _eventsManager); @@ -218,7 +215,7 @@ private void BuildManager() private void BuildBlockUntilReadyService() { - _blockUntilReadyService = new SelfRefreshingBlockUntilReadyService(_statusManager, _telemetryInitProducer); + _blockUntilReadyService = new SelfRefreshingBlockUntilReadyService(_statusManager, _telemetryInitProducer, _eventsManager); } private void BuildTelemetrySyncTask() diff --git a/src/Splitio/Services/Client/Classes/SplitClient.cs b/src/Splitio/Services/Client/Classes/SplitClient.cs index 54297fdf..7f9c0fb0 100644 --- a/src/Splitio/Services/Client/Classes/SplitClient.cs +++ b/src/Splitio/Services/Client/Classes/SplitClient.cs @@ -64,9 +64,11 @@ public abstract class SplitClient : ISplitClient protected IClientExtensionService _clientExtensionService; protected IFlagSetsFilter _flagSetsFilter; - protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatmentCalculator) + protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatmentCalculator, + EventsManager eventsManager) { ApiKey = apikey; + Splitio.Util.Helper.BuildInternalSdkEventStatus(eventsManager); _fallbackTreatmentCalculator = fallbackTreatmentCalculator; _wrapperAdapter = WrapperAdapter.Instance(); @@ -77,7 +79,7 @@ protected SplitClient(string apikey, FallbackTreatmentCalculator fallbackTreatme _factoryInstantiationsService = FactoryInstantiationsService.Instance(); _flagSetsValidator = new FlagSetsValidator(); _configService = new ConfigService(_wrapperAdapter, _flagSetsValidator, new SdkMetadataValidator()); - _statusManager = new InMemoryReadinessGatesCache(); + _statusManager = new InMemoryReadinessGatesCache(eventsManager); _tasksManager = new TasksManager(_statusManager); } diff --git a/src/Splitio/Services/Client/Classes/SplitFactory.cs b/src/Splitio/Services/Client/Classes/SplitFactory.cs index 92f8b46e..d22b6647 100644 --- a/src/Splitio/Services/Client/Classes/SplitFactory.cs +++ b/src/Splitio/Services/Client/Classes/SplitFactory.cs @@ -1,5 +1,6 @@ using Splitio.Domain; using Splitio.Services.Client.Interfaces; +using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; using Splitio.Services.InputValidation.Classes; using Splitio.Services.InputValidation.Interfaces; @@ -59,6 +60,8 @@ public ISplitManager Manager() private void BuildSplitClient() { FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(_options.FallbackTreatments); + EventsManager eventsManager = new EventsManager(new EventsManagerConfig()); + switch (_options.Mode) { case Mode.Standalone: @@ -66,11 +69,11 @@ private void BuildSplitClient() if (_apiKey == "localhost") { - _client = new LocalhostClient(_options, fallbackTreatmentCalculator); + _client = new LocalhostClient(_options, fallbackTreatmentCalculator, eventsManager); } else { - _client = new SelfRefreshingClient(_apiKey, _options, fallbackTreatmentCalculator); + _client = new SelfRefreshingClient(_apiKey, _options, fallbackTreatmentCalculator, eventsManager); } break; case Mode.Consumer: @@ -81,7 +84,7 @@ private void BuildSplitClient() var redisAssembly = Assembly.Load(new AssemblyName("Splitio.Redis")); var redisType = redisAssembly.GetType("Splitio.Redis.Services.Client.Classes.RedisClient"); - _client = (ISplitClient)Activator.CreateInstance(redisType, new object[] { _options, _apiKey, fallbackTreatmentCalculator }); + _client = (ISplitClient)Activator.CreateInstance(redisType, new object[] { _options, _apiKey, fallbackTreatmentCalculator, eventsManager }); } catch (ArgumentException ex) { diff --git a/src/Splitio/Services/Shared/Classes/SelfRefreshingBlockUntilReadyService.cs b/src/Splitio/Services/Shared/Classes/SelfRefreshingBlockUntilReadyService.cs index fcc27eec..6bf5c2b9 100644 --- a/src/Splitio/Services/Shared/Classes/SelfRefreshingBlockUntilReadyService.cs +++ b/src/Splitio/Services/Shared/Classes/SelfRefreshingBlockUntilReadyService.cs @@ -1,8 +1,11 @@ -using Splitio.Services.Cache.Interfaces; +using Splitio.Domain; +using Splitio.Services.Cache.Interfaces; +using Splitio.Services.Common; using Splitio.Services.Logger; using Splitio.Services.Shared.Interfaces; using Splitio.Telemetry.Storages; using System; +using System.Collections.Generic; namespace Splitio.Services.Shared.Classes { @@ -12,11 +15,14 @@ public class SelfRefreshingBlockUntilReadyService : IBlockUntilReadyService private readonly IStatusManager _statusManager; private readonly ITelemetryInitProducer _telemetryInitProducer; + private readonly EventsManager _eventsManager; - public SelfRefreshingBlockUntilReadyService(IStatusManager statusManager, ITelemetryInitProducer telemetryInitProducer) + public SelfRefreshingBlockUntilReadyService(IStatusManager statusManager, ITelemetryInitProducer telemetryInitProducer, + EventsManager eventsManager) { _statusManager = statusManager; _telemetryInitProducer = telemetryInitProducer; + _eventsManager = eventsManager; } public void BlockUntilReady(int blockMilisecondsUntilReady) @@ -30,6 +36,10 @@ public void BlockUntilReady(int blockMilisecondsUntilReady) if (!_statusManager.WaitUntilReady(blockMilisecondsUntilReady)) { + _eventsManager.NotifyInternalEvent(SdkInternalEvent.SdkTimedOut, + new EventMetadata(new Dictionary()), + Splitio.Util.Helper.GetSdkEventIfApplicable(SdkInternalEvent.SdkTimedOut, + _eventsManager)); _telemetryInitProducer.RecordBURTimeout(); throw new TimeoutException($"SDK was not ready in {blockMilisecondsUntilReady} milliseconds"); } diff --git a/tests/Splitio-tests/Integration Tests/BaseLocalhostClientTests.cs b/tests/Splitio-tests/Integration Tests/BaseLocalhostClientTests.cs index 4f035f95..fe9b3227 100644 --- a/tests/Splitio-tests/Integration Tests/BaseLocalhostClientTests.cs +++ b/tests/Splitio-tests/Integration Tests/BaseLocalhostClientTests.cs @@ -2,6 +2,7 @@ using Splitio.Domain; using Splitio.Redis.Services.Client.Classes; using Splitio.Services.Client.Classes; +using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; using Splitio.Telemetry.Domain; using System; @@ -24,6 +25,7 @@ public abstract class BaseLocalhostClientTests private readonly string rootFilePath; private readonly string _mode; private readonly FallbackTreatmentCalculator _fallbackTreatmentCalculator; + private readonly EventsManager _eventsManager; public BaseLocalhostClientTests(string mode) { @@ -31,6 +33,7 @@ public BaseLocalhostClientTests(string mode) rootFilePath = string.Empty; _mode = mode; _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); + _eventsManager = new EventsManager(new EventsManagerConfig()); #if NET_LATEST rootFilePath = @"Resources\"; @@ -42,7 +45,7 @@ public async Task GetTreatmentAsync() { // Arrange. var config = GetConfiguration($"{rootFilePath}test.splits"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -81,7 +84,7 @@ public void GetTreatmentSuccessfully() { //Arrange var config = GetConfiguration($"{rootFilePath}test.splits"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -105,7 +108,7 @@ public void GetTreatmentSuccessfullyWhenUpdatingSplitsFile() // Arrange var filePath = $"{rootFilePath}test2-{_mode}.splits"; var config = GetConfiguration(filePath); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -148,7 +151,7 @@ public void GetTreatmentSuccessfullyWhenUpdatingSplitsFileSameFile() Thread.Sleep(1000); var config = GetConfiguration(filePath); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -171,7 +174,7 @@ public void ClientDestroySuccessfully() { //Arrange var config = GetConfiguration($"{rootFilePath}test.splits"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -193,7 +196,7 @@ public void GetTreatment_WhenIsYamlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -225,7 +228,7 @@ public void GetTreatmentWithConfig_WhenIsYamlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -264,7 +267,7 @@ public void GetTreatment_WhenIsYmlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -296,7 +299,7 @@ public void GetTreatmentWithConfig_WhenIsYmlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -335,7 +338,7 @@ public void GetTreatments_WhenIsYamlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -372,7 +375,7 @@ public void GetTreatmentsWithConfig_WhenIsYamlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -423,7 +426,7 @@ public void GetTreatments_WhenIsYmlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -460,7 +463,7 @@ public void GetTreatmentsWithConfig_WhenIsYmlFile_Successfully() { //Arrange var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, _fallbackTreatmentCalculator); + var client = new LocalhostClient(config, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -514,7 +517,7 @@ public void FallbackTreatments_WhenFeatureDoesNotExist() FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(fallbackTreatmentsConfiguration); var config = GetConfiguration($"{rootFilePath}split.yml"); - var client = new LocalhostClient(config, fallbackTreatmentCalculator); + var client = new LocalhostClient(config, fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); diff --git a/tests/Splitio-tests/Integration Tests/InMemoryClientTests.cs b/tests/Splitio-tests/Integration Tests/InMemoryClientTests.cs index 5732ce6c..2279838c 100644 --- a/tests/Splitio-tests/Integration Tests/InMemoryClientTests.cs +++ b/tests/Splitio-tests/Integration Tests/InMemoryClientTests.cs @@ -3,6 +3,7 @@ using Newtonsoft.Json.Serialization; using Splitio.Domain; using Splitio.Services.Client.Classes; +using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; namespace Splitio_Tests.Integration_Tests @@ -12,12 +13,14 @@ public class InMemoryClientTests { private readonly string rootFilePath; private readonly FallbackTreatmentCalculator _fallbackTreatmentCalculator; + private readonly EventsManager _eventsManager; public InMemoryClientTests() { // This line is to clean the warnings. rootFilePath = string.Empty; _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); + _eventsManager = new EventsManager(new EventsManagerConfig()); #if NET_LATEST rootFilePath = @"Resources\"; @@ -36,7 +39,7 @@ public void OverridingJsonConvertSettingSnakeCaseNamingStrategy() NamingStrategy = new SnakeCaseNamingStrategy() } }; - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); //Act diff --git a/tests/Splitio-tests/Integration Tests/JSONFileClientTests.cs b/tests/Splitio-tests/Integration Tests/JSONFileClientTests.cs index efc6e8b7..6bdc8e55 100644 --- a/tests/Splitio-tests/Integration Tests/JSONFileClientTests.cs +++ b/tests/Splitio-tests/Integration Tests/JSONFileClientTests.cs @@ -3,6 +3,7 @@ using Splitio.Domain; using Splitio.Services.Cache.Interfaces; using Splitio.Services.Client.Classes; +using Splitio.Services.Common; using Splitio.Services.Events.Interfaces; using Splitio.Services.Impressions.Classes; using Splitio.Services.Impressions.Interfaces; @@ -19,12 +20,14 @@ public class JSONFileClientTests { private readonly string rootFilePath; private readonly FallbackTreatmentCalculator _fallbackTreatmentCalculator; + private readonly EventsManager _eventsManager; public JSONFileClientTests() { // This line is to clean the warnings. rootFilePath = string.Empty; _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); + _eventsManager = new EventsManager(new EventsManagerConfig()); #if NET_LATEST rootFilePath = @"Resources\"; @@ -37,7 +40,7 @@ public JSONFileClientTests() public void ExecuteGetTreatmentOnFailedParsingSplitShouldReturnControl() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); //Act var result = client.GetTreatment("test", "fail", null); @@ -52,7 +55,7 @@ public void ExecuteGetTreatmentOnFailedParsingSplitShouldReturnControl() public void ExecuteGetTreatmentOnFailedParsingSplitShouldNotAffectOtherSplits() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -69,7 +72,7 @@ public void ExecuteGetTreatmentOnFailedParsingSplitShouldNotAffectOtherSplits() public void ExecuteGetTreatmentOnDeletedSplitShouldReturnControl() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -97,7 +100,7 @@ public void ExecuteGetTreatmentOnExceptionShouldReturnControl() .Setup(x => x.GetSplit(It.IsAny())) .Throws(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, null, splitCacheMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, null, splitCacheMock.Object); //Act var result = client.GetTreatment("test", "asd", null); @@ -113,7 +116,7 @@ public void ExecuteGetTreatmentOnExceptionShouldReturnControl() public void ExecuteGetTreatmentOnRemovedUserFromSegmentShouldReturnOff() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", $"{rootFilePath}segment_payed.json", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", $"{rootFilePath}segment_payed.json", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -135,7 +138,7 @@ public void ExecuteGetTreatmentOnRemovedUserFromSegmentShouldReturnOff() public void ExecuteGetTreatmentOnSplitWithOnOffOnPartition() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -159,7 +162,7 @@ public void ExecuteGetTreatmentOnSplitWithOnOffOnPartition() public void ExecuteGetTreatmentOnSplitWithTrafficAllocation() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -183,7 +186,7 @@ public void ExecuteGetTreatmentOnSplitWithTrafficAllocation() public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIsDifferentThan100() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -207,7 +210,7 @@ public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIsDiffe public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIs1ReturnsRolloutTreatment() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_7.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_7.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -223,7 +226,7 @@ public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIs1Retu public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIs1ReturnsDefaultTreatment() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_7.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_7.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -239,7 +242,7 @@ public void ExecuteGetTreatmentOnSplitWithTrafficAllocationWhenAllocationIs1Retu public void ExecuteGetTreatmentOnSplitWithSegmentNotInitialized() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -259,7 +262,7 @@ public void ExecuteGetTreatmentAndLogLabelKilled() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -283,7 +286,7 @@ public void ExecuteGetTreatmentAndLogLabelNoConditionMatched() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -307,7 +310,7 @@ public void ExecuteGetTreatmentAndLogLabelSplitNotFound() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); //Act client.RemoveSplitFromCache("asd"); @@ -336,7 +339,7 @@ public void ExecuteGetTreatmentAndLogLabelException() .Setup(x => x.GetSplit(It.IsAny())) .Throws(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, featureFlagCacheInstance: splitCacheMock.Object, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, featureFlagCacheInstance: splitCacheMock.Object, impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -360,7 +363,7 @@ public void ExecuteGetTreatmentAndLogLabelTrafficAllocationFailed() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -383,7 +386,7 @@ public void ExecuteGetTreatmentAndLogLabelForTreatment() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -406,7 +409,7 @@ public void ExecuteGetTreatmentAndLogLabelForTreatment() public void ExecuteGetTreatmentWhenUnknownMatcherIsIncluded() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); //Act var result = client.GetTreatment("xs", "Unknown_Matcher", null); @@ -421,7 +424,7 @@ public void ExecuteGetTreatmentAndNotLogLabelForTreatmentIfLabelsNotEnabled() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object, isLabelsEnabled: false); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object, isLabelsEnabled: false); client.BlockUntilReady(1000); @@ -444,7 +447,7 @@ public void ExecuteGetTreatmentAndLogLabelAndBucketingKeyForTreatment() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -468,7 +471,7 @@ public void ExecuteGetTreatmentAndLogLabelAndBucketingKeyForTreatment() public void ExecuteGetTreatmentWithBooleanAttribute() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_4.json", "", _fallbackTreatmentCalculator, _eventsManager); var attributes = new Dictionary { @@ -490,7 +493,7 @@ public void ExecuteGetTreatmentWithBooleanAttribute() public void ExecuteGetTreatmentWithSetMatcherReturnsOff() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator, _eventsManager); var attributes = new Dictionary { @@ -512,7 +515,7 @@ public void ExecuteGetTreatmentWithSetMatcherReturnsOff() public void ExecuteGetTreatmentWithSetMatcherReturnsOn() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator, _eventsManager); var attributes = new Dictionary { @@ -534,7 +537,7 @@ public void ExecuteGetTreatmentWithSetMatcherReturnsOn() public void ExecuteGetTreatmentWithStringMatcherReturnsOff() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator, _eventsManager); var attributes = new Dictionary { @@ -556,7 +559,7 @@ public void ExecuteGetTreatmentWithStringMatcherReturnsOff() public void ExecuteGetTreatmentWithStringMatcherReturnsOn() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator, _eventsManager); var attributes = new Dictionary { @@ -578,7 +581,7 @@ public void ExecuteGetTreatmentWithStringMatcherReturnsOn() public void ExecuteGetTreatmentWithDependencyMatcherReturnsOn() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -595,7 +598,7 @@ public void ExecuteGetTreatmentWithDependencyMatcherReturnsOn() public void ExecuteGetTreatmentWithDependencyMatcherReturnsOff() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -613,7 +616,7 @@ public void ExecuteGetTreatmentWithDependencyMatcherImpressionOnChild() { //Arrange var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator, _eventsManager,impressionsLog: impressionsLogMock.Object); client.BlockUntilReady(1000); @@ -631,7 +634,7 @@ public void GetTreatment_WhenNameDoesntExist_DontLogImpression() { // Arrange. var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); var splitName = "not_exist"; client.BlockUntilReady(1000); @@ -649,7 +652,7 @@ public void GetTreatment_WhenNameDoesntExist_DontLogImpression() public void GetTreatment_WithoutBlockUntiltReady_ReturnsOff() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatment("key", "anding"); @@ -665,7 +668,7 @@ public void GetTreatment_WithoutBlockUntiltReady_ReturnsOff() public void ExecuteGetTreatments() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); List features = new List { "fail", @@ -696,7 +699,7 @@ public void ExecuteGetTreatments() public void ExecuteGetTreatmentsWithBucketing() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); List features = new List { "fail", @@ -728,7 +731,7 @@ public void ExecuteGetTreatmentsWithBucketing() public void ExecuteGetTreatmentsWithDependencyMatcherReturnsOn() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -751,7 +754,7 @@ public void ExecuteGetTreatmentsWithDependencyMatcherReturnsOn() public void ExecuteGetTreatmentsWithDependencyMatcherWithAttributesReturnsOn() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_6.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(1000); @@ -779,7 +782,7 @@ public void GetTreatments_WhenNameDoesntExist_DontLogImpression() { // Arrange. var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); var splitNames = new List { "not_exist", "not_exist_1" }; client.BlockUntilReady(1000); @@ -801,7 +804,7 @@ public void GetTreatments_WhenNameDoesntExist_DontLogImpression() public void GetTreatments_WithoutBlockUntiltReady_ReturnsEmptyList() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatments("key", new List()); @@ -815,7 +818,7 @@ public void GetTreatments_WithoutBlockUntiltReady_ReturnsEmptyList() public void GetTreatments_WithoutBlockUntiltReady_ReturnsTreatments() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatments("key", new List { "anding", "in_ten_keys" }); @@ -833,7 +836,7 @@ public void GetTreatments_WithoutBlockUntiltReady_ReturnsTreatments() public void GetTreatments_WhenClientIsReadyAndFeaturesIsEmpty_ReturnsEmptyList() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(100); // Act. @@ -850,7 +853,7 @@ public void GetTreatments_WhenClientIsReadyAndFeaturesIsEmpty_ReturnsEmptyList() public void DestroySucessfully() { //Arrange - var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_5.json", "", _fallbackTreatmentCalculator, _eventsManager); var attributes = new Dictionary { @@ -886,7 +889,7 @@ public void Track_WhenClientIsNotReady_ReturnsTrue() // Arrange. var trafficTypeValidator = new Mock(); var eventLog = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, trafficTypeValidator: trafficTypeValidator.Object, eventsLog: eventLog.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, trafficTypeValidator: trafficTypeValidator.Object, eventsLog: eventLog.Object); trafficTypeValidator .Setup(mock => mock.IsValid(It.IsAny(), It.IsAny())) @@ -907,7 +910,7 @@ public void GetTreatmentWithConfig_WhenNameDoesntExist_DontLogImpression() { // Arrange. var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); var splitName = "not_exist"; client.BlockUntilReady(1000); @@ -926,7 +929,7 @@ public void GetTreatmentWithConfig_WhenNameDoesntExist_DontLogImpression() public void GetTreatmentWithConfig_WithoutBlockUntiltReady_ReturnsOff() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatmentWithConfig("key", "anding"); @@ -944,7 +947,7 @@ public void GetTreatmentsWithConfig_WhenNameDoesntExist_DontLogImpression() { // Arrange. var impressionsLogMock = new Mock(); - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, impressionsLog: impressionsLogMock.Object); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager, impressionsLog: impressionsLogMock.Object); var splitNames = new List { "not_exist", "not_exist_1" }; client.BlockUntilReady(1000); @@ -967,7 +970,7 @@ public void GetTreatmentsWithConfig_WhenNameDoesntExist_DontLogImpression() public void GetTreatmentsWithConfig_WithoutBlockUntiltReady_ReturnsEmptyList() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatmentsWithConfig("anding", new List()); @@ -981,7 +984,7 @@ public void GetTreatmentsWithConfig_WithoutBlockUntiltReady_ReturnsEmptyList() public void GetTreatmentsWithConfig_WithoutBlockUntiltReady_ReturnsTreatments() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatmentsWithConfig("key", new List { "anding", "whitelisting_elements" }); @@ -1001,7 +1004,7 @@ public void GetTreatmentsWithConfig_WithoutBlockUntiltReady_ReturnsTreatments() public void GetTreatmentsWithConfig_WhenClientIsReadyAndFeaturesIsEmpty_ReturnsEmptyList() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(100); // Act. @@ -1018,7 +1021,7 @@ public void GetTreatmentsWithConfig_WhenClientIsReadyAndFeaturesIsEmpty_ReturnsE public void Split_Manager_WhenNameDoesntExist_ReturnsNull() { // Arrange. - var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator); + var client = new JSONFileClient($"{rootFilePath}splits_staging_3.json", "", _fallbackTreatmentCalculator, _eventsManager); var manager = client.GetSplitManager(); var splitName = "not_exist"; diff --git a/tests/Splitio-tests/Integration Tests/RedisClientTests.cs b/tests/Splitio-tests/Integration Tests/RedisClientTests.cs index 84ebcbd7..8ad5f8be 100644 --- a/tests/Splitio-tests/Integration Tests/RedisClientTests.cs +++ b/tests/Splitio-tests/Integration Tests/RedisClientTests.cs @@ -4,6 +4,7 @@ using Splitio.Redis.Services.Client.Classes; using Splitio.Redis.Services.Domain; using Splitio.Services.Client.Classes; +using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; using Splitio.Tests.Common.Resources; using Splitio_Tests.Resources; @@ -25,6 +26,7 @@ public class RedisClientTests private ConfigurationOptions config; private RedisAdapterForTests _redisAdapter; private FallbackTreatmentCalculator _fallbackTreatmentCalculator; + private EventsManager _eventsManager; [TestInitialize] public void Initialization() @@ -38,6 +40,7 @@ public void Initialization() UserPrefix = _prefix }; _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); + _eventsManager = new EventsManager(new EventsManagerConfig()); config = new ConfigurationOptions { CacheAdapterConfig = cacheAdapterConfig, @@ -64,7 +67,7 @@ public void Initialization() public void GetTreatment_WhenFeatureExists_ReturnsOn() { //Arrange - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(5000); @@ -75,7 +78,7 @@ public void GetTreatment_WhenFeatureExists_ReturnsOn() Assert.IsNotNull(result); Assert.AreEqual("on", result); - var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator); + var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); @@ -91,7 +94,7 @@ public void GetTreatment_WhenFeatureExists_ReturnsOn() public void GetTreatment_WhenFeatureExists_ReturnsOff() { //Arrange - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(5000); @@ -102,7 +105,7 @@ public void GetTreatment_WhenFeatureExists_ReturnsOff() Assert.IsNotNull(result); Assert.AreEqual("off", result); - var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator); + var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); result = client2.GetTreatment("test", "always_off", null); @@ -116,7 +119,7 @@ public void GetTreatment_WhenFeatureExists_ReturnsOff() public void GetTreatment_WhenFeatureDoenstExist_ReturnsControl() { //Arrange - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(5000); //Act @@ -126,7 +129,7 @@ public void GetTreatment_WhenFeatureDoenstExist_ReturnsControl() Assert.IsNotNull(result); Assert.AreEqual("control", result); - var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator); + var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); result = client2.GetTreatment("test", "always_control", null); @@ -145,7 +148,7 @@ public void GetTreatments_WhenFeaturesExists_ReturnsOnOff() var features = new List { alwaysOn, alwaysOff }; - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(5000); @@ -159,7 +162,7 @@ public void GetTreatments_WhenFeaturesExists_ReturnsOnOff() var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), - API_KEY, _fallbackTreatmentCalculator); + API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); result = client2.GetTreatments("test", features, null); @@ -180,7 +183,7 @@ public void GetTreatments_WhenOneFeatureDoenstExist_ReturnsOnOffControl() var features = new List { alwaysOn, alwaysOff, alwaysControl }; - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(5000); @@ -194,7 +197,7 @@ public void GetTreatments_WhenOneFeatureDoenstExist_ReturnsOnOffControl() Assert.AreEqual("control", result[alwaysControl]); var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), - API_KEY, _fallbackTreatmentCalculator); + API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); result = client2.GetTreatments("test", features, null); @@ -210,7 +213,7 @@ public void GetTreatments_WhenOneFeatureDoenstExist_ReturnsOnOffControl() public void GetTreatmentsWithConfig_WhenClientIsNotReady_ReturnsControl() { // Arrange. - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatmentsWithConfig("key", new List()); @@ -223,7 +226,7 @@ public void GetTreatmentsWithConfig_WhenClientIsNotReady_ReturnsControl() } var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), -API_KEY, _fallbackTreatmentCalculator); +API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); result = client2.GetTreatmentsWithConfig("key", new List()); @@ -240,7 +243,7 @@ public void GetTreatmentsWithConfig_WhenClientIsNotReady_ReturnsControl() public void GetTreatmentWithConfig_WhenClientIsNotReady_ReturnsControl() { // Arrange. - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatmentWithConfig("key", string.Empty); @@ -250,7 +253,7 @@ public void GetTreatmentWithConfig_WhenClientIsNotReady_ReturnsControl() Assert.IsNull(result.Config); var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), -API_KEY, _fallbackTreatmentCalculator); +API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); result = client2.GetTreatmentWithConfig("key", string.Empty); @@ -264,7 +267,7 @@ public void GetTreatmentWithConfig_WhenClientIsNotReady_ReturnsControl() public void GetTreatment_WhenClientIsNotReady_ReturnsControl() { // Arrange. - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatment("key", string.Empty); @@ -273,7 +276,7 @@ public void GetTreatment_WhenClientIsNotReady_ReturnsControl() Assert.AreEqual("control", result); var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), -API_KEY, _fallbackTreatmentCalculator); +API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); result = client2.GetTreatment("key", string.Empty); @@ -287,7 +290,7 @@ public void GetTreatments_WhenClientIsNotReady_ReturnsControl() { // Arrange. config.CacheAdapterConfig.Host = "fake-host"; - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.GetTreatments("key", new List()); @@ -298,7 +301,7 @@ public void GetTreatments_WhenClientIsNotReady_ReturnsControl() Assert.AreEqual("control", res.Value); } - var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator); + var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); result = client2.GetTreatments("key", new List()); @@ -314,7 +317,7 @@ public void GetTreatments_WhenClientIsNotReady_ReturnsControl() public void Track_WhenClientIsNotReady_ReturnsTrue() { // Arrange. - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); // Act. var result = client.Track("key", "traffic_type", "event_type"); @@ -323,7 +326,7 @@ public void Track_WhenClientIsNotReady_ReturnsTrue() Assert.IsTrue(result); var client2 = new RedisClient(GetRedisClusterConfigurationOptions(), -API_KEY, _fallbackTreatmentCalculator); +API_KEY, _fallbackTreatmentCalculator, _eventsManager); client2.BlockUntilReady(5000); // Act. @@ -342,7 +345,7 @@ public void FallbackTreatments_WhenFeatureDoesNotExist() FallbackTreatmentsConfiguration fallbackTreatmentsConfiguration = new FallbackTreatmentsConfiguration(new FallbackTreatment("on-global", "\"prop\":\"global\""), new Dictionary() { { "feature", new FallbackTreatment("off-local", "\"prop\":\"local\"") } }); FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(fallbackTreatmentsConfiguration); - var client = new RedisClient(config, API_KEY, fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(5000); @@ -380,7 +383,7 @@ public void FallbackTreatments_WhenClientNotReady() FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(fallbackTreatmentsConfiguration); config.CacheAdapterConfig.Host = "fake-host"; - var client = new RedisClient(config, API_KEY, fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, fallbackTreatmentCalculator, _eventsManager); //Act var result = client.GetTreatmentsWithConfig("test", features, null); @@ -402,7 +405,7 @@ public void FallbackTreatments_WhenExceptionOccurrs() FallbackTreatmentsConfiguration fallbackTreatmentsConfiguration = new FallbackTreatmentsConfiguration(new FallbackTreatment("on-global", "\"prop\":\"global\""), new Dictionary() { { "feature", new FallbackTreatment("off-local", "\"prop\":\"local\"") } }); FallbackTreatmentCalculator fallbackTreatmentCalculator = new FallbackTreatmentCalculator(fallbackTreatmentsConfiguration); - var client = new RedisClient(config, API_KEY, fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(5000); @@ -431,7 +434,7 @@ public void FallbackTreatments_WhenExceptionOccurrs() public void Destroy() { //Arrange - var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator); + var client = new RedisClient(config, API_KEY, _fallbackTreatmentCalculator, _eventsManager); client.BlockUntilReady(5000); //Act diff --git a/tests/Splitio-tests/Integration Tests/TargetingRulesFetcherTests.cs b/tests/Splitio-tests/Integration Tests/TargetingRulesFetcherTests.cs index f2b7dfe7..e6049299 100644 --- a/tests/Splitio-tests/Integration Tests/TargetingRulesFetcherTests.cs +++ b/tests/Splitio-tests/Integration Tests/TargetingRulesFetcherTests.cs @@ -46,7 +46,7 @@ public async Task ExecuteGetSuccessfulWithResultsFromJSONFile() var splitChangeFetcher = new JSONFileSplitChangeFetcher($"{rootFilePath}splits_staging.json"); var flagSetsFilter = new FlagSetsFilter(new HashSet()); var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), flagSetsFilter, eventsManager); - var gates = new InMemoryReadinessGatesCache(); + var gates = new InMemoryReadinessGatesCache(eventsManager); var taskManager = new TasksManager(gates); var task = taskManager.NewPeriodicTask(Splitio.Enums.Task.FeatureFlagsFetcher, 250); var featureFlagSyncService = new FeatureFlagUpdater(splitParser, splitCache, flagSetsFilter, rbsCache); @@ -92,7 +92,7 @@ public async Task ExecuteGetSuccessfulWithResultsFromJSONFileIncludingTrafficAll var splitChangeFetcher = new JSONFileSplitChangeFetcher($"{rootFilePath}splits_staging_4.json"); var flagSetsFilter = new FlagSetsFilter(new HashSet()); var splitCache = new InMemorySplitCache(new ConcurrentDictionary(), flagSetsFilter, eventsManager); - var gates = new InMemoryReadinessGatesCache(); + var gates = new InMemoryReadinessGatesCache(eventsManager); var taskManager = new TasksManager(gates); var task = taskManager.NewPeriodicTask(Splitio.Enums.Task.FeatureFlagsFetcher, 250); var featureFlagSyncService = new FeatureFlagUpdater(splitParser, splitCache, flagSetsFilter, rbsCache); @@ -141,8 +141,8 @@ public async Task ExecuteGetWithoutResults() var apiSplitChangeFetcher = new ApiSplitChangeFetcher(sdkApiClient); var sdkSegmentApiClient = new SegmentSdkApiClient(httpClient, telemetryStorage, baseUrl); var apiSegmentChangeFetcher = new ApiSegmentChangeFetcher(sdkSegmentApiClient); - var gates = new InMemoryReadinessGatesCache(); var eventsManager = new EventsManager(new EventsManagerConfig()); + var gates = new InMemoryReadinessGatesCache(eventsManager); var segmentCache = new InMemorySegmentCache(new ConcurrentDictionary(), eventsManager); var segmentsQueue = new SplitQueue(); var taskManager = new TasksManager(gates); diff --git a/tests/Splitio-tests/Unit Tests/Client/LocalhostClientForTesting.cs b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientForTesting.cs index 09c6b39e..b97cff0e 100644 --- a/tests/Splitio-tests/Unit Tests/Client/LocalhostClientForTesting.cs +++ b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientForTesting.cs @@ -1,11 +1,13 @@ -using Splitio.Services.Client.Classes; +using Splitio.Domain; +using Splitio.Services.Client.Classes; +using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; namespace Splitio_Tests.Unit_Tests.Client { public class LocalhostClientForTesting : LocalhostClient { - public LocalhostClientForTesting(string filePath, FallbackTreatmentCalculator fallbackTreatmentCalculator) : base(new ConfigurationOptions { LocalhostFilePath = filePath }, fallbackTreatmentCalculator) + public LocalhostClientForTesting(string filePath, FallbackTreatmentCalculator fallbackTreatmentCalculator) : base(new ConfigurationOptions { LocalhostFilePath = filePath }, fallbackTreatmentCalculator, new EventsManager(new EventsManagerConfig())) { } } } diff --git a/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs index aaf4a6a2..95ecd3ba 100644 --- a/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/Client/LocalhostClientUnitTests.cs @@ -1,6 +1,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Splitio.Domain; using Splitio.Services.Client.Classes; +using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; using Splitio.Services.Shared.Classes; @@ -11,12 +12,14 @@ public class LocalhostClientUnitTests { private readonly string rootFilePath; private readonly FallbackTreatmentCalculator _fallbackTreatmentCalculator; + private readonly EventsManager _eventsManager; public LocalhostClientUnitTests() { // This line is to clean the warnings. rootFilePath = string.Empty; _fallbackTreatmentCalculator = new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()); + _eventsManager = new EventsManager(new EventsManagerConfig()); #if NET_LATEST rootFilePath = @"Resources\"; @@ -28,7 +31,7 @@ public LocalhostClientUnitTests() public void GetTreatmentShouldReturnControlIfSplitNotFound() { //Arrange - var splitClient = new LocalhostClient(new ConfigurationOptions { LocalhostFilePath = $"{rootFilePath}test.splits" }, _fallbackTreatmentCalculator); + var splitClient = new LocalhostClient(new ConfigurationOptions { LocalhostFilePath = $"{rootFilePath}test.splits" }, _fallbackTreatmentCalculator, _eventsManager); //Act var result = splitClient.GetTreatment("test", "test"); @@ -41,7 +44,7 @@ public void GetTreatmentShouldReturnControlIfSplitNotFound() [DeploymentItem(@"Resources\test.splits")] public void GetTreatmentShouldRunAsSingleKeyUsingNullBucketingKey() { - var splitClient = new LocalhostClient(new ConfigurationOptions { LocalhostFilePath = $"{rootFilePath}test.splits" }, _fallbackTreatmentCalculator); + var splitClient = new LocalhostClient(new ConfigurationOptions { LocalhostFilePath = $"{rootFilePath}test.splits" }, _fallbackTreatmentCalculator, _eventsManager); splitClient.BlockUntilReady(1000); //Act diff --git a/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs b/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs index bf1e7b1b..83ca9c24 100644 --- a/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/Client/SdkReadinessGatesUnitTests.cs @@ -1,16 +1,23 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; +using Splitio.Domain; using Splitio.Services.Client.Classes; +using Splitio.Services.Common; +using System; namespace Splitio_Tests.Unit_Tests.Client { [TestClass] public class InMemoryReadinessGatesCacheUnitTests { + private bool SdkReady = false; + private EventMetadata eMetadata = null; + public event EventHandler PublicSdkUpdateHandler; + [TestMethod] public void IsSDKReadyShouldReturnFalseIfSplitsAreNotReady() { //Arrange - var gates = new InMemoryReadinessGatesCache(); + var gates = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); //Act var result = gates.IsReady(); @@ -18,5 +25,29 @@ public void IsSDKReadyShouldReturnFalseIfSplitsAreNotReady() //Assert Assert.IsFalse(result); } + + [TestMethod] + public void TestFireReadyEvent() + { + //Arrange + EventsManager eventsManager = new EventsManager(new EventsManagerConfig()); + Splitio.Util.Helper.BuildInternalSdkEventStatus(eventsManager); + var gates = new InMemoryReadinessGatesCache(eventsManager); + PublicSdkUpdateHandler += sdkReady_callback; + eventsManager.Register(SdkEvent.SdkReady, sdkReady_callback); + + //Act + gates.SetReady(); + + // Assert. + Assert.IsTrue(SdkReady); + Assert.AreEqual(0, eMetadata.GetData().Count); + } + + private void sdkReady_callback(object sender, EventMetadata metadata) + { + SdkReady = true; + eMetadata = metadata; + } } } diff --git a/tests/Splitio-tests/Unit Tests/Client/SplitClientForTesting.cs b/tests/Splitio-tests/Unit Tests/Client/SplitClientForTesting.cs index 80587cd2..12277bcb 100644 --- a/tests/Splitio-tests/Unit Tests/Client/SplitClientForTesting.cs +++ b/tests/Splitio-tests/Unit Tests/Client/SplitClientForTesting.cs @@ -1,4 +1,5 @@ -using Splitio.Services.Cache.Interfaces; +using Splitio.Domain; +using Splitio.Services.Cache.Interfaces; using Splitio.Services.Client.Classes; using Splitio.Services.Common; using Splitio.Services.Evaluator; @@ -22,7 +23,7 @@ public SplitClientForTesting(IFeatureFlagCacheConsumer featureFlagCacheConsumer, ISyncManager syncManager, FallbackTreatmentCalculator fallbackTreatmentCalculator, ITelemetryEvaluationProducer telemetryEvaluationProducer) - : base("SplitClientForTesting", fallbackTreatmentCalculator) + : base("SplitClientForTesting", fallbackTreatmentCalculator, new EventsManager(new EventsManagerConfig())) { _eventsLog = eventsLog; _impressionsLog = impressionsLog; diff --git a/tests/Splitio-tests/Unit Tests/Impressions/ImpressionsCounterTests.cs b/tests/Splitio-tests/Unit Tests/Impressions/ImpressionsCounterTests.cs index 77ce67e3..42df730c 100644 --- a/tests/Splitio-tests/Unit Tests/Impressions/ImpressionsCounterTests.cs +++ b/tests/Splitio-tests/Unit Tests/Impressions/ImpressionsCounterTests.cs @@ -1,6 +1,8 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; +using Splitio.Domain; using Splitio.Services.Client.Classes; +using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; using Splitio.Services.Impressions.Interfaces; using Splitio.Services.Tasks; @@ -27,7 +29,7 @@ public void Start_ShouldSendImpressionsCount() { // Arrange. var config = new ComponentConfig(5, 5); - var statusManager = new InMemoryReadinessGatesCache(); + var statusManager = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); var taskManager = new TasksManager(statusManager); var task = taskManager.NewPeriodicTask(Splitio.Enums.Task.ImpressionsCountSender, 1); var sendBulkDataTask = taskManager.NewOnTimeTask(Splitio.Enums.Task.ImpressionCounterSendBulkData); @@ -51,7 +53,7 @@ public void Start_ShouldNotSendImpressionsCount() { // Arrange. var config = new ComponentConfig(5, 5); - var statusManager = new InMemoryReadinessGatesCache(); + var statusManager = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); var taskManager = new TasksManager(statusManager); var task = taskManager.NewPeriodicTask(Splitio.Enums.Task.ImpressionsCountSender, 1); var sendBulkDataTask = taskManager.NewOnTimeTask(Splitio.Enums.Task.ImpressionCounterSendBulkData); @@ -70,7 +72,7 @@ public async Task Stop_ShouldSendImpressionsCount() { // Arrange. var config = new ComponentConfig(5, 5); - var statusManager = new InMemoryReadinessGatesCache(); + var statusManager = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); var taskManager = new TasksManager(statusManager); var task = taskManager.NewPeriodicTask(Splitio.Enums.Task.ImpressionsCountSender, 100); var sendBulkDataTask = taskManager.NewOnTimeTask(Splitio.Enums.Task.ImpressionCounterSendBulkData); @@ -94,7 +96,7 @@ public async Task Stop_ShouldSendImpressionsCount() public async Task ShouldSend2BulksOfImpressions() { var config = new ComponentConfig(6, 3); - var statusManager = new InMemoryReadinessGatesCache(); + var statusManager = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); var taskManager = new TasksManager(statusManager); var task = taskManager.NewPeriodicTask(Splitio.Enums.Task.ImpressionsCountSender, 100); var sendBulkDataTask = taskManager.NewOnTimeTask(Splitio.Enums.Task.ImpressionCounterSendBulkData); diff --git a/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs b/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs index 9e242cc8..97a68959 100644 --- a/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs +++ b/tests/Splitio-tests/Unit Tests/SegmentFetcher/SelfRefreshingSegmentFetcherUnitTests.cs @@ -27,7 +27,7 @@ public class SelfRefreshingSegmentFetcherUnitTests public void InitializeSegmentNotExistent() { // Arrange - var gates = new InMemoryReadinessGatesCache(); + var gates = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); gates.SetReady(); var apiClient = new Mock(); var apiFetcher = new ApiSegmentChangeFetcher(apiClient.Object); diff --git a/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs b/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs new file mode 100644 index 00000000..d5204d8e --- /dev/null +++ b/tests/Splitio-tests/Unit Tests/Shared/SelfRefreshingBlockUntilReadyServiceTests.cs @@ -0,0 +1,52 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Moq; +using Splitio.Domain; +using Splitio.Services.Cache.Interfaces; +using Splitio.Services.Common; +using Splitio.Services.Shared.Classes; +using Splitio.Telemetry.Storages; +using System; + +namespace Splitio_Tests.Unit_Tests.Shared +{ + [TestClass] + public class SelfRefreshingBlockUntilReadyServiceTests + { + private bool SdkTimedOut = false; + private EventMetadata eMetadata = null; + public event EventHandler PublicSdkUpdateHandler; + + [TestMethod] + public void TestFireTimedOutEvent() + { + //Arrange + Mock statusManager = new Mock(); + Mock telemetryProducer = new Mock(); + EventsManager eventsManager = new EventsManager(new EventsManagerConfig()); + Splitio.Util.Helper.BuildInternalSdkEventStatus(eventsManager); + var bur = new SelfRefreshingBlockUntilReadyService(statusManager.Object, telemetryProducer.Object, eventsManager); + PublicSdkUpdateHandler += SdkTimedOut_callback; + eventsManager.Register(SdkEvent.SdkReadyTimeout, SdkTimedOut_callback); + statusManager + .Setup(mock => mock.WaitUntilReady(1)) + .Returns(false); + + //Act + try + { + bur.BlockUntilReady(1); + } + catch { } + + // Assert. + Assert.IsTrue(SdkTimedOut); + Assert.AreEqual(0, eMetadata.GetData().Count); + } + + private void SdkTimedOut_callback(object sender, EventMetadata metadata) + { + SdkTimedOut = true; + eMetadata = metadata; + } + } +} diff --git a/tests/Splitio.Integration-tests/EventSourceClientTests.cs b/tests/Splitio.Integration-tests/EventSourceClientTests.cs index ba776643..0eb26bdd 100644 --- a/tests/Splitio.Integration-tests/EventSourceClientTests.cs +++ b/tests/Splitio.Integration-tests/EventSourceClientTests.cs @@ -370,7 +370,7 @@ private static (IEventSourceClient, BlockingCollection, var sseHttpClient = new SplitioHttpClient("api-key", config, new Dictionary()); var telemetryRuntimeProducer = new InMemoryTelemetryStorage(); var notificationManagerKeeper = new NotificationManagerKeeper(telemetryRuntimeProducer, streamingStatusQueue); - var statusManager = new InMemoryReadinessGatesCache(); + var statusManager = new InMemoryReadinessGatesCache(new EventsManager(new EventsManagerConfig())); var tasksManager = new TasksManager(statusManager); var task = tasksManager.NewOnTimeTask(Enums.Task.SSEConnect); diff --git a/tests/Splitio.TestSupport/SplitClientForTest.cs b/tests/Splitio.TestSupport/SplitClientForTest.cs index ddffe2eb..f79f6674 100644 --- a/tests/Splitio.TestSupport/SplitClientForTest.cs +++ b/tests/Splitio.TestSupport/SplitClientForTest.cs @@ -1,4 +1,5 @@ using Splitio.Domain; +using Splitio.Services.Common; using Splitio.Services.Impressions.Classes; using System.Collections.Generic; using System.Threading.Tasks; @@ -9,7 +10,8 @@ public class SplitClientForTest : SplitClient { private readonly Dictionary _tests; - public SplitClientForTest() : base("SplitClientForTest", new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration())) + public SplitClientForTest() : base("SplitClientForTest", new FallbackTreatmentCalculator(new FallbackTreatmentsConfiguration()), + new EventsManager(new EventsManagerConfig())) { _tests = new Dictionary(); }