public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/process/
@ 2019-04-14 19:45 Zac Medico
  0 siblings, 0 replies; 13+ messages in thread
From: Zac Medico @ 2019-04-14 19:45 UTC (permalink / raw
  To: gentoo-commits

commit:     ca08349fbec86a323037d5391717c10abc0421a8
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Apr 14 19:42:36 2019 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Apr 14 19:44:21 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=ca08349f

PipeReaderTestCase: use asyncio.create_subprocess_exec

Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/tests/process/test_poll.py | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/lib/portage/tests/process/test_poll.py b/lib/portage/tests/process/test_poll.py
index f700a5585..f505b5049 100644
--- a/lib/portage/tests/process/test_poll.py
+++ b/lib/portage/tests/process/test_poll.py
@@ -1,4 +1,4 @@
-# Copyright 1998-2018 Gentoo Foundation
+# Copyright 1998-2019 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import functools
@@ -6,13 +6,12 @@ import pty
 import shutil
 import socket
 import sys
-import subprocess
 import tempfile
 
 from portage import os
 from portage.tests import TestCase
-from portage.util._async.PopenProcess import PopenProcess
 from portage.util._eventloop.global_event_loop import global_event_loop
+from portage.util.futures import asyncio
 from _emerge.PipeReader import PipeReader
 
 class PipeReaderTestCase(TestCase):
@@ -68,17 +67,16 @@ class PipeReaderTestCase(TestCase):
 			input_files={"producer" : master_file},
 			_use_array=self._use_array,
 			scheduler=scheduler)
+		consumer.start()
 
-		producer = PopenProcess(
-			pipe_reader=consumer,
-			proc=subprocess.Popen(["bash", "-c", self._echo_cmd % test_string],
-				stdout=slave_fd),
-			scheduler=scheduler)
+		producer = scheduler.run_until_complete(asyncio.create_subprocess_exec(
+			"bash", "-c", self._echo_cmd % test_string,
+			stdout=slave_fd,
+			loop=scheduler))
 
-		producer.start()
 		os.close(slave_fd)
-		producer.wait()
-		consumer.wait()
+		scheduler.run_until_complete(producer.wait())
+		scheduler.run_until_complete(consumer.async_wait())
 
 		self.assertEqual(producer.returncode, os.EX_OK)
 		self.assertEqual(consumer.returncode, os.EX_OK)


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/process/
@ 2019-08-31  3:10 Zac Medico
  0 siblings, 0 replies; 13+ messages in thread
