예제 #1
0
파일: testFuture.py 프로젝트: sinofeng/vlcp
    def test_ensure_result2(self):
        rc = self.rc
        future = Future(self.server.scheduler)
        # Test send before wait
        obj = [0]
        obj2 = [0]

        async def routine_sender():
            try:
                with future.ensure_result():
                    raise ValueError('abc')
            except ValueError:
                obj2[0] = True
            else:
                obj2[0] = False

        async def routine_receiver():
            await rc.wait_with_timeout(0.1)
            try:
                await future.wait()
            except ValueError as exc:
                obj[0] = str(exc)
            else:
                obj[0] = None

        rc.subroutine(routine_sender())
        rc.subroutine(routine_receiver())
        self.server.serve()
        self.assertEqual(obj[0], 'abc')
        self.assertEqual(obj2[0], True)
예제 #2
0
파일: testFuture.py 프로젝트: sinofeng/vlcp
    def test_ensure_result4(self):
        rc = self.rc
        future = Future(self.server.scheduler)
        # Test send before wait
        obj = [0]
        obj2 = [0]

        async def routine_sender():
            try:
                with future.ensure_result(False, 'abc'):
                    pass
            except ValueError:
                obj2[0] = True
            else:
                obj2[0] = False

        async def routine_receiver():
            await rc.wait_with_timeout(0.1)
            obj[0] = await future.wait()

        rc.subroutine(routine_sender())
        rc.subroutine(routine_receiver())
        self.server.serve()
        self.assertEqual(obj[0], 'abc')
        self.assertEqual(obj2[0], False)
예제 #3
0
    def test_ensure_result4(self):
        rc = self.rc
        future = Future(self.server.scheduler)
        # Test send before wait
        obj = [0]
        obj2 = [0]

        def routine_sender():
            try:
                with future.ensure_result(False, 'abc'):
                    pass
            except ValueError:
                obj2[0] = True
            else:
                obj2[0] = False
            if False:
                yield

        def routine_receiver():
            for m in rc.waitWithTimeout(0.1):
                yield m
            for m in future.wait(rc):
                yield m
            obj[0] = rc.retvalue

        rc.subroutine(routine_sender())
        rc.subroutine(routine_receiver())
        self.server.serve()
        self.assertEqual(obj[0], 'abc')
        self.assertEqual(obj2[0], False)
예제 #4
0
    def test_ensure_result3(self):
        rc = self.rc
        future = Future(self.server.scheduler)
        # Test send before wait
        obj = [0]
        obj2 = [0]

        def routine_sender():
            try:
                with future.ensure_result(True):
                    raise ValueError('abc')
            except ValueError:
                obj2[0] = True
            else:
                obj2[0] = False
            if False:
                yield

        def routine_receiver():
            for m in rc.waitWithTimeout(0.1):
                yield m
            try:
                for m in future.wait(rc):
                    yield m
            except ValueError as exc:
                obj[0] = str(exc)
            else:
                obj[0] = None

        rc.subroutine(routine_sender())
        rc.subroutine(routine_receiver())
        self.server.serve()
        self.assertEqual(obj[0], 'abc')
        self.assertEqual(obj2[0], False)
예제 #5
0
    def test_future_exception1(self):
        rc = self.rc
        future = Future(self.server.scheduler)
        # Test send before wait
        obj = [0]

        def routine_sender():
            future.set_exception(ValueError('abc'))
            if False:
                yield

        def routine_receiver():
            for m in rc.waitWithTimeout(0.1):
                yield m
            try:
                for m in future.wait(rc):
                    yield m
            except ValueError as exc:
                obj[0] = str(exc)
            else:
                obj[0] = None

        rc.subroutine(routine_sender())
        rc.subroutine(routine_receiver())
        self.server.serve()
        self.assertEqual(obj[0], 'abc')
예제 #6
0
파일: testFuture.py 프로젝트: sinofeng/vlcp
    def test_future_await2(self):
        rc = self.rc
        future = Future(self.server.scheduler)
        # Test send after wait
        obj = [0]

        async def routine_sender():
            await rc.wait_with_timeout(0.1)
            future.set_result('abc')

        async def routine_receiver():
            obj[0] = await future

        rc.subroutine(routine_sender())
        rc.subroutine(routine_receiver())
        self.server.serve()
        self.assertEqual(obj[0], 'abc')
