Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_socketserver.SocketServerTest Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def pickaddr
def make_server
def run_server
def stream_examine
def dgram_examine
def test_TCPServer
def test_ThreadingTCPServer
def test_ForkingTCPServer
def test_UnixStreamServer
def test_ThreadingUnixStreamServer
def test_ForkingUnixStreamServer
def test_UDPServer
def test_ThreadingUDPServer
def test_ForkingUDPServer
def test_shutdown

Public Attributes

 port_seed
 test_files

Detailed Description

Test all socket servers.

Definition at line 65 of file test_socketserver.py.


Member Function Documentation

def test.test_socketserver.SocketServerTest.dgram_examine (   self,
  proto,
  addr 
)

Definition at line 168 of file test_socketserver.py.

00168 
00169     def dgram_examine(self, proto, addr):
00170         s = socket.socket(proto, socket.SOCK_DGRAM)
00171         s.sendto(TEST_STR, addr)
00172         buf = data = receive(s, 100)
00173         while data and b'\n' not in buf:
00174             data = receive(s, 100)
00175             buf += data
00176         self.assertEqual(buf, TEST_STR)
00177         s.close()

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_socketserver.SocketServerTest.make_server (   self,
  addr,
  svrcls,
  hdlrbase 
)

Definition at line 109 of file test_socketserver.py.

00109 
00110     def make_server(self, addr, svrcls, hdlrbase):
00111         class MyServer(svrcls):
00112             def handle_error(self, request, client_address):
00113                 self.close_request(request)
00114                 self.server_close()
00115                 raise
00116 
00117         class MyHandler(hdlrbase):
00118             def handle(self):
00119                 line = self.rfile.readline()
00120                 self.wfile.write(line)
00121 
00122         if verbose: print("creating server")
00123         server = MyServer(addr, MyHandler)
00124         self.assertEqual(server.server_address, server.socket.getsockname())
00125         return server

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 84 of file test_socketserver.py.

00084 
00085     def pickaddr(self, proto):
00086         if proto == socket.AF_INET:
00087             return (HOST, 0)
00088         else:
00089             # XXX: We need a way to tell AF_UNIX to pick its own name
00090             # like AF_INET provides port==0.
00091             dir = None
00092             if os.name == 'os2':
00093                 dir = '\socket'
00094             fn = tempfile.mktemp(prefix='unix_socket.', dir=dir)
00095             if os.name == 'os2':
00096                 # AF_UNIX socket names on OS/2 require a specific prefix
00097                 # which can't include a drive letter and must also use
00098                 # backslashes as directory separators
00099                 if fn[1] == ':':
00100                     fn = fn[2:]
00101                 if fn[0] in (os.sep, os.altsep):
00102                     fn = fn[1:]
00103                 if os.sep == '/':
00104                     fn = fn.replace(os.sep, os.altsep)
00105                 else:
00106                     fn = fn.replace(os.altsep, os.sep)
00107             self.test_files.append(fn)
00108             return fn

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_socketserver.SocketServerTest.run_server (   self,
  svrcls,
  hdlrbase,
  testfunc 
)

Definition at line 128 of file test_socketserver.py.

00128 
00129     def run_server(self, svrcls, hdlrbase, testfunc):
00130         server = self.make_server(self.pickaddr(svrcls.address_family),
00131                                   svrcls, hdlrbase)
00132         # We had the OS pick a port, so pull the real address out of
00133         # the server.
00134         addr = server.server_address
00135         if verbose:
00136             print("ADDR =", addr)
00137             print("CLASS =", svrcls)
00138 
00139         t = threading.Thread(
00140             name='%s serving' % svrcls,
00141             target=server.serve_forever,
00142             # Short poll interval to make the test finish quickly.
00143             # Time between requests is short enough that we won't wake
00144             # up spuriously too many times.
00145             kwargs={'poll_interval':0.01})
00146         t.daemon = True  # In case this function raises.
00147         t.start()
00148         if verbose: print("server running")
00149         for i in range(3):
00150             if verbose: print("test client", i)
00151             testfunc(svrcls.address_family, addr)
00152         if verbose: print("waiting for server")
00153         server.shutdown()
00154         t.join()
00155         server.server_close()
00156         if verbose: print("done")

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 68 of file test_socketserver.py.

00068 
00069     def setUp(self):
00070         signal_alarm(60)  # Kill deadlocks after 60 seconds.
00071         self.port_seed = 0
00072         self.test_files = []

Here is the call graph for this function:

Here is the caller graph for this function:

def test.test_socketserver.SocketServerTest.stream_examine (   self,
  proto,
  addr 
)

Definition at line 157 of file test_socketserver.py.

00157 
00158     def stream_examine(self, proto, addr):
00159         s = socket.socket(proto, socket.SOCK_STREAM)
00160         s.connect(addr)
00161         s.sendall(TEST_STR)
00162         buf = data = receive(s, 100)
00163         while data and b'\n' not in buf:
00164             data = receive(s, 100)
00165             buf += data
00166         self.assertEqual(buf, TEST_STR)
00167         s.close()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 73 of file test_socketserver.py.

00073 
00074     def tearDown(self):
00075         signal_alarm(0)  # Didn't deadlock.
00076         reap_children()
00077 
00078         for fn in self.test_files:
00079             try:
00080                 os.remove(fn)
00081             except os.error:
00082                 pass
00083         self.test_files[:] = []

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 189 of file test_socketserver.py.

Here is the call graph for this function:

Definition at line 224 of file test_socketserver.py.

Here is the call graph for this function:

Definition at line 207 of file test_socketserver.py.

00207 
00208             def test_ForkingUnixStreamServer(self):
00209                 with simple_subprocess(self):
00210                     self.run_server(ForkingUnixStreamServer,
00211                                     socketserver.StreamRequestHandler,
00212                                     self.stream_examine)

Here is the call graph for this function:

Definition at line 251 of file test_socketserver.py.

00251 
00252     def test_shutdown(self):
00253         # Issue #2302: shutdown() should always succeed in making an
00254         # other thread leave serve_forever().
00255         class MyServer(socketserver.TCPServer):
00256             pass
00257 
00258         class MyHandler(socketserver.StreamRequestHandler):
00259             pass
00260 
00261         threads = []
00262         for i in range(20):
00263             s = MyServer((HOST, 0), MyHandler)
00264             t = threading.Thread(
00265                 name='MyServer serving',
00266                 target=s.serve_forever,
00267                 kwargs={'poll_interval':0.01})
00268             t.daemon = True  # In case this function raises.
00269             threads.append((t, s))
00270         for t, s in threads:
00271             t.start()
00272             s.shutdown()
00273         for t, s in threads:
00274             t.join()
00275             s.server_close()
00276 

Definition at line 178 of file test_socketserver.py.

Here is the call graph for this function:

Definition at line 183 of file test_socketserver.py.

Here is the call graph for this function:

Definition at line 218 of file test_socketserver.py.

Here is the call graph for this function:

Definition at line 201 of file test_socketserver.py.

Here is the call graph for this function:

Definition at line 213 of file test_socketserver.py.

Here is the call graph for this function:

Definition at line 196 of file test_socketserver.py.

Here is the call graph for this function:


Member Data Documentation

Definition at line 70 of file test_socketserver.py.

Definition at line 71 of file test_socketserver.py.


The documentation for this class was generated from the following file: