From 63b8ab72335181700a4fd61a5852f481f3357956 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Thu, 14 Nov 2024 15:13:55 +0100 Subject: [PATCH] tests: Adjusted reproducer for #57 Signed-off-by: Jakub Jelen --- tests/unit/channel_test.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tests/unit/channel_test.py b/tests/unit/channel_test.py index a3df30dc1..9dc80524c 100644 --- a/tests/unit/channel_test.py +++ b/tests/unit/channel_test.py @@ -33,19 +33,23 @@ def ssh_channel(ssh_client_session): chan.close() -@pytest.mark.xfail( - reason='This test causes SEGFAULT, flakily. ' - 'Ref: https://github.com/ansible/pylibssh/issues/57', - strict=False, -) +def exec_second_command(ssh_channel): + # the important part is to call some other functions in between that will + # override stack of the first function making the memory more likely corrupted + + u_cmd_out = ssh_channel.exec_command('echo -n Hello Again').stdout.decode() + assert u_cmd_out == u'Hello Again' # noqa: WPS302 + + @pytest.mark.forked def test_exec_command(ssh_channel): """Test getting the output of a remotely executed command.""" u_cmd_out = ssh_channel.exec_command('echo -n Hello World').stdout.decode() assert u_cmd_out == u'Hello World' # noqa: WPS302 # Test that repeated calls to exec_command do not segfault. - u_cmd_out = ssh_channel.exec_command('echo -n Hello Again').stdout.decode() - assert u_cmd_out == u'Hello Again' # noqa: WPS302 + + # randomize the stack a bit more by calling this from yet another function + exec_second_command(ssh_channel) def test_double_close(ssh_channel):