Skip to content

Closing consumer multiple times should not raise RunTimeError #678

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

Merged
merged 1 commit into from
May 14, 2020
Merged
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
8 changes: 2 additions & 6 deletions confluent_kafka/src/Consumer.c
Original file line number Diff line number Diff line change
Expand Up @@ -981,11 +981,8 @@ static PyObject *Consumer_consume (Handle *self, PyObject *args,
static PyObject *Consumer_close (Handle *self, PyObject *ignore) {
CallState cs;

if (!self->rk) {
PyErr_SetString(PyExc_RuntimeError,
"Consumer already closed");
return NULL;
}
if (!self->rk)
Py_RETURN_NONE;

CallState_begin(self, &cs);

Expand Down Expand Up @@ -1275,7 +1272,6 @@ static PyMethodDef Consumer_methods[] = {
"see :py:func::`poll()` for more info.\n"
"\n"
" :rtype: None\n"
" :raises: RuntimeError if called on a closed consumer\n"
"\n"
},
{ "list_topics", (PyCFunction)list_topics, METH_VARARGS|METH_KEYWORDS,
Expand Down
9 changes: 3 additions & 6 deletions tests/test_Consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ def test_offsets_for_times():
c.close()


def test_multiple_close_throw_exception():
""" Calling Consumer.close() multiple times should throw Runtime Exception
def test_multiple_close_does_not_throw_exception():
""" Calling Consumer.close() multiple times should not throw Runtime Exception
"""
c = Consumer({'group.id': 'test',
'enable.auto.commit': True,
Expand All @@ -222,10 +222,7 @@ def test_multiple_close_throw_exception():

c.unsubscribe()
c.close()

with pytest.raises(RuntimeError) as ex:
c.close()
assert ex.match('Consumer already closed')
c.close()


def test_any_method_after_close_throws_exception():
Expand Down