Commit cb5bfdd2 authored by Kirill Smelkov's avatar Kirill Smelkov

golang: Test that buffered channel releases objects from buffer on chan GC

Currently it behaves correctly, but this aspect will need to be
explicitly cared about when channel implementation moves to C. Add test
to make sure it won't regress.
parent c5810987
......@@ -26,6 +26,7 @@ from pytest import raises
from os.path import dirname
import os, sys, threading, inspect, subprocess
from six.moves import range as xrange
import gc, weakref
import golang
from golang import _chan_recv, _chan_send
......@@ -183,6 +184,23 @@ def test_chan():
ch.close()
assert done.recv() == 'b'
# buffered: releases objects in buffer on chan gc
ch = chan(3)
class Obj(object): pass
obj1 = Obj(); w1 = weakref.ref(obj1); assert w1() is obj1
obj2 = Obj(); w2 = weakref.ref(obj2); assert w2() is obj2
ch.send(obj1)
ch.send(obj2)
del obj1
del obj2
gc.collect()
assert w1() is not None
assert w2() is not None
ch = None
gc.collect()
assert w1() is None
assert w2() is None
# benchmark sync chan send/recv.
def bench_chan(b):
......
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