コード例 #1
0
        public async STT.Task DbUsage_CachedVsForced()
        {
            await Test(async() =>
            {
                var logger = new TestDbUsageLogger();

                // get initial
                var handler = new DatabaseUsageHandler(logger);
                var usage1  = await handler.GetDatabaseUsageAsync(false, CancellationToken.None);

                // wait a bit and get cached
                await STT.Task.Delay(100);
                handler    = new DatabaseUsageHandler(logger);
                var usage2 = await handler.GetDatabaseUsageAsync(false, CancellationToken.None);

                // wait a bit and get fresh data
                await STT.Task.Delay(100);
                handler    = new DatabaseUsageHandler(logger);
                var usage3 = await handler.GetDatabaseUsageAsync(true, CancellationToken.None);

                // wait a bit and get cached again
                await STT.Task.Delay(100);
                handler    = new DatabaseUsageHandler(logger);
                var usage4 = await handler.GetDatabaseUsageAsync(false, CancellationToken.None);

                Assert.AreEqual(usage1.Executed, usage2.Executed);
                Assert.IsTrue(usage2.Executed < usage3.Executed);
                Assert.AreEqual(usage3.Executed, usage4.Executed);
            }).ConfigureAwait(false);
        }
コード例 #2
0
        public async STT.Task DbUsage_Logger_CreatingCache()
        {
            await Test(builder =>
            {
                builder.EnableNodeObservers(typeof(DatabaseUsageCacheTestNodeObserver));
            }, async() =>
            {
                var logger = new TestDbUsageLogger();
                DatabaseUsageCacheTestNodeObserver.CreatingCrashEnabledOnce = true;

                var handler = new DatabaseUsageHandler(logger);
                var _       = await handler.GetDatabaseUsageAsync(false, CancellationToken.None);

                Assert.AreEqual(logger.LastLevel, LogLevel.Warning);
                Assert.IsNotNull(logger.LastMessage);
                Assert.IsTrue(logger.LastMessage.Contains("An error occurred during saving DatabaseUsage.cache"));
            }).ConfigureAwait(false);
        }