Example #1
0
        public void StoppingCollectionShouldMarkAsComplete()
        {
            var collection = new NagleBlockingCollection <int>(100);

            using (collection)
            {
                Assert.That(collection.IsCompleted, Is.False);
                collection.CompleteAdding();
                Assert.That(collection.IsCompleted, Is.True);
            }
        }
Example #2
0
        /// <summary>
        /// Stops the producer from accepting new messages, and optionally waits for in-flight messages to be sent before returning.
        /// </summary>
        /// <param name="waitForRequestsToComplete">True to wait for in-flight requests to complete, false otherwise.</param>
        /// <param name="maxWait">Maximum time to wait for in-flight requests to complete. Has no effect if <c>waitForRequestsToComplete</c> is false</param>
        public void Stop(bool waitForRequestsToComplete = true, TimeSpan?maxWait = null)
        {
            //block incoming data
            _nagleBlockingCollection.CompleteAdding();

            if (waitForRequestsToComplete)
            {
                //wait for the collection to drain
                _postTask.Wait(maxWait ?? TimeSpan.FromSeconds(MaxDisposeWaitSeconds));
            }

            _stopToken.Cancel();
        }
Example #3
0
        public async void StoppingCollectionShouldPreventMoreItemsAdded()
        {
            var collection = new NagleBlockingCollection <int>(100);

            using (collection)
            {
                await collection.AddAsync(1, CancellationToken.None);

                Assert.That(collection.Count, Is.EqualTo(1));
                collection.CompleteAdding();
                await collection.AddAsync(1, CancellationToken.None);
            }
        }
 public async void StoppingCollectionShouldPreventMoreItemsAdded()
 {
     var collection = new NagleBlockingCollection<int>(100);
     using (collection)
     {
         await collection.AddAsync(1, CancellationToken.None);
         Assert.That(collection.Count, Is.EqualTo(1));
         collection.CompleteAdding();
         await collection.AddAsync(1, CancellationToken.None);
     }
 }
 public void StoppingCollectionShouldMarkAsComplete()
 {
     var collection = new NagleBlockingCollection<int>(100);
     using (collection)
     {
         Assert.That(collection.IsCompleted, Is.False);
         collection.CompleteAdding();
         Assert.That(collection.IsCompleted, Is.True);
     }
 }