summaryrefslogtreecommitdiff
path: root/test/git/async/test_channel.py
blob: 444a076a0f008f5540e9a17e179f4f74eb7ddb50 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Channel testing"""
from test.testlib import *
from git.async.channel import *

import time

class TestChannels(TestBase):
	
	def test_base(self):
		# creating channel yields a write and a read channal
		wc, rc = mkchannel()
		assert isinstance(wc, WChannel)		# default args
		assert isinstance(rc, RChannel)
		
		
		# TEST UNLIMITED SIZE CHANNEL - writing+reading is FIFO
		item = 1
		item2 = 2
		wc.write(item)
		wc.write(item2)
		
		# read all - it blocks as its still open for writing
		to = 0.2
		st = time.time()
		assert rc.read(timeout=to) == [item, item2]
		assert time.time() - st >= to
		
		# next read blocks. it waits a second
		st = time.time()
		assert len(rc.read(1, True, to)) == 0
		assert time.time() - st >= to
		
		# writing to a closed channel raises
		assert not wc.closed()
		wc.close()
		assert wc.closed()
		wc.close()	# fine
		assert wc.closed()
		
		self.failUnlessRaises(ReadOnly, wc.write, 1)
		
		# reading from a closed channel never blocks
		assert len(rc.read()) == 0
		assert len(rc.read(5)) == 0
		assert len(rc.read(1)) == 0