gh-121596: Fix Sharing Interpreter Channels (gh-121597)

This fixes a mistake in gh-113012 and adds a test that verifies the fix.
This commit is contained in:
Eric Snow 2024-07-10 15:31:09 -06:00 committed by GitHub
parent 7641743d48
commit 35a67e36aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View file

@ -48,6 +48,7 @@ class TestChannels(TestBase):
self.assertEqual(after, created)
def test_shareable(self):
interp = interpreters.create()
rch, sch = channels.create()
self.assertTrue(
@ -60,8 +61,25 @@ class TestChannels(TestBase):
rch2 = rch.recv()
sch2 = rch.recv()
interp.prepare_main(rch=rch, sch=sch)
sch.send_nowait(rch)
sch.send_nowait(sch)
interp.exec(dedent("""
rch2 = rch.recv()
sch2 = rch.recv()
assert rch2 == rch
assert sch2 == sch
sch.send_nowait(rch2)
sch.send_nowait(sch2)
"""))
rch3 = rch.recv()
sch3 = rch.recv()
self.assertEqual(rch2, rch)
self.assertEqual(sch2, sch)
self.assertEqual(rch3, rch)
self.assertEqual(sch3, sch)
def test_is_closed(self):
rch, sch = channels.create()