Ejemplo n.º 1
0
        public async Task When_Disposed_While_Refreshing_We_Shutdown_Gracefully()
        {
            using var cache = new TestDeviceCache(this.quickRefreshOptions, true);
            var deviceMock = CreateMockDevice();

            deviceMock.Setup(x => x.InitializeAsync(It.IsAny <NetworkServerConfiguration>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync((NetworkServerConfiguration config, CancellationToken token) =>
            {
                token.WaitHandle.WaitOne();
                throw new LoRaProcessingException("Refresh failed.", LoRaProcessingErrorCode.DeviceInitializationFailed);
            });

            var device = deviceMock.Object;

            cache.Register(device);

            while (!deviceMock.Invocations.Any(x => x.Method.Name == nameof(LoRaDevice.InitializeAsync)))
            {
                await Task.Delay(5);
            }

            cache.Dispose();
            var count = cache.DeviceRefreshCount;
            await Task.Delay(this.quickRefreshOptions.ValidationInterval * 2);

            Assert.Equal(count, cache.DeviceRefreshCount);
        }
Ejemplo n.º 2
0
        public async Task When_Cache_Is_Disposed_While_Waiting_For_Refresh_Refresh_Stops()
        {
            var options = this.quickRefreshOptions with
            {
                RefreshInterval = TimeSpan.FromSeconds(250)
            };
            var cache = new TestDeviceCache(options);

            cache.Dispose();

            var count = cache.RefreshOperationsCount;
            await Task.Delay(700);

            Assert.Equal(count, cache.RefreshOperationsCount);
        }