예제 #7
0
파일: testFuture.py 프로젝트: sinofeng/vlcp
    def test_future_nowait1(self):
        rc = self.rc
        future = Future(self.server.scheduler)
        # Test send before wait
        obj = [None, None]

        async def routine_sender():
            future.set_result('abc')

        async def routine_receiver():
            await rc.wait_with_timeout(0.1)
            obj[0] = future.done()
            obj[1] = future.result()

        rc.subroutine(routine_sender())
        rc.subroutine(routine_receiver())
        self.server.serve()
        self.assertEqual(obj, [True, 'abc'])
예제 #8
0
파일: testFuture.py 프로젝트: sinofeng/vlcp
    def test_ensure_result(self):
        rc = self.rc
        future = Future(self.server.scheduler)
        # Test send before wait
        obj = [0]

        async def routine_sender():
            with future.ensure_result():
                future.set_result('abc')

        async def routine_receiver():
            await rc.wait_with_timeout(0.1)
            obj[0] = await future.wait()

        rc.subroutine(routine_sender())
        rc.subroutine(routine_receiver())
        self.server.serve()
        self.assertEqual(obj[0], 'abc')
예제 #9
0
    def test_future2(self):
        rc = self.rc
        future = Future(self.server.scheduler)
        # Test send after wait
        obj = [0]

        def routine_sender():
            for m in rc.waitWithTimeout(0.1):
                yield m
            future.set_result('abc')

        def routine_receiver():
            for m in future.wait(rc):
                yield m
            obj[0] = rc.retvalue

        rc.subroutine(routine_sender())
        rc.subroutine(routine_receiver())
        self.server.serve()
        self.assertEqual(obj[0], 'abc')
예제 #10
0
파일: testFuture.py 프로젝트: sinofeng/vlcp
    def test_future_nowait_exception2(self):
        rc = self.rc
        future = Future(self.server.scheduler)
        # Test send before wait
        obj = [None, None]

        async def routine_sender():
            await rc.wait_with_timeout(0.1)
            future.set_exception(ValueError('abc'))

        async def routine_receiver():
            try:
                obj[0] = future.done()
                obj[1] = future.result()
            except ValueError as exc:
                obj[1] = str(exc)

        rc.subroutine(routine_sender())
        rc.subroutine(routine_receiver())
        self.server.serve()
        self.assertEqual(obj, [False, None])
예제 #11
0
    def test_future_nowait2(self):
        rc = self.rc
        future = Future(self.server.scheduler)
        # Test send before wait
        obj = [None, None]

        def routine_sender():
            for m in rc.waitWithTimeout(0.1):
                yield m
            future.set_result('abc')

        def routine_receiver():
            obj[0] = future.done()
            obj[1] = future.result()
            if False:
                yield

        rc.subroutine(routine_sender())
        rc.subroutine(routine_receiver())
        self.server.serve()
        self.assertEqual(obj, [False, None])
예제 #12
0
파일: testFuture.py 프로젝트: sinofeng/vlcp
    def test_future_exception2(self):
        rc = self.rc
        future = Future(self.server.scheduler)
        # Test send before wait
        obj = [0]

        async def routine_sender():
            await rc.wait_with_timeout(0.1)
            future.set_exception(ValueError('abc'))

        async def routine_receiver():
            try:
                await future.wait()
            except ValueError as exc:
                obj[0] = str(exc)
            else:
                obj[0] = None

        rc.subroutine(routine_sender())
        rc.subroutine(routine_receiver())
        self.server.serve()
        self.assertEqual(obj[0], 'abc')
예제 #13
0
    def test_future_nowait_exception1(self):
        rc = self.rc
        future = Future(self.server.scheduler)
        # Test send before wait
        obj = [None, None]

        def routine_sender():
            future.set_exception(ValueError('abc'))
            if False:
                yield

        def routine_receiver():
            for m in rc.waitWithTimeout(0.1):
                yield m
            try:
                obj[0] = future.done()
                obj[1] = future.result()
            except ValueError as exc:
                obj[1] = str(exc)

        rc.subroutine(routine_sender())
        rc.subroutine(routine_receiver())
        self.server.serve()
        self.assertEqual(obj, [True, 'abc'])