public async Task GetAllEndPointsChangedShouldFireConfigChange()
        {
            SetMockToReturnHost(MasterService);
            SetMockToReturnHost(OriginatingService);

            //in the first time can fire one or two event
            var discovey = GetServiceDiscovey();

            //wait for discovey to be initialize!!
            var endPoints = await discovey.GetAllEndPoints();

            endPoints.Single().HostName.ShouldBe(OriginatingService);

            var waitForEvents = discovey.EndPointsChanged.StartCountingEvents();

            _configDic[$"Discovery.Services.{_serviceName}.Source"] = "Config";
            _configDic[$"Discovery.Services.{_serviceName}.Hosts"]  = "localhost";
            Console.WriteLine("RaiseChangeEvent");

            Task waitForChangeEvent = waitForEvents.WhenNextEventReceived();

            _configRefresh.RaiseChangeEvent();
            await waitForChangeEvent;

            waitForEvents.ReceivedEvents.Count.ShouldBe(1);


            endPoints = await discovey.GetAllEndPoints();

            endPoints.Single().HostName.ShouldBe("localhost");
            waitForEvents.ReceivedEvents.Count.ShouldBe(1);
        }
        private async Task WaitForConfigChange(Action update)
        {
            var waitForInit = await _serviceDiscovery.GetNextHost();

            var task = _serviceDiscovery.EndPointsChanged.WhenEventReceived();

            update();
            _configRefresh.RaiseChangeEvent();

            await task;
        }
示例#3
0
        public async Task EndPointsChangedShouldFireConfigChange()
        {
            SetMockToReturnHost(MasterService);
            SetMockToReturnHost(OriginatingService);

            //in the first time can fire one or two event
            var discovey      = GetServiceDiscovey();
            var waitForEvents = discovey.EndPointsChanged.StartCountingEvents();

            await discovey.GetNextHost();

            _configDic[$"Discovery.Services.{_serviceName}.Hosts"]  = "localhost";
            _configDic[$"Discovery.Services.{_serviceName}.Source"] = "Config";

            _configRefresh.RaiseChangeEvent();
            await waitForEvents.WhenNextEventReceived();

            var host = await discovey.GetNextHost();

            host.HostName.ShouldBe("localhost");
            waitForEvents.ReceivedEvents.Count.ShouldBe(1);
        }
        private async Task WaitForConfigChange(Action update)
        {
            var oldValue = _serviceDiscovery.LastConfig;

            update();
            _configRefresh.RaiseChangeEvent();

            for (int i = 0; i < 500; i++)
            {
                if (_serviceDiscovery.LastConfig != null && Equals(oldValue, _serviceDiscovery.LastConfig) == false)
                {
                    return;
                }

                await Task.Delay(10);
            }

            throw new TimeoutException("time out");
        }
        public async Task EndPointsChangedShouldFireConfigChange()
        {
            int numOfEvent = 0;

            SetMockToReturnHost(_masterService);
            SetMockToReturnHost(_originatingService);

            //in the first time can fire one or two event
            var discovey = GetServiceDiscovey;
            await discovey.GetNextHost();

            discovey.EndPointsChanged.LinkTo(new ActionBlock <string>(x => numOfEvent++));
            _configDic[$"Discovery.Services.{SERVICE_NAME}.Source"] = "Config";
            _configDic[$"Discovery.Services.{SERVICE_NAME}.Hosts"]  = "localhost";

            _configRefresh.RaiseChangeEvent();
            Thread.Sleep(400);

            var host = await discovey.GetNextHost();

            host.HostName.ShouldBe("localhost");

            numOfEvent.ShouldBe(2);
        }