test_server.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # test_server.py -- Compatibility tests for git server.
  2. # Copyright (C) 2010 Google, Inc.
  3. #
  4. # Dulwich is dual-licensed under the Apache License, Version 2.0 and the GNU
  5. # General Public License as public by the Free Software Foundation; version 2.0
  6. # or (at your option) any later version. You can redistribute it and/or
  7. # modify it under the terms of either of these two licenses.
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. #
  15. # You should have received a copy of the licenses; if not, see
  16. # <http://www.gnu.org/licenses/> for a copy of the GNU General Public License
  17. # and <http://www.apache.org/licenses/LICENSE-2.0> for a copy of the Apache
  18. # License, Version 2.0.
  19. #
  20. """Compatibility tests between Dulwich and the cgit server.
  21. Warning: these tests should be fairly stable, but when writing/debugging new
  22. tests, deadlocks may freeze the test process such that it cannot be
  23. Ctrl-C'ed. On POSIX systems, you can kill the tests with Ctrl-Z, "kill %".
  24. """
  25. import os
  26. import sys
  27. import threading
  28. from dulwich.server import DictBackend, TCPGitServer
  29. from .. import skipIf
  30. from .server_utils import NoSideBand64kReceivePackHandler, ServerTests
  31. from .utils import CompatTestCase, require_git_version
  32. @skipIf(sys.platform == "win32", "Broken on windows, with very long fail time.")
  33. class GitServerTestCase(ServerTests, CompatTestCase):
  34. """Tests for client/server compatibility.
  35. This server test case does not use side-band-64k in git-receive-pack.
  36. """
  37. protocol = "git"
  38. def _handlers(self):
  39. return {b"git-receive-pack": NoSideBand64kReceivePackHandler}
  40. def _check_server(self, dul_server):
  41. receive_pack_handler_cls = dul_server.handlers[b"git-receive-pack"]
  42. caps = receive_pack_handler_cls.capabilities()
  43. self.assertNotIn(b"side-band-64k", caps)
  44. def _start_server(self, repo):
  45. backend = DictBackend({b"/": repo})
  46. dul_server = TCPGitServer(backend, b"localhost", 0, handlers=self._handlers())
  47. self._check_server(dul_server)
  48. self.addCleanup(dul_server.shutdown)
  49. self.addCleanup(dul_server.server_close)
  50. threading.Thread(target=dul_server.serve).start()
  51. self._server = dul_server
  52. _, port = self._server.socket.getsockname()
  53. return port
  54. @skipIf(sys.platform == "win32", "Broken on windows, with very long fail time.")
  55. class GitServerSideBand64kTestCase(GitServerTestCase):
  56. """Tests for client/server compatibility with side-band-64k support."""
  57. # side-band-64k in git-receive-pack was introduced in git 1.7.0.2
  58. min_git_version = (1, 7, 0, 2)
  59. def setUp(self):
  60. super().setUp()
  61. # side-band-64k is broken in the windows client.
  62. # https://github.com/msysgit/git/issues/101
  63. # Fix has landed for the 1.9.3 release.
  64. if os.name == "nt":
  65. require_git_version((1, 9, 3))
  66. def _handlers(self):
  67. return None # default handlers include side-band-64k
  68. def _check_server(self, server):
  69. receive_pack_handler_cls = server.handlers[b"git-receive-pack"]
  70. caps = receive_pack_handler_cls.capabilities()
  71. self.assertIn(b"side-band-64k", caps)