~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

(jr) New hook server_exception in bzrlib.smart.server to catch any exception
 caused while running bzr serve. (Jonathan Riddell,
 #274578) (Jonathan Riddell)

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
            'run_bzr_serve_then_func hook')
82
82
        # start a TCP server
83
83
        try:
84
 
            out, err = self.run_bzr(['serve'] + list(serve_args))
 
84
            out, err = self.run_bzr(['serve'] + list(serve_args), retcode=retcode)
85
85
        except KeyboardInterrupt, e:
86
86
            out, err = e.args
87
87
        return out, err
93
93
        super(TestBzrServe, self).setUp()
94
94
        self.disable_missing_extensions_warning()
95
95
 
 
96
    def test_server_exception_with_hook(self):
 
97
        """test exception hook works to catch exceptions from server"""
 
98
        def hook(exception):
 
99
            from bzrlib.trace import note
 
100
            note("catching exception")
 
101
            return True
 
102
        SmartTCPServer.hooks.install_named_hook(
 
103
            'server_exception', hook,
 
104
            'test_server_except_hook hook')
 
105
        args = []
 
106
        out, err = self.run_bzr_serve_then_func(args, retcode=0)
 
107
        self.assertEqual('listening on port: 4155\ncatching exception\n', err)
 
108
 
 
109
    def test_server_exception_no_hook(self):
 
110
        """test exception without hook returns error"""
 
111
        args = []
 
112
        out, err = self.run_bzr_serve_then_func(args, retcode=3)
 
113
 
96
114
    def assertInetServerShutsdownCleanly(self, process):
97
115
        """Shutdown the server process looking for errors."""
98
116
        # Shutdown the server: the server should shut down when it cannot read