From: Zac Medico @ 2019-08-31  3:10 UTC (permalink / raw
  To: gentoo-commits

commit:     a6b9b218bc8599a5c07470aabc41a7af6a1f05d7
Author:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Fri Aug 30 18:24:48 2019 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Aug 31 03:10:14 2019 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=a6b9b218

Add test case for unshare_net code in portage.process

Code by Zac Medico, with some small tweaks.

Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/tests/process/test_unshare_net.py | 38 +++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/lib/portage/tests/process/test_unshare_net.py b/lib/portage/tests/process/test_unshare_net.py
new file mode 100644
index 000000000..745b79a47
--- /dev/null
+++ b/lib/portage/tests/process/test_unshare_net.py
@@ -0,0 +1,38 @@
+# Copyright 2019 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+import errno
+import os
+import platform
+
+import portage.process
+from portage.const import BASH_BINARY
+from portage.tests import TestCase
+
+CLONE_NEWNET = 0x40000000
+
+UNSHARE_NET_TEST_SCRIPT = """
+ping -c 1 -W 1 127.0.0.1 || exit 1
+ping -c 1 -W 1 10.0.0.1 || exit 1
+[[ -n ${IPV6} ]] || exit 0
+ping -c 1 -W 1 ::1 || exit 1
+ping -c 1 -W 1 fd::1 || exit 1
+"""
+
+class UnshareNetTestCase(TestCase):
+
+	def testUnshareNet(self):
+
+		if platform.system() != 'Linux':
+			self.skipTest('not Linux')
+		if portage.process.find_binary('ping') is None:
+			self.skipTest('ping not found')
+
+		errno_value = portage.process._unshare_validate(CLONE_NEWNET)
+		if errno_value != 0:
+			self.skipTest("Unable to unshare: %s" % (
+				errno.errorcode.get(errno_value, '?')))
+
+		env = os.environ.copy()
+		env['IPV6'] = '1' if portage.process._has_ipv6() else ''
+		self.assertEqual(portage.process.spawn([BASH_BINARY, '-c', UNSHARE_NET_TEST_SCRIPT], unshare_net=True, env=env), 0)


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/process/
@ 2021-01-18 12:20 Zac Medico
  0 siblings, 0 replies; 13+ messages in thread
From: Zac Medico @ 2021-01-18 12:20 UTC (permalink / raw
  To: gentoo-commits

commit:     b3b9acc13c432ccd1610a442d57257dfac763cc4
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 18 09:43:24 2021 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Jan 18 11:18:43 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=b3b9acc1

PipeLoggerTestCase: Use async and await syntax

Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/tests/process/test_PipeLogger.py | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)

diff --git a/lib/portage/tests/process/test_PipeLogger.py b/lib/portage/tests/process/test_PipeLogger.py
index acc3b8af9..48e198bc5 100644
--- a/lib/portage/tests/process/test_PipeLogger.py
+++ b/lib/portage/tests/process/test_PipeLogger.py
@@ -1,4 +1,4 @@
-# Copyright 2020 Gentoo Authors
+# Copyright 2020-2021 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 from portage import os
@@ -6,14 +6,12 @@ from portage.tests import TestCase
 from portage.util._async.PipeLogger import PipeLogger
 from portage.util.futures import asyncio
 from portage.util.futures._asyncio.streams import _reader, _writer
-from portage.util.futures.compat_coroutine import coroutine, coroutine_return
 from portage.util.futures.unix_events import _set_nonblocking
 
 
 class PipeLoggerTestCase(TestCase):
 
-	@coroutine
-	def _testPipeLoggerToPipe(self, test_string, loop=None):
+	async def _testPipeLoggerToPipe(self, test_string, loop):
 		"""
 		Test PipeLogger writing to a pipe connected to a PipeReader.
 		This verifies that PipeLogger does not deadlock when writing
@@ -24,7 +22,7 @@ class PipeLoggerTestCase(TestCase):
 		input_fd, writer_pipe = os.pipe()
 		_set_nonblocking(writer_pipe)
 		writer_pipe = os.fdopen(writer_pipe, 'wb', 0)
-		writer = asyncio.ensure_future(_writer(writer_pipe, test_string.encode('ascii'), loop=loop), loop=loop)
+		writer = asyncio.ensure_future(_writer(writer_pipe, test_string.encode('ascii')))
 		writer.add_done_callback(lambda writer: writer_pipe.close())
 
 		pr, pw = os.pipe()
@@ -37,22 +35,22 @@ class PipeLoggerTestCase(TestCase):
 
 		# Before starting the reader, wait here for a moment, in order
 		# to exercise PipeLogger's handling of EAGAIN during write.
-		yield asyncio.wait([writer], timeout=0.01, loop=loop)
+		await asyncio.wait([writer], timeout=0.01)
 
-		reader = _reader(pr, loop=loop)
-		yield writer
-		content = yield reader
-		yield consumer.async_wait()
+		reader = _reader(pr)
+		await writer
+		content = await reader
+		await consumer.async_wait()
 
 		self.assertEqual(consumer.returncode, os.EX_OK)
 
-		coroutine_return(content.decode('ascii', 'replace'))
+		return content.decode('ascii', 'replace')
 
 	def testPipeLogger(self):
 		loop = asyncio._wrap_loop()
 
 		for x in (1, 2, 5, 6, 7, 8, 2**5, 2**10, 2**12, 2**13, 2**14, 2**17, 2**17 + 1):
 			test_string = x * "a"
-			output = loop.run_until_complete(self._testPipeLoggerToPipe(test_string, loop=loop))
+			output = loop.run_until_complete(self._testPipeLoggerToPipe(test_string, loop))
 			self.assertEqual(test_string, output,
 				"x = %s, len(output) = %s" % (x, len(output)))


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/process/
@ 2021-01-18 12:20 Zac Medico
  0 siblings, 0 replies; 13+ messages in thread
From: Zac Medico @ 2021-01-18 12:20 UTC (permalink / raw
  To: gentoo-commits

commit:     b7469f2f9777e818e9c0f3fa46e90c3f7f1c904a
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Jan 18 11:49:28 2021 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Jan 18 11:50:10 2021 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=b7469f2f

AsyncFunctionTestCase: Use async and await syntax

Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/tests/process/test_AsyncFunction.py | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/lib/portage/tests/process/test_AsyncFunction.py b/lib/portage/tests/process/test_AsyncFunction.py
index b3f80b8ac..ce4b2a93b 100644
--- a/lib/portage/tests/process/test_AsyncFunction.py
+++ b/lib/portage/tests/process/test_AsyncFunction.py
@@ -1,4 +1,4 @@
-# Copyright 2020 Gentoo Authors
+# Copyright 2020-2021 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import sys
@@ -9,7 +9,6 @@ from portage.tests import TestCase
 from portage.util._async.AsyncFunction import AsyncFunction
 from portage.util.futures import asyncio
 from portage.util.futures._asyncio.streams import _writer
-from portage.util.futures.compat_coroutine import coroutine
 from portage.util.futures.unix_events import _set_nonblocking
 
 
@@ -20,8 +19,7 @@ class AsyncFunctionTestCase(TestCase):
 		os.close(pw)
 		return ''.join(sys.stdin)
 
-	@coroutine
-	def _testAsyncFunctionStdin(self, loop=None):
+	async def _testAsyncFunctionStdin(self, loop):
 		test_string = '1\n2\n3\n'
 		pr, pw = os.pipe()
 		fd_pipes = {0:pr}
@@ -30,8 +28,8 @@ class AsyncFunctionTestCase(TestCase):
 		os.close(pr)
 		_set_nonblocking(pw)
 		with open(pw, mode='wb', buffering=0) as pipe_write:
-			yield _writer(pipe_write, test_string.encode('utf_8'), loop=loop)
-		self.assertEqual((yield reader.async_wait()), os.EX_OK)
+			await _writer(pipe_write, test_string.encode('utf_8'))
+		self.assertEqual((await reader.async_wait()), os.EX_OK)
 		self.assertEqual(reader.result, test_string)
 
 	def testAsyncFunctionStdin(self):


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/process/
@ 2023-05-26 15:45 Sam James
  0 siblings, 0 replies; 13+ messages in thread
From: Sam James @ 2023-05-26 15:45 UTC (permalink / raw
  To: gentoo-commits

commit:     68eec067946997d64462a9d5fe188d1d830ea7a0
Author:     David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Mon May  1 08:50:15 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May 26 15:44:36 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=68eec067

tests: process: port testUnshareNet to pytest

...using skipif, instead of the old addPortageSkip mechanism.

Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/portage/tests/process/test_unshare_net.py | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/lib/portage/tests/process/test_unshare_net.py b/lib/portage/tests/process/test_unshare_net.py
index 6951faab6..4c70465f8 100644
--- a/lib/portage/tests/process/test_unshare_net.py
+++ b/lib/portage/tests/process/test_unshare_net.py
@@ -5,10 +5,13 @@ import errno
 import os
 import platform
 
+import pytest
+
 import portage.process
 from portage.const import BASH_BINARY
 from portage.tests import TestCase
 
+
 CLONE_NEWNET = 0x40000000
 
 UNSHARE_NET_TEST_SCRIPT = """
@@ -19,18 +22,19 @@ ping -c 1 -W 1 ::1 || exit 1
 ping -c 1 -W 1 fd::1 || exit 1
 """
 
+ABILITY_TO_UNSHARE = portage.process._unshare_validate(CLONE_NEWNET)
+
 
 class UnshareNetTestCase(TestCase):
+    @pytest.mark.skipif(platform.system() != "Linux", reason="not Linux")
+    @pytest.mark.skipif(
+        portage.process.find_binary("ping") is None, reason="ping not found"
+    )
+    @pytest.mark.skipif(
+        ABILITY_TO_UNSHARE != 0,
+        reason=f"Unable to unshare: {errno.errorcode.get(ABILITY_TO_UNSHARE, '?')}",
+    )
     def testUnshareNet(self):
-        if platform.system() != "Linux":
-            self.skipTest("not Linux")
-        if portage.process.find_binary("ping") is None:
-            self.skipTest("ping not found")
-
-        errno_value = portage.process._unshare_validate(CLONE_NEWNET)
-        if errno_value != 0:
-            self.skipTest(f"Unable to unshare: {errno.errorcode.get(errno_value, '?')}")
-
         env = os.environ.copy()
         env["IPV6"] = "1" if portage.process._has_ipv6() else ""
         self.assertEqual(


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/process/
@ 2023-05-26 15:45 Sam James
  0 siblings, 0 replies; 13+ messages in thread
From: Sam James @ 2023-05-26 15:45 UTC (permalink / raw
  To: gentoo-commits

commit:     3db3c517d7e7635f3507f1e7f921dcc9fdd33c9a
Author:     David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Mon May  1 09:18:48 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May 26 15:44:36 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=3db3c517

tests: process: order of skipif conditions changed

...to agree with the original, checking if:

1. system is not Linux
2. ping is missing
3. portage.process._unshare_validate returns error

Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/portage/tests/process/test_unshare_net.py | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/lib/portage/tests/process/test_unshare_net.py b/lib/portage/tests/process/test_unshare_net.py
index 4c70465f8..7910e1553 100644
--- a/lib/portage/tests/process/test_unshare_net.py
+++ b/lib/portage/tests/process/test_unshare_net.py
@@ -13,7 +13,6 @@ from portage.tests import TestCase
 
 
 CLONE_NEWNET = 0x40000000
-
 UNSHARE_NET_TEST_SCRIPT = """
 ping -c 1 -W 1 127.0.0.1 || exit 1
 ping -c 1 -W 1 10.0.0.1 || exit 1
@@ -21,19 +20,18 @@ ping -c 1 -W 1 10.0.0.1 || exit 1
 ping -c 1 -W 1 ::1 || exit 1
 ping -c 1 -W 1 fd::1 || exit 1
 """
-
 ABILITY_TO_UNSHARE = portage.process._unshare_validate(CLONE_NEWNET)
 
 
 class UnshareNetTestCase(TestCase):
-    @pytest.mark.skipif(platform.system() != "Linux", reason="not Linux")
-    @pytest.mark.skipif(
-        portage.process.find_binary("ping") is None, reason="ping not found"
-    )
     @pytest.mark.skipif(
         ABILITY_TO_UNSHARE != 0,
         reason=f"Unable to unshare: {errno.errorcode.get(ABILITY_TO_UNSHARE, '?')}",
     )
+    @pytest.mark.skipif(
+        portage.process.find_binary("ping") is None, reason="ping not found"
+    )
+    @pytest.mark.skipif(platform.system() != "Linux", reason="not Linux")
     def testUnshareNet(self):
         env = os.environ.copy()
         env["IPV6"] = "1" if portage.process._has_ipv6() else ""


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/process/
@ 2023-05-26 15:45 Sam James
  0 siblings, 0 replies; 13+ messages in thread
From: Sam James @ 2023-05-26 15:45 UTC (permalink / raw
  To: gentoo-commits

commit:     c36ef773b5b130ef8ee2219c5a371877be1bd41f
Author:     David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri May 19 12:45:13 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May 26 15:44:37 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=c36ef773

tests: process: port PipeReaderArrayTestCase to pytest

...since in some cases will fail. But it only happens
*sometimes*.

Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/portage/tests/process/test_poll.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/portage/tests/process/test_poll.py b/lib/portage/tests/process/test_poll.py
index 284dd168e..371dd1906 100644
--- a/lib/portage/tests/process/test_poll.py
+++ b/lib/portage/tests/process/test_poll.py
@@ -1,4 +1,4 @@
-# Copyright 1998-2020 Gentoo Authors
+# Copyright 1998-2020, 2023 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import functools
@@ -7,6 +7,8 @@ import shutil
 import socket
 import tempfile
 
+import pytest
+
 from portage import os
 from portage.tests import TestCase
 from portage.util._eventloop.global_event_loop import global_event_loop
@@ -109,6 +111,7 @@ class PipeReaderTestCase(TestCase):
                     cleanup()
 
 
+@pytest.mark.xfail()  # This fails sometimes, that's the reason of xfail here
 class PipeReaderArrayTestCase(PipeReaderTestCase):
     _use_array = True
     # sleep allows reliable triggering of the failure mode on fast computers


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/process/
@ 2023-05-26 15:45 Sam James
  0 siblings, 0 replies; 13+ messages in thread
From: Sam James @ 2023-05-26 15:45 UTC (permalink / raw
  To: gentoo-commits

commit:     f027096346460cb031c2cb6c66e494b79d1b4433
Author:     David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri May  5 15:38:54 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May 26 15:44:37 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=f0270963

tests: process: port to pytest test about spawning with large env var

Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/portage/tests/process/test_spawn_fail_e2big.py | 50 +++++++++-------------
 1 file changed, 20 insertions(+), 30 deletions(-)

diff --git a/lib/portage/tests/process/test_spawn_fail_e2big.py b/lib/portage/tests/process/test_spawn_fail_e2big.py
index d3be51670..7a0096630 100644
--- a/lib/portage/tests/process/test_spawn_fail_e2big.py
+++ b/lib/portage/tests/process/test_spawn_fail_e2big.py
@@ -2,39 +2,29 @@
 # Distributed under the terms of the GNU General Public License v2
 
 import platform
-import tempfile
 
-from pathlib import Path
+import pytest
 
 import portage.process
-
-from portage import shutil
 from portage.const import BASH_BINARY
-from portage.tests import TestCase
-
-
-class SpawnE2bigTestCase(TestCase):
-    def testSpawnE2big(self):
-        if platform.system() != "Linux":
-            self.skipTest("not Linux")
-
-        env = dict()
-        env["VERY_LARGE_ENV_VAR"] = "X" * 1024 * 256
 
-        tmpdir = tempfile.mkdtemp()
-        try:
-            logfile = tmpdir / Path("logfile")
-            echo_output = "Should never appear"
-            retval = portage.process.spawn(
-                [BASH_BINARY, "-c", "echo", echo_output], env=env, logfile=logfile
-            )
 
-            with open(logfile) as f:
-                logfile_content = f.read()
-                self.assertIn(
-                    "Largest environment variable: VERY_LARGE_ENV_VAR (262164 bytes)",
-                    logfile_content,
-                )
-            self.assertEqual(retval, 1)
-        finally:
-            shutil.rmtree(tmpdir)
+@pytest.mark.skipif(platform.system() != "Linux", reason="not Linux")
+def test_spawnE2big(capsys, tmp_path):
+    env = dict()
+    env["VERY_LARGE_ENV_VAR"] = "X" * 1024 * 256
+
+    logfile = tmp_path / "logfile"
+    echo_output = "Should never appear"
+    with capsys.disabled():
+        retval = portage.process.spawn(
+            [BASH_BINARY, "-c", "echo", echo_output], env=env, logfile=logfile
+        )
+
+    with open(logfile) as f:
+        logfile_content = f.read()
+        assert (
+            "Largest environment variable: VERY_LARGE_ENV_VAR (262164 bytes)"
+            in logfile_content
+        )
+    assert retval == 1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/process/
@ 2023-11-02 14:57 Zac Medico
  0 siblings, 0 replies; 13+ messages in thread
From: Zac Medico @ 2023-11-02 14:57 UTC (permalink / raw
  To: gentoo-commits

commit:     3b1234ba69a31709cd5aec1ae070901e3a28bb7c
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Wed Nov  1 05:07:32 2023 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Nov  2 14:56:37 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=3b1234ba

testAsyncFunctionStdin: multiprocessing spawn compat

For compatibility with the multiprocessing spawn start
method, we delay restoration of the stdin file descriptor,
since this file descriptor is sent to the subprocess
asynchronously.

Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
Bug: https://bugs.gentoo.org/916601

 lib/portage/tests/process/test_AsyncFunction.py | 30 +++++++++++++++++++------
 1 file changed, 23 insertions(+), 7 deletions(-)

diff --git a/lib/portage/tests/process/test_AsyncFunction.py b/lib/portage/tests/process/test_AsyncFunction.py
index d02a3395c1..1faf8f49f7 100644
--- a/lib/portage/tests/process/test_AsyncFunction.py
+++ b/lib/portage/tests/process/test_AsyncFunction.py
@@ -42,21 +42,37 @@ class AsyncFunctionTestCase(TestCase):
                 ),
             )
             reader.start()
+            # For compatibility with the multiprocessing spawn start
+            # method, we delay restoration of the stdin file descriptor,
+            # since this file descriptor is sent to the subprocess
+            # asynchronously.
+            _set_nonblocking(pw.fileno())
+            with open(pw.fileno(), mode="wb", buffering=0, closefd=False) as pipe_write:
+                await _writer(pipe_write, test_string.encode("utf_8"))
+            pw.close()
+            self.assertEqual((await reader.async_wait()), os.EX_OK)
+            self.assertEqual(reader.result, test_string)
         finally:
             os.dup2(stdin_backup, portage._get_stdin().fileno())
             os.close(stdin_backup)
 
-        _set_nonblocking(pw.fileno())
-        with open(pw.fileno(), mode="wb", buffering=0, closefd=False) as pipe_write:
-            await _writer(pipe_write, test_string.encode("utf_8"))
-        pw.close()
-        self.assertEqual((await reader.async_wait()), os.EX_OK)
-        self.assertEqual(reader.result, test_string)
-
     def testAsyncFunctionStdin(self):
         loop = asyncio._wrap_loop()
         loop.run_until_complete(self._testAsyncFunctionStdin(loop=loop))
 
+    def testAsyncFunctionStdinSpawn(self):
+        orig_start_method = multiprocessing.get_start_method()
+        if orig_start_method == "spawn":
+            self.skipTest("multiprocessing start method is already spawn")
+        # NOTE: An attempt was made to use multiprocessing.get_context("spawn")
+        # here, but it caused the python process to terminate unexpectedly
+        # during a send_handle call.
+        multiprocessing.set_start_method("spawn", force=True)
+        try:
+            self.testAsyncFunctionStdin()
+        finally:
+            multiprocessing.set_start_method(orig_start_method, force=True)
+
     @staticmethod
     def _test_getpid_fork(preexec_fn=None):
         """


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/process/
@ 2024-02-03 22:54 Zac Medico
  0 siblings, 0 replies; 13+ messages in thread
From: Zac Medico @ 2024-02-03 22:54 UTC (permalink / raw
  To: gentoo-commits

commit:     7ea1175091886baa677d11290d4b725a64e68710
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Feb  3 19:36:13 2024 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sat Feb  3 19:55:19 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=7ea11750

Revert "testAsyncFunctionStdin: multiprocessing spawn compat"

This reverts commit 3b1234ba69a31709cd5aec1ae070901e3a28bb7c,
since ForkProcess now solves the problem by creating temporary
duplicate file descriptors.

Bug: https://bugs.gentoo.org/916601
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/tests/process/test_AsyncFunction.py | 19 ++++++++-----------
 1 file changed, 8 insertions(+), 11 deletions(-)

diff --git a/lib/portage/tests/process/test_AsyncFunction.py b/lib/portage/tests/process/test_AsyncFunction.py
index a056f268bd..eb426a5c02 100644
--- a/lib/portage/tests/process/test_AsyncFunction.py
+++ b/lib/portage/tests/process/test_AsyncFunction.py
@@ -1,4 +1,4 @@
-# Copyright 2020-2023 Gentoo Authors
+# Copyright 2020-2024 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 import functools
@@ -44,20 +44,17 @@ class AsyncFunctionTestCase(TestCase):
                 ),
             )
             reader.start()
-            # For compatibility with the multiprocessing spawn start
-            # method, we delay restoration of the stdin file descriptor,
-            # since this file descriptor is sent to the subprocess
-            # asynchronously.
-            _set_nonblocking(pw.fileno())
-            with open(pw.fileno(), mode="wb", buffering=0, closefd=False) as pipe_write:
-                await _writer(pipe_write, test_string.encode("utf_8"))
-            pw.close()
-            self.assertEqual((await reader.async_wait()), os.EX_OK)
-            self.assertEqual(reader.result, test_string)
         finally:
             os.dup2(stdin_backup, portage._get_stdin().fileno())
             os.close(stdin_backup)
 
+        _set_nonblocking(pw.fileno())
+        with open(pw.fileno(), mode="wb", buffering=0, closefd=False) as pipe_write:
+            await _writer(pipe_write, test_string.encode("utf_8"))
+        pw.close()
+        self.assertEqual((await reader.async_wait()), os.EX_OK)
+        self.assertEqual(reader.result, test_string)
+
     def testAsyncFunctionStdin(self):
         loop = asyncio._wrap_loop()
         loop.run_until_complete(self._testAsyncFunctionStdin(loop=loop))


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/process/
@ 2024-02-09  7:08 Sam James
  0 siblings, 0 replies; 13+ messages in thread
