Example #1
0
        public async Task SessionCreateIsThrottled()
        {
            using (var pool = new SessionPool())
            {
                pool.Options.MaximumConcurrentSessionCreates = 2;

                // We use a specially designed mock that records simultaneous create calls.
                // Moq actually does internal synchronization that disallows parallel calls.
                var mockClient = new ParallelSpannerClient();

                var sessionList = Enumerable.Range(0, 100)
                                  .Select(x => CreateSessionAsync(pool, mockClient))
                                  .ToList();

                await Task.WhenAll(sessionList);

                Assert.True(mockClient.MaxConcurrentRequests <= pool.Options.MaximumConcurrentSessionCreates);
            }
        }
        public async Task SessionCreateIsThrottled()
        {
            using (var pool = new SessionPool())
            {
                pool.Options.MaximumConcurrentSessionCreates = 2;

                //we use a specially designed mock that records simultaneous create calls.
                //Moq actually does internal synchronization that disallows parallel calls.
                var mockClient = new ParallelSpannerClient();

                var sessionList = Enumerable.Range(0, 100).Select(
                    x => pool.CreateSessionFromPoolAsync(
                        mockClient, s_defaultName.ProjectId,
                        s_defaultName.InstanceId, s_defaultName.DatabaseId, null, CancellationToken.None)).ToList();

                await Task.WhenAll(sessionList).ConfigureAwait(false);

                Assert.True(mockClient.MaxConcurrentRequests <= pool.Options.MaximumConcurrentSessionCreates);
            }
        }