Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disposing Consumer should interrupt consumption #98

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/kafka-net/Consumer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ public void Dispose()

_options.Log.DebugFormat("Consumer: Disposing...");
_disposeToken.Cancel();
_fetchResponseQueue.CompleteAdding();

//wait for all threads to unwind
foreach (var task in _partitionPollingIndex.Values.Where(task => task != null))
Expand Down
22 changes: 22 additions & 0 deletions src/kafka-tests/Unit/ConsumerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,28 @@ public void CancellationShouldInterruptConsumption()
}
}

[Test]
public void DisposeShouldInterruptConsumption()
{
var routerProxy = new BrokerRouterProxy(new MoqMockingKernel());
routerProxy.BrokerConn0.FetchResponseFunction = () => { return new FetchResponse(); };

var router = routerProxy.Create();

var options = CreateOptions(router);

Task consumeTask;
using (var consumer = new Consumer(options))
{
consumeTask = Task.Run(() => consumer.Consume().FirstOrDefault());

//wait until the fake broker is running and requesting fetches
TaskTest.WaitFor(() => routerProxy.BrokerConn0.FetchRequestCallCount > 10);
}

Assert.True(consumeTask.Wait(TimeSpan.FromSeconds(1)));
}

[Test]
public void ConsumerWhitelistShouldOnlyConsumeSpecifiedPartition()
{
Expand Down