Exemple #1
0
 def testServerClientSsl(self):
     c1 = Client('ssl://localhost:199', self.protocolClient, self.scheduler, 'testcerts/client.key', 'testcerts/client.crt', 'testcerts/root.crt')
     s1 = TcpServer('lssl://localhost:199', self.protocolServer, self.scheduler, 'testcerts/server.key', 'testcerts/server.crt', 'testcerts/root.crt')
     r = RoutineContainer(self.scheduler, True)
     ret = bytearray()
     def mainA():
         m = TestDataEvent.createMatcher()
         stopped = False
         while True:
             yield (m,)
             if r.event.connection is c1:
                 ret.extend(b'B')
             else:
                 ret.extend(b'A')
             if not stopped:
                 for m in s1.shutdown():
                     yield m
                 stopped = True
     r.main = mainA
     r.start()
     s1.start()
     def waitAndStart(c):
         for m in r.waitWithTimeout(0.5):
             yield m
         c.start()
     r.subroutine(waitAndStart(c1))
     self.scheduler.main()
     self.assertEqual(ret, b'ABABABABABABABABABAB')
Exemple #2
0
 def testServerClientSsl(self):
     c1 = Client('ssl://localhost:199', self.protocolClient, self.scheduler, 'testcerts/client.key', 'testcerts/client.crt', 'testcerts/root.crt')
     s1 = TcpServer('lssl://localhost:199', self.protocolServer, self.scheduler, 'testcerts/server.key', 'testcerts/server.crt', 'testcerts/root.crt')
     r = RoutineContainer(self.scheduler, True)
     ret = bytearray()
     def mainA():
         m = TestDataEvent.createMatcher()
         stopped = False
         while True:
             yield (m,)
             if r.event.connection is c1:
                 ret.extend(b'B')
             else:
                 ret.extend(b'A')
             if not stopped:
                 for m in s1.shutdown():
                     yield m
                 stopped = True
     r.main = mainA
     r.start()
     s1.start()
     def waitAndStart(c):
         for m in r.waitWithTimeout(0.5):
             yield m
         c.start()
     r.subroutine(waitAndStart(c1))
     self.scheduler.main()
     self.assertEqual(ret, b'ABABABABABABABABABAB')
Exemple #3
0
    def testMultipleClients(self):
        c1 = Client('tcp://localhost:199', self.protocolClient, self.scheduler)
        c2 = Client('tcp://localhost:199', self.protocolClient, self.scheduler)
        s1 = TcpServer('ltcp://localhost:199', self.protocolServer,
                       self.scheduler)
        r = RoutineContainer(self.scheduler, True)
        counter = {c1: 0, c2: 0}
        ret = bytearray()

        def mainA():
            m = TestDataEvent.createMatcher()
            c1c = False
            c2c = False
            shutdown = False
            while True:
                yield (m, )
                counter[r.event.connection] = counter.get(
                    r.event.connection, 0) + 1
                if r.event.connection is c1:
                    ret.extend(b'A')
                    c1c = True
                elif r.event.connection is c2:
                    ret.extend(b'B')
                    c2c = True
                if c1c and c2c and not shutdown:
                    for m in s1.shutdown():
                        yield m
                    shutdown = True

        r.main = mainA
        r.start()
        s1.start()

        def waitAndStart(c):
            for m in r.waitWithTimeout(0.5):
                yield m
            c.start()

        r.subroutine(waitAndStart(c1))
        r.subroutine(waitAndStart(c2))
        self.scheduler.main()
        print(ret)
        self.assertEqual(counter[c1], 10)
        self.assertEqual(counter[c2], 10)
Exemple #4
0
 def testMultipleClients(self):
     c1 = Client('tcp://localhost:199', self.protocolClient, self.scheduler)
     c2 = Client('tcp://localhost:199', self.protocolClient, self.scheduler)
     s1 = TcpServer('ltcp://localhost:199', self.protocolServer, self.scheduler)
     r = RoutineContainer(self.scheduler, True)
     counter = {c1:0, c2:0}
     ret = bytearray()
     def mainA():
         m = TestDataEvent.createMatcher()
         c1c = False
         c2c = False
         shutdown = False
         while True:
             yield (m,)
             counter[r.event.connection] = counter.get(r.event.connection, 0) + 1
             if r.event.connection is c1:
                 ret.extend(b'A')
                 c1c = True
             elif r.event.connection is c2:
                 ret.extend(b'B')
                 c2c = True
             if c1c and c2c and not shutdown:
                 for m in s1.shutdown():
                     yield m
                 shutdown = True
     r.main = mainA
     r.start()
     s1.start()
     def waitAndStart(c):
         for m in r.waitWithTimeout(0.5):
             yield m
         c.start()
     r.subroutine(waitAndStart(c1))
     r.subroutine(waitAndStart(c2))
     self.scheduler.main()
     print(ret)
     self.assertEqual(counter[c1], 10)
     self.assertEqual(counter[c2], 10)