test_server.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 threading
  26. import os
  27. import sys
  28. from dulwich.server import (
  29. DictBackend,
  30. TCPGitServer,
  31. )
  32. from dulwich.tests import skipIf
  33. from dulwich.tests.compat.server_utils import (
  34. ServerTests,
  35. NoSideBand64kReceivePackHandler,
  36. )
  37. from dulwich.tests.compat.utils import (
  38. CompatTestCase,
  39. require_git_version,
  40. )
  41. @skipIf(sys.platform == 'win32',
  42. 'Broken on windows, with very long fail time.')
  43. class GitServerTestCase(ServerTests, CompatTestCase):
  44. """Tests for client/server compatibility.
  45. This server test case does not use side-band-64k in git-receive-pack.
  46. """
  47. protocol = 'git'
  48. def _handlers(self):
  49. return {b'git-receive-pack': NoSideBand64kReceivePackHandler}
  50. def _check_server(self, dul_server):
  51. receive_pack_handler_cls = dul_server.handlers[b'git-receive-pack']
  52. caps = receive_pack_handler_cls.capabilities()
  53. self.assertFalse(b'side-band-64k' in caps)
  54. def _start_server(self, repo):
  55. backend = DictBackend({b'/': repo})
  56. dul_server = TCPGitServer(backend, b'localhost', 0,
  57. handlers=self._handlers())
  58. self._check_server(dul_server)
  59. self.addCleanup(dul_server.shutdown)
  60. self.addCleanup(dul_server.server_close)
  61. threading.Thread(target=dul_server.serve).start()
  62. self._server = dul_server
  63. _, port = self._server.socket.getsockname()
  64. return port
  65. @skipIf(sys.platform == 'win32',
  66. 'Broken on windows, with very long fail time.')
  67. class GitServerSideBand64kTestCase(GitServerTestCase):
  68. """Tests for client/server compatibility with side-band-64k support."""
  69. # side-band-64k in git-receive-pack was introduced in git 1.7.0.2
  70. min_git_version = (1, 7, 0, 2)
  71. def setUp(self):
  72. super(GitServerSideBand64kTestCase, self).setUp()
  73. # side-band-64k is broken in the widows client.
  74. # https://github.com/msysgit/git/issues/101
  75. # Fix has landed for the 1.9.3 release.
  76. if os.name == 'nt':
  77. require_git_version((1, 9, 3))
  78. def _handlers(self):
  79. return None # default handlers include side-band-64k
  80. def _check_server(self, server):
  81. receive_pack_handler_cls = server.handlers[b'git-receive-pack']
  82. caps = receive_pack_handler_cls.capabilities()
  83. self.assertTrue(b'side-band-64k' in caps)