コード例 #1
0
 def test_ignore_other_errors(self):
     inet4_server = self.mox.CreateMock(
         wsgi_server._SingleAddressWsgiServer)
     inet6_server = self.mox.CreateMock(
         wsgi_server._SingleAddressWsgiServer)
     self.mox.StubOutWithMock(wsgi_server, '_SingleAddressWsgiServer')
     self.mox.StubOutWithMock(socket, 'getaddrinfo')
     socket.getaddrinfo('localhost', 0, socket.AF_UNSPEC,
                        socket.SOCK_STREAM, 0,
                        socket.AI_PASSIVE).AndReturn([
                            (None, None, None, None, ('127.0.0.1', 0,
                                                      'baz')),
                            (None, None, None, None, ('::1', 0, 'baz'))
                        ])
     wsgi_server._SingleAddressWsgiServer(('127.0.0.1', 0),
                                          None).AndReturn(inet4_server)
     inet4_server.start()
     inet4_server.port = 123
     wsgi_server._SingleAddressWsgiServer(('::1', 123),
                                          None).AndReturn(inet6_server)
     inet6_server.start().AndRaise(
         wsgi_server.BindError('message',
                               (errno.ENOPROTOOPT, 'no protocol')))
     self.mox.ReplayAll()
     self.server.start()
     self.mox.VerifyAll()
     self.assertItemsEqual([inet4_server], self.server._servers)
コード例 #2
0
 def test_retry_limited(self):
   inet4_servers = [self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
                    for _ in range(wsgi_server._PORT_0_RETRIES)]
   inet6_servers = [self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
                    for _ in range(wsgi_server._PORT_0_RETRIES)]
   self.mox.StubOutWithMock(wsgi_server, '_SingleAddressWsgiServer')
   self.mox.StubOutWithMock(socket, 'getaddrinfo')
   socket.getaddrinfo('localhost', 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0,
                      socket.AI_PASSIVE).AndReturn(
                          [(None, None, None, None, ('127.0.0.1', 0, 'baz')),
                           (None, None, None, None, ('::1', 0, 'baz'))])
   for offset, (inet4_server, inet6_server) in enumerate(zip(
       inet4_servers, inet6_servers)):
     wsgi_server._SingleAddressWsgiServer(('127.0.0.1', 0), None).AndReturn(
         inet4_server)
     inet4_server.start()
     inet4_server.port = offset + 1
     wsgi_server._SingleAddressWsgiServer(('::1', offset + 1), None).AndReturn(
         inet6_server)
     inet6_server.start().AndRaise(
         wsgi_server.BindError('message', (errno.EADDRINUSE, 'in use')))
     inet4_server.quit()
   self.mox.ReplayAll()
   self.assertRaises(wsgi_server.BindError, self.server.start)
   self.mox.VerifyAll()
コード例 #3
0
 def test_retry_limited(self):
     inet4_servers = [
         self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
         for _ in range(wsgi_server._PORT_0_RETRIES)
     ]
     inet6_servers = [
         self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
         for _ in range(wsgi_server._PORT_0_RETRIES)
     ]
     self.mox.StubOutWithMock(wsgi_server, '_SingleAddressWsgiServer')
     self.mox.StubOutWithMock(socket, 'getaddrinfo')
     socket.getaddrinfo('localhost', 0, socket.AF_UNSPEC,
                        socket.SOCK_STREAM, 0,
                        socket.AI_PASSIVE).AndReturn([
                            (None, None, None, None, ('127.0.0.1', 0,
                                                      'baz')),
                            (None, None, None, None, ('::1', 0, 'baz'))
                        ])
     for offset, (inet4_server, inet6_server) in enumerate(
             zip(inet4_servers, inet6_servers)):
         wsgi_server._SingleAddressWsgiServer(('127.0.0.1', 0),
                                              None).AndReturn(inet4_server)
         inet4_server.start()
         inet4_server.port = offset + 1
         wsgi_server._SingleAddressWsgiServer(('::1', offset + 1),
                                              None).AndReturn(inet6_server)
         inet6_server.start().AndRaise(
             wsgi_server.BindError('message', (errno.EADDRINUSE, 'in use')))
         inet4_server.quit()
     self.mox.ReplayAll()
     self.assertRaises(wsgi_server.BindError, self.server.start)
     self.mox.VerifyAll()
コード例 #4
0
 def test_basic_behavior(self):
     inet4_server = self.mox.CreateMock(
         wsgi_server._SingleAddressWsgiServer)
     inet6_server = self.mox.CreateMock(
         wsgi_server._SingleAddressWsgiServer)
     self.mox.StubOutWithMock(wsgi_server, '_SingleAddressWsgiServer')
     self.mox.StubOutWithMock(socket, 'getaddrinfo')
     socket.getaddrinfo('localhost', 0, socket.AF_UNSPEC,
                        socket.SOCK_STREAM, 0,
                        socket.AI_PASSIVE).AndReturn([
                            (None, None, None, None, ('127.0.0.1', 0,
                                                      'baz')),
                            (None, None, None, None, ('::1', 0, 'baz'))
                        ])
     wsgi_server._SingleAddressWsgiServer(('127.0.0.1', 0),
                                          None).AndReturn(inet4_server)
     inet4_server.start()
     inet4_server.port = 123
     wsgi_server._SingleAddressWsgiServer(('::1', 123),
                                          None).AndReturn(inet6_server)
     inet6_server.start()
     self.mox.ReplayAll()
     self.server.start()
     self.mox.VerifyAll()
     self.assertItemsEqual([inet4_server, inet6_server],
                           self.server._servers)
コード例 #5
0
ファイル: wsgi_server_test.py プロジェクト: haolei/appscale
    def test_start_all_fail_to_bind(self):
        failing_server = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
        self.mox.StubOutWithMock(wsgi_server, "_SingleAddressWsgiServer")
        self.mox.StubOutWithMock(socket, "getaddrinfo")
        socket.getaddrinfo("localhost", 123, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE).AndReturn(
            [(None, None, None, None, ("foo", "bar", "baz"))]
        )
        wsgi_server._SingleAddressWsgiServer(("foo", "bar"), None).AndReturn(failing_server)
        failing_server.start().AndRaise(wsgi_server.BindError)

        self.mox.ReplayAll()
        self.assertRaises(wsgi_server.BindError, self.server.start)
        self.mox.VerifyAll()
コード例 #6
0
ファイル: wsgi_server_test.py プロジェクト: haolei/appscale
 def test_retry_eaddrinuse(self):
     inet4_server = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
     inet6_server = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
     inet4_server_retry = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
     inet6_server_retry = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
     self.mox.StubOutWithMock(wsgi_server, "_SingleAddressWsgiServer")
     self.mox.StubOutWithMock(socket, "getaddrinfo")
     socket.getaddrinfo("localhost", 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE).AndReturn(
         [(None, None, None, None, ("127.0.0.1", 0, "baz")), (None, None, None, None, ("::1", 0, "baz"))]
     )
     # First try
     wsgi_server._SingleAddressWsgiServer(("127.0.0.1", 0), None).AndReturn(inet4_server)
     inet4_server.start()
     inet4_server.port = 123
     wsgi_server._SingleAddressWsgiServer(("::1", 123), None).AndReturn(inet6_server)
     inet6_server.start().AndRaise(wsgi_server.BindError("message", (errno.EADDRINUSE, "in use")))
     inet4_server.quit()
     # Retry
     wsgi_server._SingleAddressWsgiServer(("127.0.0.1", 0), None).AndReturn(inet4_server_retry)
     inet4_server_retry.start()
     inet4_server_retry.port = 456
     wsgi_server._SingleAddressWsgiServer(("::1", 456), None).AndReturn(inet6_server_retry)
     inet6_server_retry.start()
     self.mox.ReplayAll()
     self.server.start()
     self.mox.VerifyAll()
     self.assertItemsEqual([inet4_server_retry, inet6_server_retry], self.server._servers)
コード例 #7
0
ファイル: wsgi_server_test.py プロジェクト: JWW81/stochss
  def test_start_all_fail_to_bind(self):
    failing_server = self.mox.CreateMock(
        wsgi_server._SingleAddressWsgiServer)
    self.mox.StubOutWithMock(wsgi_server, '_SingleAddressWsgiServer')
    self.mox.StubOutWithMock(socket, 'getaddrinfo')
    socket.getaddrinfo('localhost', 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0,
                       socket.AI_PASSIVE).AndReturn(
                           [(None, None, None, None, ('foo', 'bar', 'baz'))])
    wsgi_server._SingleAddressWsgiServer(('foo', 'bar'), None).AndReturn(
        failing_server)
    failing_server.start().AndRaise(wsgi_server.BindError)

    self.mox.ReplayAll()
    self.assertRaises(wsgi_server.BindError, self.server.start)
    self.mox.VerifyAll()
コード例 #8
0
  def test_start_all_fail_to_bind(self):
    failing_server = self.mox.CreateMock(
        wsgi_server._SingleAddressWsgiServer)
    self.mox.StubOutWithMock(wsgi_server, '_SingleAddressWsgiServer')
    self.mox.StubOutWithMock(socket, 'getaddrinfo')
    socket.getaddrinfo('localhost', 123, socket.AF_UNSPEC, socket.SOCK_STREAM,
                       0, socket.AI_PASSIVE).AndReturn(
                           [(None, None, None, None, ('foo', 'bar', 'baz'))])
    wsgi_server._SingleAddressWsgiServer(('foo', 'bar'), None).AndReturn(
        failing_server)
    failing_server.start().AndRaise(wsgi_server.BindError)

    self.mox.ReplayAll()
    self.assertRaises(wsgi_server.BindError, self.server.start)
    self.mox.VerifyAll()
コード例 #9
0
ファイル: wsgi_server_test.py プロジェクト: haolei/appscale
 def test_basic_behavior(self):
     inet4_server = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
     inet6_server = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
     self.mox.StubOutWithMock(wsgi_server, "_SingleAddressWsgiServer")
     self.mox.StubOutWithMock(socket, "getaddrinfo")
     socket.getaddrinfo("localhost", 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE).AndReturn(
         [(None, None, None, None, ("127.0.0.1", 0, "baz")), (None, None, None, None, ("::1", 0, "baz"))]
     )
     wsgi_server._SingleAddressWsgiServer(("127.0.0.1", 0), None).AndReturn(inet4_server)
     inet4_server.start()
     inet4_server.port = 123
     wsgi_server._SingleAddressWsgiServer(("::1", 123), None).AndReturn(inet6_server)
     inet6_server.start()
     self.mox.ReplayAll()
     self.server.start()
     self.mox.VerifyAll()
     self.assertItemsEqual([inet4_server, inet6_server], self.server._servers)
コード例 #10
0
ファイル: wsgi_server_test.py プロジェクト: haolei/appscale
 def test_ignore_other_errors(self):
     inet4_server = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
     inet6_server = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
     self.mox.StubOutWithMock(wsgi_server, "_SingleAddressWsgiServer")
     self.mox.StubOutWithMock(socket, "getaddrinfo")
     socket.getaddrinfo("localhost", 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE).AndReturn(
         [(None, None, None, None, ("127.0.0.1", 0, "baz")), (None, None, None, None, ("::1", 0, "baz"))]
     )
     wsgi_server._SingleAddressWsgiServer(("127.0.0.1", 0), None).AndReturn(inet4_server)
     inet4_server.start()
     inet4_server.port = 123
     wsgi_server._SingleAddressWsgiServer(("::1", 123), None).AndReturn(inet6_server)
     inet6_server.start().AndRaise(wsgi_server.BindError("message", (errno.ENOPROTOOPT, "no protocol")))
     self.mox.ReplayAll()
     self.server.start()
     self.mox.VerifyAll()
     self.assertItemsEqual([inet4_server], self.server._servers)
コード例 #11
0
  def test_remove_duplicates(self):
    foo_server = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
    foo2_server = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
    self.mox.StubOutWithMock(wsgi_server, '_SingleAddressWsgiServer')
    self.mox.StubOutWithMock(socket, 'getaddrinfo')
    socket.getaddrinfo('localhost', 123, socket.AF_UNSPEC, socket.SOCK_STREAM,
                       0, socket.AI_PASSIVE).AndReturn(
                           [(0, 0, 0, '', ('127.0.0.1', 123)),
                            (0, 0, 0, '', ('::1', 123, 0, 0)),
                            (0, 0, 0, '', ('127.0.0.1', 123))])
    wsgi_server._SingleAddressWsgiServer(('127.0.0.1', 123), None).AndReturn(
        foo_server)
    foo_server.start()
    wsgi_server._SingleAddressWsgiServer(('::1', 123), None).AndReturn(
        foo2_server)
    foo2_server.start()

    self.mox.ReplayAll()
    self.server.start()
    self.mox.VerifyAll()
コード例 #12
0
  def test_remove_duplicates(self):
    foo_server = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
    foo2_server = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
    self.mox.StubOutWithMock(wsgi_server, '_SingleAddressWsgiServer')
    self.mox.StubOutWithMock(socket, 'getaddrinfo')
    socket.getaddrinfo('localhost', 123, socket.AF_UNSPEC, socket.SOCK_STREAM,
                       0, socket.AI_PASSIVE).AndReturn(
                           [(0, 0, 0, '', ('127.0.0.1', 123)),
                            (0, 0, 0, '', ('::1', 123, 0, 0)),
                            (0, 0, 0, '', ('127.0.0.1', 123))])
    wsgi_server._SingleAddressWsgiServer(('127.0.0.1', 123), None).AndReturn(
        foo_server)
    foo_server.start()
    wsgi_server._SingleAddressWsgiServer(('::1', 123), None).AndReturn(
        foo2_server)
    foo2_server.start()

    self.mox.ReplayAll()
    self.server.start()
    self.mox.VerifyAll()
コード例 #13
0
    def test_start_some_fail_to_bind(self):
        failing_server = self.mox.CreateMock(
            wsgi_server._SingleAddressWsgiServer)
        starting_server = self.mox.CreateMock(
            wsgi_server._SingleAddressWsgiServer)
        another_starting_server = self.mox.CreateMock(
            wsgi_server._SingleAddressWsgiServer)
        self.mox.StubOutWithMock(wsgi_server, '_SingleAddressWsgiServer')
        self.mox.StubOutWithMock(socket, 'getaddrinfo')
        socket.getaddrinfo('localhost', 123, socket.AF_UNSPEC,
                           socket.SOCK_STREAM, 0,
                           socket.AI_PASSIVE).AndReturn([
                               (None, None, None, None, ('foo', 'bar', 'baz')),
                               (None, None, None, None, (1, 2, 3, 4, 5)),
                               (None, None, None, None, (3, 4))
                           ])
        wsgi_server._SingleAddressWsgiServer(('foo', 'bar'),
                                             None).AndReturn(failing_server)
        wsgi_server._SingleAddressWsgiServer((1, 2),
                                             None).AndReturn(starting_server)
        wsgi_server._SingleAddressWsgiServer(
            (3, 4), None).AndReturn(another_starting_server)
        starting_server.start()
        failing_server.start().AndRaise(wsgi_server.BindError)
        another_starting_server.start()

        self.mox.ReplayAll()
        self.server.start()
        self.mox.VerifyAll()
        self.assertItemsEqual([starting_server, another_starting_server],
                              self.server._servers)
コード例 #14
0
  def test_start_some_fail_to_bind(self):
    failing_server = self.mox.CreateMock(
        wsgi_server._SingleAddressWsgiServer)
    starting_server = self.mox.CreateMock(
        wsgi_server._SingleAddressWsgiServer)
    another_starting_server = self.mox.CreateMock(
        wsgi_server._SingleAddressWsgiServer)
    self.mox.StubOutWithMock(wsgi_server, '_SingleAddressWsgiServer')
    self.mox.StubOutWithMock(socket, 'getaddrinfo')
    socket.getaddrinfo('localhost', 123, socket.AF_UNSPEC, socket.SOCK_STREAM,
                       0, socket.AI_PASSIVE).AndReturn(
                           [(None, None, None, None, ('foo', 'bar', 'baz')),
                            (None, None, None, None, (1, 2, 3, 4, 5)),
                            (None, None, None, None, (3, 4))])
    wsgi_server._SingleAddressWsgiServer(('foo', 'bar'), None).AndReturn(
        failing_server)
    wsgi_server._SingleAddressWsgiServer((1, 2), None).AndReturn(
        starting_server)
    wsgi_server._SingleAddressWsgiServer((3, 4), None).AndReturn(
        another_starting_server)
    starting_server.start()
    failing_server.start().AndRaise(wsgi_server.BindError)
    another_starting_server.start()

    self.mox.ReplayAll()
    self.server.start()
    self.mox.VerifyAll()
    self.assertItemsEqual([starting_server, another_starting_server],
                          self.server._servers)
コード例 #15
0
 def test_ignore_other_errors(self):
   inet4_server = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
   inet6_server = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
   self.mox.StubOutWithMock(wsgi_server, '_SingleAddressWsgiServer')
   self.mox.StubOutWithMock(socket, 'getaddrinfo')
   socket.getaddrinfo('localhost', 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0,
                      socket.AI_PASSIVE).AndReturn(
                          [(None, None, None, None, ('127.0.0.1', 0, 'baz')),
                           (None, None, None, None, ('::1', 0, 'baz'))])
   wsgi_server._SingleAddressWsgiServer(('127.0.0.1', 0), None).AndReturn(
       inet4_server)
   inet4_server.start()
   inet4_server.port = 123
   wsgi_server._SingleAddressWsgiServer(('::1', 123), None).AndReturn(
       inet6_server)
   inet6_server.start().AndRaise(
       wsgi_server.BindError('message', (errno.ENOPROTOOPT, 'no protocol')))
   self.mox.ReplayAll()
   self.server.start()
   self.mox.VerifyAll()
   self.assertItemsEqual([inet4_server],
                         self.server._servers)
コード例 #16
0
 def test_retry_eaddrinuse(self):
     inet4_server = self.mox.CreateMock(
         wsgi_server._SingleAddressWsgiServer)
     inet6_server = self.mox.CreateMock(
         wsgi_server._SingleAddressWsgiServer)
     inet4_server_retry = self.mox.CreateMock(
         wsgi_server._SingleAddressWsgiServer)
     inet6_server_retry = self.mox.CreateMock(
         wsgi_server._SingleAddressWsgiServer)
     self.mox.StubOutWithMock(wsgi_server, '_SingleAddressWsgiServer')
     self.mox.StubOutWithMock(socket, 'getaddrinfo')
     socket.getaddrinfo('localhost', 0, socket.AF_UNSPEC,
                        socket.SOCK_STREAM, 0,
                        socket.AI_PASSIVE).AndReturn([
                            (None, None, None, None, ('127.0.0.1', 0,
                                                      'baz')),
                            (None, None, None, None, ('::1', 0, 'baz'))
                        ])
     # First try
     wsgi_server._SingleAddressWsgiServer(('127.0.0.1', 0),
                                          None).AndReturn(inet4_server)
     inet4_server.start()
     inet4_server.port = 123
     wsgi_server._SingleAddressWsgiServer(('::1', 123),
                                          None).AndReturn(inet6_server)
     inet6_server.start().AndRaise(
         wsgi_server.BindError('message', (errno.EADDRINUSE, 'in use')))
     inet4_server.quit()
     # Retry
     wsgi_server._SingleAddressWsgiServer(
         ('127.0.0.1', 0), None).AndReturn(inet4_server_retry)
     inet4_server_retry.start()
     inet4_server_retry.port = 456
     wsgi_server._SingleAddressWsgiServer(
         ('::1', 456), None).AndReturn(inet6_server_retry)
     inet6_server_retry.start()
     self.mox.ReplayAll()
     self.server.start()
     self.mox.VerifyAll()
     self.assertItemsEqual([inet4_server_retry, inet6_server_retry],
                           self.server._servers)
コード例 #17
0
 def test_retry_eaddrinuse(self):
   inet4_server = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
   inet6_server = self.mox.CreateMock(wsgi_server._SingleAddressWsgiServer)
   inet4_server_retry = self.mox.CreateMock(
       wsgi_server._SingleAddressWsgiServer)
   inet6_server_retry = self.mox.CreateMock(
       wsgi_server._SingleAddressWsgiServer)
   self.mox.StubOutWithMock(wsgi_server, '_SingleAddressWsgiServer')
   self.mox.StubOutWithMock(socket, 'getaddrinfo')
   socket.getaddrinfo('localhost', 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0,
                      socket.AI_PASSIVE).AndReturn(
                          [(None, None, None, None, ('127.0.0.1', 0, 'baz')),
                           (None, None, None, None, ('::1', 0, 'baz'))])
   # First try
   wsgi_server._SingleAddressWsgiServer(('127.0.0.1', 0), None).AndReturn(
       inet4_server)
   inet4_server.start()
   inet4_server.port = 123
   wsgi_server._SingleAddressWsgiServer(('::1', 123), None).AndReturn(
       inet6_server)
   inet6_server.start().AndRaise(
       wsgi_server.BindError('message', (errno.EADDRINUSE, 'in use')))
   inet4_server.quit()
   # Retry
   wsgi_server._SingleAddressWsgiServer(('127.0.0.1', 0), None).AndReturn(
       inet4_server_retry)
   inet4_server_retry.start()
   inet4_server_retry.port = 456
   wsgi_server._SingleAddressWsgiServer(('::1', 456), None).AndReturn(
       inet6_server_retry)
   inet6_server_retry.start()
   self.mox.ReplayAll()
   self.server.start()
   self.mox.VerifyAll()
   self.assertItemsEqual([inet4_server_retry, inet6_server_retry],
                         self.server._servers)
コード例 #18
0
 def setUp(self):
     self.mox = mox.Mox()
     self.server = wsgi_server._SingleAddressWsgiServer(('localhost', 0),
                                                        None)
コード例 #19
0
 def setUp(self):
   # Since WsgiHostCheck is middleware and doesn't listen for requests,
   # we wrap it behind a _SingleAddressWsgiServer to send HTTP requests to it
   self.server = wsgi_server._SingleAddressWsgiServer(('localhost', 0), None)
   self.server.start()
コード例 #20
0
 def setUp(self):
   self.mox = mox.Mox()
   self.server = wsgi_server._SingleAddressWsgiServer(('localhost', 0), None)
コード例 #21
0
 def setUp(self):
   super(_SingleAddressWsgiServerTest, self).setUp()
   self.server = wsgi_server._SingleAddressWsgiServer(('localhost', 0),
                                                      self.wsgi_application)
   self.server.start()
コード例 #22
0
 def setUp(self):
     super(_SingleAddressWsgiServerTest, self).setUp()
     self.server = wsgi_server._SingleAddressWsgiServer(
         ('localhost', 0), self.wsgi_application)
     self.server.start()