1 # test_server.py -- Compatibility tests for git server.
2 # Copyright (C) 2010 Google, Inc.
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
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.
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,
20 """Compatibility tests between Dulwich and the cgit server.
22 Warning: these tests should be fairly stable, but when writing/debugging new
23 tests, deadlocks may freeze the test process such that it cannot be Ctrl-C'ed.
24 On *nix, you can kill the tests with Ctrl-Z, "kill %".
29 from dulwich.server import (
34 from server_utils import (
37 NoSideBand64kReceivePackHandler,
44 if not getattr(TCPGitServer, 'shutdown', None):
45 _TCPGitServer = TCPGitServer
47 class TCPGitServer(ShutdownServerMixIn, TCPGitServer):
48 """Subclass of TCPGitServer that can be shut down."""
50 def __init__(self, *args, **kwargs):
51 # BaseServer is old-style so we have to call both __init__s
52 ShutdownServerMixIn.__init__(self)
53 _TCPGitServer.__init__(self, *args, **kwargs)
55 serve = ShutdownServerMixIn.serve_forever
58 class GitServerTestCase(ServerTests, CompatTestCase):
59 """Tests for client/server compatibility.
61 This server test case does not use side-band-64k in git-receive-pack.
67 ServerTests.setUp(self)
68 CompatTestCase.setUp(self)
71 ServerTests.tearDown(self)
72 CompatTestCase.tearDown(self)
75 return {'git-receive-pack': NoSideBand64kReceivePackHandler}
77 def _check_server(self, dul_server):
78 receive_pack_handler_cls = dul_server.handlers['git-receive-pack']
79 caps = receive_pack_handler_cls.capabilities()
80 self.assertFalse('side-band-64k' in caps)
82 def _start_server(self, repo):
83 backend = DictBackend({'/': repo})
84 dul_server = TCPGitServer(backend, 'localhost', 0,
85 handlers=self._handlers())
86 self._check_server(dul_server)
87 threading.Thread(target=dul_server.serve).start()
88 self._server = dul_server
89 _, port = self._server.socket.getsockname()
93 class GitServerSideBand64kTestCase(GitServerTestCase):
94 """Tests for client/server compatibility with side-band-64k support."""
96 # side-band-64k in git-receive-pack was introduced in git 1.7.0.2
97 min_git_version = (1, 7, 0, 2)
100 return None # default handlers include side-band-64k
102 def _check_server(self, server):
103 receive_pack_handler_cls = server.handlers['git-receive-pack']
104 caps = receive_pack_handler_cls.capabilities()
105 self.assertTrue('side-band-64k' in caps)