(self)
| 6621 | s.close() |
| 6622 | |
| 6623 | def testShare(self): |
| 6624 | # Transfer the listening server socket to another process |
| 6625 | # and service it from there. |
| 6626 | |
| 6627 | # Create process: |
| 6628 | q = multiprocessing.Queue() |
| 6629 | p = multiprocessing.Process(target=self.remoteProcessServer, args=(q,)) |
| 6630 | p.start() |
| 6631 | |
| 6632 | # Get the shared socket data |
| 6633 | data = self.serv.share(p.pid) |
| 6634 | |
| 6635 | # Pass the shared socket to the other process |
| 6636 | addr = self.serv.getsockname() |
| 6637 | self.serv.close() |
| 6638 | q.put(data) |
| 6639 | |
| 6640 | # The data that the server will send us |
| 6641 | message = b"slapmahfro" |
| 6642 | q.put(message) |
| 6643 | |
| 6644 | # Connect |
| 6645 | s = socket.create_connection(addr) |
| 6646 | # listen for the data |
| 6647 | m = [] |
| 6648 | while True: |
| 6649 | data = s.recv(100) |
| 6650 | if not data: |
| 6651 | break |
| 6652 | m.append(data) |
| 6653 | s.close() |
| 6654 | received = b"".join(m) |
| 6655 | self.assertEqual(received, message) |
| 6656 | p.join() |
| 6657 | |
| 6658 | def testShareLength(self): |
| 6659 | data = self.serv.share(os.getpid()) |
nothing calls this directly
no test coverage detected