Commits

Anonymous committed e2fed40

Set server listen timeout - fixed a test

Comments (0)

Files changed (3)

+syntax: glob
+
+*~
+*.py[co]
+*.py[co]-*
+build/*
+dist/*

python/protorpc/webapp_test_util.py

         knows to shut itself down.
     """
     self.server = server
+    # This timeout is for the socket when a connection is made.
     self.server.socket.settimeout(None)
+    # This timeout is for when waiting for a connection.  The allows
+    # server.handle_request() to listen for a short time, then timeout,
+    # allowing the server to check for shutdown.
+    self.server.timeout = 0.05
     self.__serving = True
 
     super(ServerThread, self).__init__(*args, **kwargs)

python/protorpc/wsgi/service_test.py

 
   def setUp(self):
     self.protocols = None
+    remote.Protocols.set_default(remote.Protocols.new_default())
     super(ServiceMappingTest, self).setUp()
 
   def CreateServices(self):
   def testAlternateProtocols(self):
     self.protocols = remote.Protocols()
     self.protocols.add_protocol(protojson, 'altproto', 'image/png')
+
+    global_protocols = remote.Protocols()
+    global_protocols.add_protocol(protojson, 'server-side-name', 'image/png')
+    remote.Protocols.set_default(global_protocols)
     self.ResetServer()
 
     self.connection = transport.HttpTransport(
     self.stub.optional_message(string_value='alternate-protocol')
 
   def testAlwaysUseDefaults(self):
-    original_protocols = remote.Protocols.get_default()
-    try:
-      new_protocols = remote.Protocols()
-      new_protocols.add_protocol(protojson, 'altproto', 'image/png')
+    new_protocols = remote.Protocols()
+    new_protocols.add_protocol(protojson, 'altproto', 'image/png')
 
-      self.connection = transport.HttpTransport(
-        self.service_url, protocol=new_protocols.lookup_by_name('altproto'))
-      self.stub = webapp_test_util.TestService.Stub(self.connection)
+    self.connection = transport.HttpTransport(
+      self.service_url, protocol=new_protocols.lookup_by_name('altproto'))
+    self.stub = webapp_test_util.TestService.Stub(self.connection)
 
-      self.assertRaisesWithRegexpMatch(
-        remote.ServerError,
-        'HTTP Error 415: Unsupported Media Type',
-        self.stub.optional_message, string_value='alternate-protocol')
+    self.assertRaisesWithRegexpMatch(
+      remote.ServerError,
+      'HTTP Error 415: Unsupported Media Type',
+      self.stub.optional_message, string_value='alternate-protocol')
 
-      remote.Protocols.set_default(new_protocols)
+    remote.Protocols.set_default(new_protocols)
 
-      self.stub.optional_message(string_value='alternate-protocol')
-    finally:
-      remote.Protocols.set_default(original_protocols)
+    self.stub.optional_message(string_value='alternate-protocol')
 
 
 class ProtoServiceMappingsTest(ServiceMappingTest):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.