Commit 2b6ba47b authored by Ramon Nou's avatar Ramon Nou
Browse files

Fix replication recovery test daemon restart race

parent ac89eb37
Loading
Loading
Loading
Loading
Loading
+9 −3
Changes for tests/integration/data/test_replication.py: 9 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -144,6 +144,7 @@ def test_replication_survives_daemon_failure_and_recovers(
    repair_env["GKFS_NUM_REPL"] = "1"
    file_path = d00.mountdir / "replicated_failure_recovery"
    ready_marker = Path(test_workspace.twd) / "replica_failure_test_ready"
    repair_process = None
    try:
        result = setup_client.script(
            f"dd if=/dev/zero of='{file_path}' bs=1M count=2 conv=fsync status=none",
@@ -165,25 +166,30 @@ def test_replication_survives_daemon_failure_and_recovers(
        repair_script = f"""
            dd if=/dev/zero of='{file_path}' bs=1M count=2 oflag=append conv=notrunc status=none || true
            : > '{ready_marker}'
            sleep 4
            read -r restart_ready || exit 1
            sleep 3
        """
        # The degraded append can fail; the marker acknowledges its attempt.
        # Wait using a shell builtin, not a preloaded external sleep: removing
        # the dead registration temporarily leaves only one host, so a fresh
        # client with GKFS_NUM_REPL=1 cannot initialize until restart completes.
        repair_process = subprocess.Popen(
            ["bash", "-c", repair_script],
            env=repair_env,
            stdin=subprocess.PIPE,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
        )
        deadline = time.monotonic() + 15
        while not ready_marker.exists() and time.monotonic() < deadline:
            time.sleep(0.1)
        assert ready_marker.exists(), "repair client did not complete initial write"
        assert ready_marker.exists(), "repair client did not finish initial write attempt"

        _remove_dead_daemon_registration(d01)
        d01.run()
        assert d01._proc.poll() is None

        stdout, stderr = repair_process.communicate(timeout=30)
        stdout, stderr = repair_process.communicate(input=b"ready\n", timeout=30)
        assert repair_process.returncode == 0, stderr.decode(errors="replace")

        result = setup_client.script(