a9088854e48a6309e04bdf222c69d2e9545f7b54
[jelmer/dulwich-libgit2.git] / dulwich / tests / compat / test_server.py
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
20 """Compatibilty tests between Dulwich and the cgit server.
21
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 %".
25 """
26
27 import threading
28
29 from dulwich import server
30 from server_utils import (
31     ServerTests,
32     ShutdownServerMixIn,
33     )
34 from utils import (
35     CompatTestCase,
36     SkipTest,
37     )
38
39
40 if getattr(server.TCPGitServer, 'shutdown', None):
41     TCPGitServer = server.TCPGitServer
42 else:
43     class TCPGitServer(ShutdownServerMixIn, server.TCPGitServer):
44         """Subclass of TCPGitServer that can be shut down."""
45
46         def __init__(self, *args, **kwargs):
47             # BaseServer is old-style so we have to call both __init__s
48             ShutdownServerMixIn.__init__(self)
49             server.TCPGitServer.__init__(self, *args, **kwargs)
50
51         serve = ShutdownServerMixIn.serve_forever
52
53
54 class GitServerTestCase(ServerTests, CompatTestCase):
55     """Tests for client/server compatibility."""
56
57     protocol = 'git'
58
59     def setUp(self):
60         ServerTests.setUp(self)
61         CompatTestCase.setUp(self)
62
63     def tearDown(self):
64         ServerTests.tearDown(self)
65         CompatTestCase.tearDown(self)
66
67     def _start_server(self, repo):
68         dul_server = TCPGitServer(server.GitBackend(repo), 'localhost', 0)
69         threading.Thread(target=dul_server.serve).start()
70         self._server = dul_server
71         _, port = self._server.socket.getsockname()
72         return port
73
74     def test_push_to_dulwich(self):
75         raise SkipTest('Skipping push test due to known deadlock bug.')