~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_serve.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-10-13 10:50:33 UTC
  • mfrom: (2077 +trunk)
  • mto: (2145.1.1 keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: v.ladeuil+lp@free.fr-20061013105033-7e091ff8dcc0ed0c
Merge bzr.dev. Including http modifications by "smart" related code

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
from bzrlib.transport import get_transport, smart
31
31
 
32
32
 
33
 
class DoesNotCloseStdOutClient(smart.SmartStreamClient):
34
 
    """A client that doesn't close stdout upon disconnect().
35
 
    
36
 
    We wish to let stdout remain open so that we can see if the server writes
37
 
    anything to stdout during its shutdown.
38
 
    """
39
 
 
40
 
    def disconnect(self):
41
 
        if self._connected:
42
 
            self._connected = False
43
 
            # The client's out is the server's in.
44
 
            self._out.close()
45
 
 
46
 
 
47
33
class TestBzrServe(TestCaseWithTransport):
48
34
 
49
 
    def assertInetServerShutsdownCleanly(self, client, process):
 
35
    def assertInetServerShutsdownCleanly(self, process):
50
36
        """Shutdown the server process looking for errors."""
51
 
        # Disconnect the client forcefully JUST IN CASE because of __del__'s use
52
 
        # in the smart module.
53
 
        client.disconnect()
54
 
 
55
 
        # Shutdown the server: the client should have disconnected cleanly and
56
 
        # closed stdin, so the server process should shut itself down.
57
 
        self.assertTrue(process.stdin.closed)
 
37
        # Shutdown the server: the server should shut down when it cannot read
 
38
        # from stdin anymore.
 
39
        process.stdin.close()
58
40
        # Hide stdin from the subprocess module, so it won't fail to close it.
59
41
        process.stdin = None
60
42
        result = self.finish_bzr_subprocess(process, retcode=0)
82
64
        # Connect to the server
83
65
        # We use this url because while this is no valid URL to connect to this
84
66
        # server instance, the transport needs a URL.
85
 
        client = DoesNotCloseStdOutClient(
86
 
            lambda: (process.stdout, process.stdin))
87
 
        transport = smart.SmartTransport('bzr://localhost/', client=client)
88
 
        return process, client, transport
 
67
        medium = smart.SmartSimplePipesClientMedium(
 
68
            process.stdout, process.stdin)
 
69
        transport = smart.SmartTransport('bzr://localhost/', medium=medium)
 
70
        return process, transport
89
71
 
90
72
    def start_server_port(self, extra_options=()):
91
73
        """Start a bzr server subprocess.
106
88
 
107
89
    def test_bzr_serve_inet_readonly(self):
108
90
        """bzr server should provide a read only filesystem by default."""
109
 
        process, client, transport = self.start_server_inet()
 
91
        process, transport = self.start_server_inet()
110
92
        self.assertRaises(errors.TransportNotPossible, transport.mkdir, 'adir')
111
 
        # finish with the transport
112
 
        del transport
113
 
        self.assertInetServerShutsdownCleanly(client, process)
 
93
        self.assertInetServerShutsdownCleanly(process)
114
94
 
115
95
    def test_bzr_serve_inet_readwrite(self):
116
96
        # Make a branch
117
97
        self.make_branch('.')
118
98
 
119
 
        process, client, transport = self.start_server_inet(['--allow-writes'])
 
99
        process, transport = self.start_server_inet(['--allow-writes'])
120
100
 
121
101
        # We get a working branch
122
102
        branch = BzrDir.open_from_transport(transport).open_branch()
123
103
        branch.repository.get_revision_graph()
124
104
        self.assertEqual(None, branch.last_revision())
125
 
 
126
 
        # finish with the transport
127
 
        del transport
128
 
 
129
 
        self.assertInetServerShutsdownCleanly(client, process)
 
105
        self.assertInetServerShutsdownCleanly(process)
130
106
 
131
107
    def test_bzr_serve_port_readonly(self):
132
108
        """bzr server should provide a read only filesystem by default."""