Commit 2fc6797c authored by Kirill Smelkov's avatar Kirill Smelkov

select: Another select-select test which reuses channels during iterations

Previous select-select test uses 2 channels and recreats them every
iteration. However the bug we just saw in b51b8d5d (select: Run tests
more thoroughly) is of parasitic nature - where misbehaviour depends on
what state has been left there from previous select and whether the race
to get to that state fast enough succeeded.

So add a more secialized test which tries to trigger the parasitic
effects that depend on previous state left by select on the channels.

The test, similarly to b51b8d5d, currently fails.
parent b51b8d5d
...@@ -302,6 +302,7 @@ def test_select(): ...@@ -302,6 +302,7 @@ def test_select():
# select vs select # select vs select
# channels are recreated on every iteration.
for i in range(N): for i in range(N):
ch1 = chan() ch1 = chan()
ch2 = chan() ch2 = chan()
...@@ -340,6 +341,48 @@ def test_select(): ...@@ -340,6 +341,48 @@ def test_select():
assert len(ch2._sendq) == len(ch2._recvq) == 0 assert len(ch2._sendq) == len(ch2._recvq) == 0
# select vs select
# channels are shared for all iterations.
# (this tries to trigger parasitic effects from already performed select)
ch1 = chan()
ch2 = chan()
done = chan()
def _():
for i in range(N):
_, _rx = select(
(ch1.send, 'a%d' % i),
(ch2.send, 'xxx2'),
)
assert (_, _rx) == (0, None)
_, _rx = select(
(ch1.send, 'yyy2'),
ch2.recv,
)
assert (_, _rx) == (1, 'b%d' % i)
done.close()
go(_)
for i in range(N):
_, _rx = select(
ch1.recv,
(ch2.send, 'xxx1'),
)
assert (_, _rx) == (0, 'a%d' % i)
_, _rx = select(
(ch1.send, 'yyy1'),
(ch2.send, 'b%d' % i),
)
assert (_, _rx) == (1, None)
done.recv()
assert len(ch1._sendq) == len(ch1._recvq) == 0
assert len(ch2._sendq) == len(ch2._recvq) == 0
def test_method(): def test_method():
# test how @method works # test how @method works
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment