Commit c5810987 authored by Kirill Smelkov's avatar Kirill Smelkov

golang: Run all select tests "more thoroughly"

Starting from b51b8d5d (select: Run tests more thoroughly) we are
running select subtests in repeated mode with N=1000. However not all
select subtests were run in repeated mode - for example e.g.
"non-blocking try send: not ok" was being run only once.

-> Rework all select subtests to be run in repeated mode to increase the
probability of catching bugs.
parent fa667412
...@@ -207,24 +207,26 @@ def test_select(): ...@@ -207,24 +207,26 @@ def test_select():
# non-blocking try send: not ok # non-blocking try send: not ok
ch = chan() ch = chan()
_, _rx = select( for i in range(N):
(ch.send, 0), _, _rx = select(
default, (ch.send, 0),
) default,
assert (_, _rx) == (1, None) )
assert (_, _rx) == (1, None)
# non-blocking try recv: not ok # non-blocking try recv: not ok
_, _rx = select( for i in range(N):
ch.recv, _, _rx = select(
default, ch.recv,
) default,
assert (_, _rx) == (1, None) )
assert (_, _rx) == (1, None)
_, _rx = select( _, _rx = select(
ch.recv_, ch.recv_,
default, default,
) )
assert (_, _rx) == (1, None) assert (_, _rx) == (1, None)
# non-blocking try send: ok # non-blocking try send: ok
ch = chan() ch = chan()
...@@ -281,16 +283,22 @@ def test_select(): ...@@ -281,16 +283,22 @@ def test_select():
ch2 = chan() ch2 = chan()
done = chan() done = chan()
def _(): def _():
waitBlocked(ch1.send) while 1:
assert ch1.recv() == 'a' waitBlocked(ch1.send)
x = ch1.recv()
if x == 'stop':
break
assert x == 'a'
done.close() done.close()
go(_) go(_)
_, _rx = select( for i in range(N):
(ch1.send, 'a'), _, _rx = select(
(ch2.send, 'b'), (ch1.send, 'a'),
) (ch2.send, 'b'),
assert (_, _rx) == (0, None) )
assert (_, _rx) == (0, None)
ch1.send('stop')
done.recv() done.recv()
assert len_sendq(ch1) == len_recvq(ch1) == 0 assert len_sendq(ch1) == len_recvq(ch1) == 0
assert len_sendq(ch2) == len_recvq(ch2) == 0 assert len_sendq(ch2) == len_recvq(ch2) == 0
...@@ -301,16 +309,18 @@ def test_select(): ...@@ -301,16 +309,18 @@ def test_select():
ch2 = chan() ch2 = chan()
done = chan() done = chan()
def _(): def _():
waitBlocked(ch1.recv) for i in range(N):
ch1.send('a') waitBlocked(ch1.recv)
ch1.send('a')
done.close() done.close()
go(_) go(_)
_, _rx = select( for i in range(N):
ch1.recv, _, _rx = select(
ch2.recv, ch1.recv,
) ch2.recv,
assert (_, _rx) == (0, 'a') )
assert (_, _rx) == (0, 'a')
done.recv() done.recv()
assert len_sendq(ch1) == len_recvq(ch1) == 0 assert len_sendq(ch1) == len_recvq(ch1) == 0
assert len_sendq(ch2) == len_recvq(ch2) == 0 assert len_sendq(ch2) == len_recvq(ch2) == 0
...@@ -321,16 +331,22 @@ def test_select(): ...@@ -321,16 +331,22 @@ def test_select():
ch2 = chan() ch2 = chan()
done = chan() done = chan()
def _(): def _():
waitBlocked(ch1.send) while 1:
assert ch1.recv() == 'a' waitBlocked(ch1.send)
x = ch1.recv()
if x == 'stop':
break
assert x == 'a'
done.close() done.close()
go(_) go(_)
_, _rx = select( for i in range(N):
(ch1.send, 'a'), _, _rx = select(
ch2.recv, (ch1.send, 'a'),
) ch2.recv,
assert (_, _rx) == (0, None) )
assert (_, _rx) == (0, None)
ch1.send('stop')
done.recv() done.recv()
assert len_sendq(ch1) == len_recvq(ch1) == 0 assert len_sendq(ch1) == len_recvq(ch1) == 0
assert len_sendq(ch2) == len_recvq(ch2) == 0 assert len_sendq(ch2) == len_recvq(ch2) == 0
...@@ -341,16 +357,18 @@ def test_select(): ...@@ -341,16 +357,18 @@ def test_select():
ch2 = chan() ch2 = chan()
done = chan() done = chan()
def _(): def _():
waitBlocked(ch1.recv) for i in range(N):
ch1.send('a') waitBlocked(ch1.recv)
ch1.send('a')
done.close() done.close()
go(_) go(_)
_, _rx = select( for i in range(N):
ch1.recv, _, _rx = select(
(ch2.send, 'b'), ch1.recv,
) (ch2.send, 'b'),
assert (_, _rx) == (0, 'a') )
assert (_, _rx) == (0, 'a')
done.recv() done.recv()
assert len_sendq(ch1) == len_recvq(ch1) == 0 assert len_sendq(ch1) == len_recvq(ch1) == 0
assert len_sendq(ch2) == len_recvq(ch2) == 0 assert len_sendq(ch2) == len_recvq(ch2) == 0
......
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