test_server.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # test_server.py -- Compatibilty 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. """Compatibilty 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. )
  29. from dulwich.tests import (
  30. TestSkipped,
  31. )
  32. from server_utils import (
  33. ServerTests,
  34. ShutdownServerMixIn,
  35. )
  36. from utils import (
  37. CompatTestCase,
  38. )
  39. if not getattr(TCPGitServer, 'shutdown', None):
  40. _TCPGitServer = TCPGitServer
  41. class TCPGitServer(ShutdownServerMixIn, TCPGitServer):
  42. """Subclass of TCPGitServer that can be shut down."""
  43. def __init__(self, *args, **kwargs):
  44. # BaseServer is old-style so we have to call both __init__s
  45. ShutdownServerMixIn.__init__(self)
  46. _TCPGitServer.__init__(self, *args, **kwargs)
  47. serve = ShutdownServerMixIn.serve_forever
  48. class GitServerTestCase(ServerTests, CompatTestCase):
  49. """Tests for client/server compatibility."""
  50. protocol = 'git'
  51. def setUp(self):
  52. ServerTests.setUp(self)
  53. CompatTestCase.setUp(self)
  54. def tearDown(self):
  55. ServerTests.tearDown(self)
  56. CompatTestCase.tearDown(self)
  57. def _start_server(self, repo):
  58. backend = DictBackend({'/': repo})
  59. dul_server = TCPGitServer(backend, 'localhost', 0)
  60. threading.Thread(target=dul_server.serve).start()
  61. self._server = dul_server
  62. _, port = self._server.socket.getsockname()
  63. return port