From: Sam James @ 2024-02-09  7:08 UTC (permalink / raw
  To: gentoo-commits

commit:     a308d831ceb1f1e7d0733700117cc18c8eca09c8
Author:     Matoro Mahri <matoro_gentoo <AT> matoro <DOT> tk>
AuthorDate: Wed Jan 31 20:26:06 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Feb  9 07:08:22 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=a308d831

tests: process: calculate size of E2BIG environment variable dynamically

The size of the command line required to trigger E2BIG response from the
kernel is defined as MAX_ARG_STRLEN, which is equal to 32 * PAGE_SIZE.
Therefore the minimum size required to trigger the expected error
response must be calculated dynamically based on PAGE_SIZE.

Bug: https://bugs.gentoo.org/923368
Signed-off-by: Matoro Mahri <matoro_gentoo <AT> matoro.tk>
Closes: https://github.com/gentoo/portage/pull/1246
Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/portage/tests/process/test_spawn_fail_e2big.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/portage/tests/process/test_spawn_fail_e2big.py b/lib/portage/tests/process/test_spawn_fail_e2big.py
index 7a00966302..abb1113fea 100644
--- a/lib/portage/tests/process/test_spawn_fail_e2big.py
+++ b/lib/portage/tests/process/test_spawn_fail_e2big.py
@@ -2,6 +2,7 @@
 # Distributed under the terms of the GNU General Public License v2
 
 import platform
+import resource
 
 import pytest
 
@@ -12,7 +13,9 @@ from portage.const import BASH_BINARY
 @pytest.mark.skipif(platform.system() != "Linux", reason="not Linux")
 def test_spawnE2big(capsys, tmp_path):
     env = dict()
-    env["VERY_LARGE_ENV_VAR"] = "X" * 1024 * 256
+    # Kernel MAX_ARG_STRLEN is defined as 32 * PAGE_SIZE
+    max_arg_strlen_bytes = 32 * resource.getpagesize()
+    env["VERY_LARGE_ENV_VAR"] = "X" * max_arg_strlen_bytes
 
     logfile = tmp_path / "logfile"
     echo_output = "Should never appear"
@@ -24,7 +27,7 @@ def test_spawnE2big(capsys, tmp_path):
     with open(logfile) as f:
         logfile_content = f.read()
         assert (
-            "Largest environment variable: VERY_LARGE_ENV_VAR (262164 bytes)"
+            f"Largest environment variable: VERY_LARGE_ENV_VAR ({max_arg_strlen_bytes + 20} bytes)"
             in logfile_content
         )
     assert retval == 1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/process/
@ 2024-02-25  0:45 Zac Medico
  0 siblings, 0 replies; 13+ messages in thread
From: Zac Medico @ 2024-02-25  0:45 UTC (permalink / raw
  To: gentoo-commits

commit:     9e84ef57ba747766c9147c1ac1b247faa1f05956
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Feb 25 00:31:13 2024 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Sun Feb 25 00:42:46 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=9e84ef57

testSpawnReturnProcTerminate: Fix integer in spawn command argument

The invalid integer in the spawn command argument intermittently
triggered this error when SIGTERM did not arrive until after the
exec call:

----------------------------- Captured stderr call -----------------------------
Process ForkProcess-23:
Traceback (most recent call last):
  File "/home/runner/work/portage/portage/lib/portage/process.py", line 818, in _exec_wrapper
    _exec(
  File "/home/runner/work/portage/portage/lib/portage/process.py", line 1068, in _exec
    _exec2(
  File "/home/runner/work/portage/portage/lib/portage/process.py", line 1166, in _exec2
    os.execve(binary, myargs, env)
TypeError: expected str, bytes or os.PathLike object, not int

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.12.2/x64/lib/python3.12/multiprocessing/process.py", line 314, in _bootstrap
    self.run()
  File "/opt/hostedtoolcache/Python/3.12.2/x64/lib/python3.12/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/home/runner/work/portage/portage/lib/portage/util/_async/ForkProcess.py", line 328, in _bootstrap
    sys.exit(target(*(args or []), **(kwargs or {})))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/portage/portage/lib/portage/process.py", line 1441, in __call__
    return self._target(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/runner/work/portage/portage/lib/portage/process.py", line 853, in _exec_wrapper
    writemsg(f"{e}:\n   {' '.join(mycommand)}\n", noiselevel=-1)
                         ^^^^^^^^^^^^^^^^^^^
TypeError: sequence item 1: expected str instance, int found

Bug: https://bugs.gentoo.org/916566#c20
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/tests/process/test_spawn_returnproc.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/portage/tests/process/test_spawn_returnproc.py b/lib/portage/tests/process/test_spawn_returnproc.py
index 6d823d9c3d..8fbf54d0d2 100644
--- a/lib/portage/tests/process/test_spawn_returnproc.py
+++ b/lib/portage/tests/process/test_spawn_returnproc.py
@@ -32,7 +32,7 @@ class SpawnReturnProcTestCase(TestCase):
         loop = global_event_loop()
 
         async def watch_pid():
-            proc = spawn([sleep_binary, 9999], returnproc=True)
+            proc = spawn([sleep_binary, "9999"], returnproc=True)
             proc.terminate()
             self.assertEqual(await proc.wait(), -signal.SIGTERM)
 


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/process/
@ 2024-02-28  6:26 Zac Medico
  0 siblings, 0 replies; 13+ messages in thread
From: Zac Medico @ 2024-02-28  6:26 UTC (permalink / raw
  To: gentoo-commits

commit:     e882b1e956d50808a0143875a8ca35f2fc21f368
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Wed Feb 28 06:25:45 2024 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed Feb 28 06:25:45 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=e882b1e9

UnshareNetTestCase: Initialize ABILITY_TO_UNSHARE in setUp

Initialize ABILITY_TO_UNSHARE in setUp so that _unshare_validate
uses the correct PORTAGE_MULTIPROCESSING_START_METHOD setup
from super().setUp(), eliminating messages like this from CI
runs for the multiprocessing start method spawn:

    /opt/hostedtoolcache/Python/3.12.2/x64/lib/python3.12/multiprocessing/popen_fork.py:66:
    DeprecationWarning: This process (pid=2886) is multi-threaded, use of fork() may lead to deadlocks in the child.

The cause of these messages can be traced by patching python's
multiprocessing popen_fork.py like this:

--- /usr/lib/python3.12/multiprocessing/popen_fork.py
+++ /usr/lib/python3.12/multiprocessing/popen_fork.py
@@ -2,2 +2,3 @@
 import signal
+import traceback

@@ -62,2 +63,3 @@
     def _launch(self, process_obj):
+        traceback.print_stack()
         code = 1

Fixes: 3110ec376cbc ("actions: Fix interaction between start-method and pytest-xdist")
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>

 lib/portage/tests/process/test_unshare_net.py | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/lib/portage/tests/process/test_unshare_net.py b/lib/portage/tests/process/test_unshare_net.py
index dabf15585f..ad3b288ef4 100644
--- a/lib/portage/tests/process/test_unshare_net.py
+++ b/lib/portage/tests/process/test_unshare_net.py
@@ -20,19 +20,27 @@ ping -c 1 -W 1 10.0.0.1 || exit 1
 ping -c 1 -W 1 ::1 || exit 1
 ping -c 1 -W 1 fd::1 || exit 1
 """
-ABILITY_TO_UNSHARE = portage.process._unshare_validate(CLONE_NEWNET)
 
 
 class UnshareNetTestCase(TestCase):
-    @pytest.mark.skipif(
-        ABILITY_TO_UNSHARE != 0,
-        reason=f"Unable to unshare: {errno.errorcode.get(ABILITY_TO_UNSHARE, '?')}",
-    )
+    def setUp(self):
+        """
+        Initialize ABILITY_TO_UNSHARE in setUp so that _unshare_validate
+        uses the correct PORTAGE_MULTIPROCESSING_START_METHOD setup
+        from super().setUp().
+        """
+        super().setUp()
+        self.ABILITY_TO_UNSHARE = portage.process._unshare_validate(CLONE_NEWNET)
+
     @pytest.mark.skipif(
         portage.process.find_binary("ping") is None, reason="ping not found"
     )
     @pytest.mark.skipif(platform.system() != "Linux", reason="not Linux")
     def testUnshareNet(self):
+        if self.ABILITY_TO_UNSHARE != 0:
+            pytest.skip(
+                f"Unable to unshare: {errno.errorcode.get(self.ABILITY_TO_UNSHARE, '?')}"
+            )
         env = os.environ.copy()
         env["IPV6"] = "1" if portage.process._has_ipv6() else ""
         self.assertEqual(


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2024-02-28  6:26 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-25  0:45 [gentoo-commits] proj/portage:master commit in: lib/portage/tests/process/ Zac Medico
  -- strict thread matches above, loose matches on Subject: below --
2024-02-28  6:26 Zac Medico
2024-02-09  7:08 Sam James
2024-02-03 22:54 Zac Medico
2023-11-02 14:57 Zac Medico
2023-05-26 15:45 Sam James
2023-05-26 15:45 Sam James
2023-05-26 15:45 Sam James
2023-05-26 15:45 Sam James
2021-01-18 12:20 Zac Medico
2021-01-18 12:20 Zac Medico
2019-08-31  3:10 Zac Medico
2019-04-14 19:45 Zac Medico

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox