diff --git a/py/test/rsession/hostmanage.py b/py/test/rsession/hostmanage.py index 300a3a8d7..2fb70da80 100644 --- a/py/test/rsession/hostmanage.py +++ b/py/test/rsession/hostmanage.py @@ -17,10 +17,14 @@ class HostInfo(object): def __init__(self, spec): parts = spec.split(':', 1) self.hostname = parts.pop(0) - if parts: + if parts and parts[0]: self.relpath = parts[0] else: - self.relpath = "pytestcache-" + self.hostname + self.relpath = "pytestcache-" + self.hostname + if spec.find(':') == -1 and self.hostname == 'localhost': + self.rsync_flag = False + else: + self.rsync_flag = True self.hostid = self._getuniqueid(self.hostname) def _getuniqueid(self, hostname): @@ -90,7 +94,7 @@ class HostRSync(py.execnet.RSync): def add_target_host(self, host, reporter=lambda x: None, destrelpath=None, finishedcallback=None): key = host.hostname, host.relpath - if key in self._synced: + if not host.rsync_flag or key in self._synced: if finishedcallback: finishedcallback() return False @@ -139,7 +143,7 @@ class HostManager(object): host, reporter, destrelpath, finishedcallback= lambda host=host, root=root: donecallback(host, root)) reporter(repevent.HostRSyncing(host, root, remotepath)) - rsync.send() + rsync.send_if_targets() def setup_hosts(self, reporter): self.init_rsync(reporter) diff --git a/py/test/rsession/testing/test_hostmanage.py b/py/test/rsession/testing/test_hostmanage.py index e7a553e3f..fe9421bc0 100644 --- a/py/test/rsession/testing/test_hostmanage.py +++ b/py/test/rsession/testing/test_hostmanage.py @@ -24,7 +24,7 @@ class TestHostInfo(DirSetup): return hostinfo def test_defaultpath(self): - x = HostInfo("localhost") + x = HostInfo("localhost:") assert x.hostname == "localhost" assert x.relpath == "pytestcache-" + x.hostname @@ -34,11 +34,11 @@ class TestHostInfo(DirSetup): assert x.hostname == "localhost" def test_hostid(self): - x = HostInfo("localhost") - y = HostInfo("localhost") + x = HostInfo("localhost:") + y = HostInfo("localhost:") assert x.hostid != y.hostid x = HostInfo("localhost:/tmp") - y = HostInfo("localhost") + y = HostInfo("localhost:") assert x.hostid != y.hostid def test_non_existing_hosts(self): @@ -192,6 +192,20 @@ class TestHostManager(DirSetup): assert self.dest.join("dir5","file").check() assert not self.dest.join("dir6").check() + def test_hostmanage_optimise_localhost(self): + def add_target(self, a, b, c): + assert 0, "Should not rsync here" + try: + config = py.test.config._reparse([self.source]) + old_add_target = HostRSync.add_target + HostRSync.add_target = add_target + hm = HostManager(config, hosts=[HostInfo('localhost') for i in + range(3)]) + events = [] + hm.init_rsync(reporter=events.append) + finally: + HostRSync.add_target = old_add_target + def test_getpath_relto_home(): x = getpath_relto_home("hello") assert x == py.path.local._gethomedir().join("hello")