10000 bpo-32604: Improve subinterpreter tests. by ericsnowcurrently · Pull Request #6914 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-32604: Improve subinterpreter tests. #6914

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 18 commits into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
channel_drop_interpreter -> channel_release.
  • Loading branch information
ericsnowcurrently committed May 16, 2018
commit 5242a349edbf5d82a9987f4719c8edea337a273d
48 changes: 25 additions & 23 deletions Lib/test/test__xxsubinterpreters.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,18 +904,20 @@ def test_ids_global(self):

####################

def test_drop_single_user(self):
# XXX Add more tests for channel_release().

def test_release_single_user(self):
cid = interpreters.channel_create()
interpreters.channel_send(cid, b'spam')
interpreters.channel_recv(cid)
interpreters.channel_drop_interpreter(cid, send=True, recv=True)
interpreters.channel_release(cid, send=True, recv=True)

with self.assertRaises(interpreters.ChannelClosedError):
interpreters.channel_send(cid, b'eggs')
with self.assertRaises(interpreters.ChannelClosedError):
interpreters.channel_recv(cid)

def test_drop_multiple_users(self):
def test_release_multiple_users(self):
cid = interpreters.channel_create()
id1 = interpreters.create()
id2 = interpreters.create()
Expand All @@ -926,98 +928,98 @@ def test_drop_multiple_users(self):
out = _run_output(id2, dedent(f"""
import _xxsubinterpreters as _interpreters
obj = _interpreters.channel_recv({int(cid)})
_interpreters.channel_drop_interpreter({int(cid)})
_interpreters.channel_release({int(cid)})
print(repr(obj))
"""))
interpreters.run_string(id1, dedent(f"""
_interpreters.channel_drop_interpreter({int(cid)})
_interpreters.channel_release({int(cid)})
"""))

self.assertEqual(out.strip(), "b'spam'")

def test_drop_no_kwargs(self):
def test_release_no_kwargs(self):
cid = interpreters.channel_create()
interpreters.channel_send(cid, b'spam')
interpreters.channel_recv(cid)
interpreters.channel_drop_interpreter(cid)
interpreters.channel_release(cid)

with self.assertRaises(interpreters.ChannelClosedError):
interpreters.channel_send(cid, b'eggs')
with self.assertRaises(interpreters.ChannelClosedError):
interpreters.channel_recv(cid)

def test_drop_multiple_times(self):
def test_release_multiple_times(self):
cid = interpreters.channel_create()
interpreters.channel_send(cid, b'spam')
interpreters.channel_recv(cid)
interpreters.channel_drop_interpreter(cid, send=True, recv=True)
interpreters.channel_release(cid, send=True, recv=True)

with self.assertRaises(interpreters.ChannelClosedError):
interpreters.channel_drop_interpreter(cid, send=True, recv=True)
interpreters.channel_release(cid, send=True, recv=True)

def test_drop_with_unused_items(self):
def test_release_with_unused_items(self):
cid = interpreters.channel_create()
interpreters.channel_send(cid, b'spam')
interpreters.channel_send(cid, b'ham')
interpreters.channel_drop_interpreter(cid, send=True, recv=True)
interpreters.channel_release(cid, send=True, recv=True)

with self.assertRaises(interpreters.ChannelClosedError):
interpreters.channel_recv(cid)

def test_drop_never_used(self):
def test_release_never_used(self):
cid = interpreters.channel_create()
interpreters.channel_drop_interpreter(cid)
interpreters.channel_release(cid)

with self.assertRaises(interpreters.ChannelClosedError):
interpreters.channel_send(cid, b'spam')
with self.assertRaises(interpreters.ChannelClosedError):
interpreters.channel_recv(cid)

def test_drop_by_unassociated_interp(self):
def test_release_by_unassociated_interp(self):
cid = interpreters.channel_create()
interpreters.channel_send(cid, b'spam')
interp = interpreters.create()
interpreters.run_string(interp, dedent(f"""
import _xxsubinterpreters as _interpreters
_interpreters.channel_drop_interpreter({int(cid)})
_interpreters.channel_release({int(cid)})
"""))
obj = interpreters.channel_recv(cid)
interpreters.channel_drop_interpreter(cid)
interpreters.channel_release(cid)

with self.assertRaises(interpreters.ChannelClosedError):
interpreters.channel_send(cid, b'eggs')
self.assertEqual(obj, b'spam')

def test_drop_close_if_unassociated(self):
def test_release_close_if_unassociated(self):
cid = interpreters.channel_create()
interp = interpreters.create()
interpreters.run_string(interp, dedent(f"""
import _xxsubinterpreters as _interpreters
obj = _interpreters.channel_send({int(cid)}, b'spam')
_interpreters.channel_drop_interpreter({int(cid)})
_interpreters.channel_release({int(cid)})
"""))

with self.assertRaises(interpreters.ChannelClosedError):
interpreters.channel_recv(cid)

def test_drop_partially(self):
def test_release_partially(self):
# XXX Is partial close too weird/confusing?
cid = interpreters.channel_create()
interpreters.channel_send(cid, None)
interpreters.channel_recv(cid)
interpreters.channel_send(cid, b'spam')
interpreters.channel_drop_interpreter(cid, send=True)
interpreters.channel_release(cid, send=True)
obj = interpreters.channel_recv(cid)

self.assertEqual(obj, b'spam')

def test_drop_used_multiple_times_by_single_user(self):
def test_release_used_multiple_times_by_single_user(self):
cid = interpreters.channel_create()
interpreters.channel_send(cid, b'spam')
interpreters.channel_send(cid, b'spam')
interpreters.channel_send(cid, b'spam')
interpreters.channel_recv(cid)
interpreters.channel_drop_interpreter(cid, send=True, recv=True)
interpreters.channel_release(cid, send=True, recv=True)

with self.assertRaises(interpreters.ChannelClosedError):
interpreters.channel_send(cid, b'eggs')
Expand Down
12 changes: 6 additions & 6 deletions Modules/_xxsubinterpretersmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -2530,15 +2530,15 @@ Close the channel for all interpreters. Once the channel's ID has\n\
no more ref counts the channel will be destroyed.");

static PyObject *
channel_drop_interpreter(PyObject *self, PyObject *args, PyObject *kwds)
channel_release(PyObject *self, PyObject *args, PyObject *kwds)
{
// Note that only the current interpreter is affected.
static char *kwlist[] = {"id", "send", "recv", NULL};
PyObject *id;
int send = -1;
int recv = -1;
if (!PyArg_ParseTupleAndKeywords(args, kwds,
"O|$pp:channel_drop_interpreter", kwlist,
"O|$pp:channel_release", kwlist,
&id, &send, &recv))
return NULL;

Expand All @@ -2564,8 +2564,8 @@ channel_drop_interpreter(PyObject *self, PyObject *args, PyObject *kwds)
Py_RETURN_NONE;
}

PyDoc_STRVAR(channel_drop_interpreter_doc,
"channel_drop_interpreter(ID, *, send=None, recv=None)\n\
PyDoc_STRVAR(channel_release_doc,
"channel_release(ID, *, send=None, recv=None)\n\
\n\
Close the channel for the current interpreter. 'send' and 'recv'\n\
(bool) may be used to indicate the ends to close. By default both\n\
Expand Down Expand Up @@ -2608,8 +2608,8 @@ static PyMethodDef module_functions[] = {
METH_VARARGS, channel_recv_doc},
{"channel_close", channel_close,
METH_O, channel_close_doc},
{"channel_drop_interpreter", (PyCFunction)channel_drop_interpreter,
METH_VARARGS | METH_KEYWORDS, channel_drop_interpreter_doc},
{"channel_release", (PyCFunction)channel_release,
METH_VARARGS | METH_KEYWORDS, channel_release_doc},
{"_channel_id", (PyCFunction)channel__channel_id,
METH_VARARGS | METH_KEYWORDS, NULL},

Expand Down
0