• Kirill Smelkov's avatar
    golang: Add test for blocked select(send|recv) vs close · 02f6991f
    Kirill Smelkov authored
    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
    02f6991f
Name
Last commit
Last update
golang Loading commit data...
gpython Loading commit data...
.gitignore Loading commit data...
CHANGELOG.rst Loading commit data...
COPYING Loading commit data...
MANIFEST.in Loading commit data...
README.rst Loading commit data...
setup.py Loading commit data...
tox.ini Loading commit data...