2
0

test_server.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 Ctrl-C'ed.
  22. On *nix, you can kill the tests with Ctrl-Z, "kill %".
  23. """
  24. import threading
  25. from dulwich.server import (
  26. DictBackend,
  27. TCPGitServer,
  28. ReceivePackHandler,
  29. )
  30. from server_utils import (
  31. ServerTests,
  32. ShutdownServerMixIn,
  33. NoSideBand64kReceivePackHandler,
  34. )
  35. from utils import (
  36. CompatTestCase,
  37. )
  38. if not getattr(TCPGitServer, 'shutdown', None):
  39. _TCPGitServer = TCPGitServer
  40. class TCPGitServer(ShutdownServerMixIn, TCPGitServer):
  41. """Subclass of TCPGitServer that can be shut down."""
  42. def __init__(self, *args, **kwargs):
  43. # BaseServer is old-style so we have to call both __init__s
  44. ShutdownServerMixIn.__init__(self)
  45. _TCPGitServer.__init__(self, *args, **kwargs)
  46. serve = ShutdownServerMixIn.serve_forever
  47. class GitServerTestCase(ServerTests, CompatTestCase):
  48. """Tests for client/server compatibility.
  49. This server test case does not use side-band-64k in git-receive-pack.
  50. """
  51. protocol = 'git'
  52. def setUp(self):
  53. ServerTests.setUp(self)
  54. CompatTestCase.setUp(self)
  55. def tearDown(self):
  56. ServerTests.tearDown(self)
  57. CompatTestCase.tearDown(self)
  58. def _handlers(self):
  59. return {'git-receive-pack': NoSideBand64kReceivePackHandler}
  60. def _check_server(self, dul_server):
  61. receive_pack_handler_cls = dul_server.handlers['git-receive-pack']
  62. caps = receive_pack_handler_cls.capabilities()
  63. self.assertFalse('side-band-64k' in caps)
  64. def _start_server(self, repo):
  65. backend = DictBackend({'/': repo})
  66. dul_server = TCPGitServer(backend, 'localhost', 0,
  67. handlers=self._handlers())
  68. self._check_server(dul_server)
  69. threading.Thread(target=dul_server.serve).start()
  70. self._server = dul_server
  71. _, port = self._server.socket.getsockname()
  72. return port
  73. class GitServerSideBand64kTestCase(GitServerTestCase):
  74. """Tests for client/server compatibility with side-band-64k support."""
  75. # side-band-64k in git-receive-pack was introduced in git 1.7.0.2
  76. min_git_version = (1, 7, 0, 2)
  77. def _handlers(self):
  78. return None # default handlers include side-band-64k
  79. def _check_server(self, server):
  80. receive_pack_handler_cls = server.handlers['git-receive-pack']
  81. caps = receive_pack_handler_cls.capabilities()
  82. self.assertTrue('side-band-64k' in caps)