public async Task FillCacheWithoutRemovingClients()
        {
            int maxClientCount    = 10;
            var clientWrapperList = new List <(ResourceWrapper <GrpcCopyClient> Wrapper, GrpcCopyClient Client)>();

            _clientCache = new GrpcCopyClientCache(_context, maxClientCount: maxClientCount, maxClientAgeMinutes: 63, waitBetweenCleanupMinutes: 30, bufferSize: 65536);

            for (int i = 0; i < maxClientCount; i++)
            {
                var clientWrapper = await _clientCache.CreateAsync(LocalHost, i, true);

                clientWrapperList.Add((clientWrapper, clientWrapper.Value));
            }

            // Create new clients for every port
            Assert.Equal(maxClientCount, _clientCache.Counter.GetCounterValue(ResourcePoolCounters.Created));

            // Zero clients were cleaned
            Assert.Equal(0, _clientCache.Counter.GetCounterValue(ResourcePoolCounters.Cleaned));

            // Zero clients were reused
            Assert.Equal(0, _clientCache.Counter.GetCounterValue(ResourcePoolCounters.Reused));

            foreach (var c in clientWrapperList)
            {
                c.Wrapper._lastUseTime -= TimeSpan.FromDays(1);
                c.Wrapper.Dispose();
            }

            await _clientCache.CleanupAsync();

            // All clients were cleaned
            Assert.Equal(maxClientCount, _clientCache.Counter.GetCounterValue(ResourcePoolCounters.Cleaned));
        }
        public async Task ValidateBackgroundCleanup()
        {
            List <GrpcCopyClient> clientList = new List <GrpcCopyClient>();
            var key = new GrpcCopyClientKey(LocalHost, 11, true);
            ResourceWrapper <GrpcCopyClient> clientWrapper;

            using (clientWrapper = await _clientCache.CreateAsync(key.Host, key.GrpcPort, key.UseCompression))
            {
                clientList.Add(clientWrapper.Value);
                clientWrapper._lastUseTime = DateTime.UtcNow - TimeSpan.FromHours(2);
            }

            // Start cleanup now; don't wait for another loop
            await _clientCache.CleanupAsync(force : false, numberToRelease : int.MaxValue);

            var newClient = await _clientCache.CreateAsync(key.Host, key.GrpcPort, key.UseCompression);

            clientList.Add(newClient.Value);

            // If we found a different client, then cleanup successfully removed the original client
            Assert.NotSame(newClient.Value, clientWrapper.Value);
            Assert.Equal(1, newClient.Uses);
        }