From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id DAF47138334 for ; Sat, 19 Oct 2019 23:15:58 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0F2CFE0899; Sat, 19 Oct 2019 23:15:58 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id DAE5EE0899 for ; Sat, 19 Oct 2019 23:15:57 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 3D36034C068 for ; Sat, 19 Oct 2019 23:15:56 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 143EC773 for ; Sat, 19 Oct 2019 23:15:54 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1571526810.491b3ff4d35194765c8ee93c6a438097551fd07e.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/tests/ebuild/ X-VCS-Repository: proj/portage X-VCS-Files: lib/portage/tests/ebuild/test_fetch.py X-VCS-Directories: lib/portage/tests/ebuild/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 491b3ff4d35194765c8ee93c6a438097551fd07e X-VCS-Branch: master Date: Sat, 19 Oct 2019 23:15:54 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: b705ed74-f689-4e3e-9d07-be52610eb259 X-Archives-Hash: 04478d9626e72cc86c25af8354075e84 commit: 491b3ff4d35194765c8ee93c6a438097551fd07e Author: Zac Medico gentoo org> AuthorDate: Sat Oct 19 23:12:46 2019 +0000 Commit: Zac Medico gentoo org> CommitDate: Sat Oct 19 23:13:30 2019 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=491b3ff4 testEbuildFetch: demonstrate fetch behavior with stale file and no digests Signed-off-by: Zac Medico gentoo.org> lib/portage/tests/ebuild/test_fetch.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/portage/tests/ebuild/test_fetch.py b/lib/portage/tests/ebuild/test_fetch.py index da63d9dea..f50fea0dd 100644 --- a/lib/portage/tests/ebuild/test_fetch.py +++ b/lib/portage/tests/ebuild/test_fetch.py @@ -20,7 +20,7 @@ from portage.util._async.SchedulerInterface import SchedulerInterface from portage.util._eventloop.global_event_loop import global_event_loop from portage.package.ebuild.config import config from portage.package.ebuild.digestgen import digestgen -from portage.package.ebuild.fetch import (_download_suffix, FlatLayout, +from portage.package.ebuild.fetch import (_download_suffix, fetch, FlatLayout, FilenameHashLayout, MirrorLayoutConfig) from _emerge.EbuildFetcher import EbuildFetcher from _emerge.Package import Package @@ -51,6 +51,12 @@ class EbuildFetchTestCase(TestCase): } loop = SchedulerInterface(global_event_loop()) + + def run_async(func, *args, **kwargs): + with ForkExecutor(loop=loop) as executor: + return loop.run_until_complete(loop.run_in_executor(executor, + functools.partial(func, *args, **kwargs))) + scheme = 'http' host = '127.0.0.1' content = {} @@ -99,6 +105,29 @@ class EbuildFetchTestCase(TestCase): portdb = root_config.trees["porttree"].dbapi settings = config(clone=playground.settings) + # Demonstrate that fetch preserves a stale file in DISTDIR when no digests are given. + foo_uri = {'foo': ('{scheme}://{host}:{port}/distfiles/foo'.format(scheme=scheme, host=host, port=server.server_port),)} + foo_path = os.path.join(settings['DISTDIR'], 'foo') + foo_stale_content = b'stale content\n' + with open(foo_path, 'wb') as f: + f.write(b'stale content\n') + + self.assertTrue(bool(run_async(fetch, foo_uri, settings, try_mirrors=False))) + + with open(foo_path, 'rb') as f: + self.assertEqual(f.read(), foo_stale_content) + with open(foo_path, 'rb') as f: + self.assertNotEqual(f.read(), distfiles['foo']) + + # Remove the stale file in order to forcefully update it. + os.unlink(foo_path) + + self.assertTrue(bool(run_async(fetch, foo_uri, settings, try_mirrors=False))) + + with open(foo_path, 'rb') as f: + self.assertEqual(f.read(), distfiles['foo']) + + # Test emirrordist invocation. emirrordist_cmd = (portage._python_interpreter, '-b', '-Wd', os.path.join(self.bindir, 'emirrordist'), '--distfiles', settings['DISTDIR'],