test_server.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # test_server.py -- Compatibility tests for git server.
  2. # Copyright (C) 2010 Google, Inc.
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; version 2
  7. # of the License or (at your option) any later version of
  8. # the License.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  18. # MA 02110-1301, USA.
  19. """Compatibility tests between Dulwich and the cgit server.
  20. Warning: these tests should be fairly stable, but when writing/debugging new
  21. tests, deadlocks may freeze the test process such that it cannot be
  22. Ctrl-C'ed. On POSIX systems, you can kill the tests with Ctrl-Z, "kill %".
  23. """
  24. import threading
  25. from dulwich.server import (
  26. DictBackend,
  27. TCPGitServer,
  28. )
  29. from dulwich.tests.compat.server_utils import (
  30. ServerTests,
  31. ShutdownServerMixIn,
  32. NoSideBand64kReceivePackHandler,
  33. )
  34. from dulwich.tests.compat.utils import (
  35. CompatTestCase,
  36. )
  37. if not getattr(TCPGitServer, 'shutdown', None):
  38. _TCPGitServer = TCPGitServer
  39. class TCPGitServer(ShutdownServerMixIn, TCPGitServer):
  40. """Subclass of TCPGitServer that can be shut down."""
  41. def __init__(self, *args, **kwargs):
  42. # BaseServer is old-style so we have to call both __init__s
  43. ShutdownServerMixIn.__init__(self)
  44. _TCPGitServer.__init__(self, *args, **kwargs)
  45. serve = ShutdownServerMixIn.serve_forever
  46. class GitServerTestCase(ServerTests, CompatTestCase):
  47. """Tests for client/server compatibility.
  48. This server test case does not use side-band-64k in git-receive-pack.
  49. """
  50. protocol = 'git'
  51. def _handlers(self):
  52. return {'git-receive-pack': NoSideBand64kReceivePackHandler}
  53. def _check_server(self, dul_server):
  54. receive_pack_handler_cls = dul_server.handlers['git-receive-pack']
  55. caps = receive_pack_handler_cls.capabilities()
  56. self.assertFalse('side-band-64k' in caps)
  57. def _start_server(self, repo):
  58. backend = DictBackend({'/': repo})
  59. dul_server = TCPGitServer(backend, 'localhost', 0,
  60. handlers=self._handlers())
  61. self._check_server(dul_server)
  62. self.addCleanup(dul_server.shutdown)
  63. threading.Thread(target=dul_server.serve).start()
  64. self._server = dul_server
  65. _, port = self._server.socket.getsockname()
  66. return port
  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 _handlers(self):
  72. return None # default handlers include side-band-64k
  73. def _check_server(self, server):
  74. receive_pack_handler_cls = server.handlers['git-receive-pack']
  75. caps = receive_pack_handler_cls.capabilities()
  76. self.assertTrue('side-band-64k' in caps)