Commit 02f6991f authored by Kirill Smelkov's avatar Kirill Smelkov

golang: Add test for blocked select(send|recv) vs close

This test passes, but the functionality was not tested before. In
particular all tests were passing even with the following hand-edits:

    --- a/golang/__init__.py
    +++ b/golang/__init__.py
    @@ -627,7 +627,7 @@ def selected():
             sel = g.which
             if isinstance(sel, _SendWaiting):
                 if not sel.ok:
    -                panic("send on closed channel")
    +                panic("send on closed channel ZZZ")
                 return sel.sel_n, None

             if isinstance(sel, _RecvWaiting):

with added tests the bug is caught and reported:

    def test_select():
        N = 1000 # times to do repeated select/chan or select/select interactions

        # sync: close vs select(send)
        ch = chan()
        def _():
            waitBlocked(ch.send)
            ch.close()
        go(_)
>       with panics("send on closed channel"): select((ch.send, 0))

golang_test.py:353:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <golang.golang_test.panics instance at 0x7fc1da66e5f0>, exc_type = <class 'golang._PanicError'>, exc_val = _PanicError('send on closed channel ZZZ',)
exc_tb = <traceback object at 0x7fc1dabc33b0>

    def __exit__(self, exc_type, exc_val, exc_tb):
        ok = self.raises.__exit__(exc_type, exc_val, exc_tb)
        if not ok:
            return ok
        # _PanicError raised - let's check panic argument
>       assert self.exc_info.value.args == (self.arg,)
E       AssertionError: assert ('send on clo...channel ZZZ',) == ('send on closed channel',)
E         At index 0 diff: 'send on closed channel ZZZ' != 'send on closed channel'
E         Use -v to get the full diff

golang_test.py:1032: AssertionError
parent c6bb9eb3
...@@ -344,6 +344,22 @@ def bench_chan(b): ...@@ -344,6 +344,22 @@ def bench_chan(b):
def test_select(): def test_select():
N = 1000 # times to do repeated select/chan or select/select interactions N = 1000 # times to do repeated select/chan or select/select interactions
# sync: close vs select(send)
ch = chan()
def _():
waitBlocked(ch.send)
ch.close()
go(_)
with panics("send on closed channel"): select((ch.send, 0))
# sync: close vs select(recv)
ch = chan()
def _():
waitBlocked(ch.recv)
ch.close()
go(_)
assert select(ch.recv) == (0, None)
# non-blocking try send: not ok # non-blocking try send: not ok
ch = chan() ch = chan()
for i in range(N): for i in range(N):
......
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