Commit 86f627f1 authored by Ramon Nou's avatar Ramon Nou
Browse files

test: avoid bash wrapper in sfind integration test

Run sfind and ls directly with the required environment instead of
wrapping commands in bash -c. This prevents double preloading of bash and
sfind, which can cause shell teardown crashes after successful sfind runs.

Also count matching ls output lines in Python and remove the unused shlex
import.
parent b45d460a
Loading
Loading
Loading
Loading
+13 −15
Original line number Diff line number Diff line
@@ -3,7 +3,6 @@ import pytest
import logging
from harness.gkfs import Daemon, ShellClient, Client, find_command
import os
import shlex
import time

log = logging.getLogger(__name__)
@@ -83,17 +82,19 @@ def test_sfind_permutations(test_workspace, request, conf, buff_size):
            "LIBGKFS_LOG": "info"
        }
        
        test_env_str = "\n".join([f"export {k}={v}" for k,v in test_client_env.items()])
        
        sfind_bin = find_command("sfind", test_workspace.bindirs)
        assert sfind_bin, "sfind binary not found"
        
        # --- sfind Check ---
        log.info(f"Running sfind...")
        # sfind <target_dir> -S 1 -M <mount_dir>
        sfind_cmd = f"{test_env_str}\n{sfind_bin} {test_dir} -S 1 -M {mount_dir}"
        # Use run("bash", "-c", ...)
        ret = client.run("bash", "-c", sfind_cmd, timeout=SHELL_CHECK_TIMEOUT)
        # Run sfind directly instead of wrapping it in `bash -c`: ShellClient
        # preloads the executed process, and preloading both bash and sfind can
        # make the shell crash during teardown after sfind already printed a
        # successful MATCHED line.
        ret = client.run(
            str(sfind_bin), str(test_dir), "-S", "1", "-M", str(mount_dir),
            timeout=SHELL_CHECK_TIMEOUT, env=test_client_env)

        sfind_stderr = ret.stderr.decode() if ret.stderr else ""
        sfind_stdout = ret.stdout.decode() if ret.stdout else ""
@@ -106,21 +107,18 @@ def test_sfind_permutations(test_workspace, request, conf, buff_size):
        log.info(f"Running ls check...")
        # Avoid `ls -l` here: long format stats every entry and is the first
        # thing to time out on overloaded CI runners.
        # Expected: 2000
        ls_cmd = (
            f"{test_env_str}\n"
            f"ls -1 {shlex.quote(str(test_dir))} | grep '^file_' | wc -l"
        )
        ret_ls = client.run("bash", "-c", ls_cmd, timeout=SHELL_CHECK_TIMEOUT)
        ret_ls = client.run(
            "ls", "-1", str(test_dir), timeout=SHELL_CHECK_TIMEOUT,
            env=test_client_env)

        ls_stderr = ret_ls.stderr.decode() if ret_ls.stderr else ""
        ls_stdout = ret_ls.stdout.decode() if ret_ls.stdout else ""

        assert ret_ls.exit_code == 0, f"ls check failed with {ret_ls.exit_code}\nStderr: {ls_stderr}"

        # parse count
        count = ls_stdout.strip()
        assert count == "2000", f"ls count expected 2000, got '{count}'"
        count = sum(1 for line in ls_stdout.splitlines()
                    if line.startswith("file_"))
        assert count == 2000, f"ls count expected 2000, got '{count}'"
        log.info("ls verification successful.")

    finally: