patch: more sftp unit tests
John Arbash Meinel
john at arbash-meinel.com
Tue Dec 13 13:39:41 GMT 2005
Robey Pointer wrote:
>
> On 9 Dec 2005, at 6:57, John Arbash Meinel wrote:
>
...
> If you mean the event.wait(N) calls, those are actually timeouts -- if
> the event isn't triggered before that timeout, the test is failing in
> some fundamental way. (But it would take 5-30 seconds to fail, so we'd
> know cuz people would *really* be screaming.) :)
>
>
>> It could be the startup time for the ssh server. In which case we could
>> consider spawning the SSH server at some other time, and clean it up
>> independently of each test case. Then each test case would just tell the
>> SSH server what to consider as root, rather than spawning an entire
>> new one.
>
>
> I think this is the real problem. SSH negotiation is hard, and
> (currently) for each unit test, we do each side of the negotiation,
> sync up, do the test, then do a clean sync'd shutdown.
>
> For the paramiko sftp unit tests, I cheated a little bit by having the
> test *class* create the transport and shut it down when the whole test
> suite was done. If we had transport caching, we could actually just
> have the "stub sftp server" keep running during the whole sftp test
> suite, and bzr's sftp transport would keep reusing the cached SSH session.
>
Actually, we do have a little bit of caching. For example,
"get_transport" could actually return a previously created connection. I
don't prefer that, since we do want to test the
bzrlib.transport.get_transport code.
I already have a test that opens 2 connections to the SFTP server (which
would fail if we didn't have caching because the server only accepts 1
connection), but I also check to make sure the server doesn't log 2
connections.
I thought with unittest test classes, that the class was actually
instantiated multiple times, one for each of the test_* functions. The
easy way I see to do it is something like:
class TestSftpTransport(TestCaseW...)
_server = None
def get_server(self, basedir):
if TestSftpTransport._server is None:
#initialize the server
srv = TestSftpTransport._server
srv.set_base(basedir)
return srv
So the class essentially creates a Class-wide singleton. (You could use
a global, I just think a class member is cleaner).
The question is how to tell the server to clean itself up? How do we
know when all of the SftpTransport tests are done?
I can see cheating, and using introspection, so that we also have a
member with "_num_tests", that decrements as tests are run, and when it
reaches 0, the server is closed. But that would also require integrating
with the TestRunner code, since only it knows what tests it is actually
going to run.
So anyway, I can see easily how to do the "only 1 server, and only 1
connection" part of the puzzle. The harder part is how to tell it when
it is done.
>
>> I guess we need to profile to figure out where the time is spent.
>
>
> It would be helpful. I've been meaning to do the same against paramiko
> with this new lsprof thing when I get the time. (Unfortunately my
> vacation ended today.)
Sorry to hear that. You have been very productive.
John
=:->
>
> robey
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20051213/57e9fa2e/attachment.pgp
More information about the bazaar
mailing list