Skip to content

Handle cross-platform shell execution and adapt test utilities accordingly#2226

Open
mkondratek wants to merge 1 commit intodevelopfrom
mk/chore/tests-on-windows
Open

Handle cross-platform shell execution and adapt test utilities accordingly#2226
mkondratek wants to merge 1 commit intodevelopfrom
mk/chore/tests-on-windows

Conversation

@mkondratek
Copy link
Collaborator

No description provided.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests in this class were failing before on Windows. Now they pass. 🟢

Process process = new ProcessBuilder()
.command(command)
.directory(workingDirectory.toFile())
.redirectErrorStream(true)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On Windows, the OS pipe buffer for process output is limited. In the original implementation, the Java process called process.waitFor() before reading from the output streams. When the script's output exceeded the buffer size, the script would block waiting for the buffer to be cleared, while the Java process was blocked waiting for the script to finish, resulting in a deadlock.

@mkondratek mkondratek force-pushed the mk/chore/tests-on-windows branch from d769fb4 to cfaa4a2 Compare January 31, 2026 23:39
@mkondratek
Copy link
Collaborator Author

@PawelLipski, let me know whether we want to get all these tests running and green on Windows.

I think it should be possible (including the UI tests), but we’d also need Windows CI. Without it, we’ll likely end up with Windows-only failures again sooner or later.

If setting up a Windows pipeline is too costly, maybe we should reconsider fixing these tests on Windows for now. Even this PR—which is mostly a preamble for follow-up changes—already adds quite a bit of Windows-specific boilerplate. If that code is likely to stay unused, maybe we shouldn’t introduce it yet.

WDYT?

@PawelLipski
Copy link
Collaborator

@PawelLipski, let me know whether we want to get all these tests running and green on Windows.

I think it should be possible (including the UI tests), but we’d also need Windows CI. Without it, we’ll likely end up with Windows-only failures again sooner or later.

If setting up a Windows pipeline is too costly, maybe we should reconsider fixing these tests on Windows for now. Even this PR—which is mostly a preamble for follow-up changes—already adds quite a bit of Windows-specific boilerplate. If that code is likely to stay unused, maybe we shouldn’t introduce it yet.

WDYT?

Definitely, let's set up Windows CI if it isn't too difficult. In git-machete CLI, there's a dedicated Windows executor/job and even a macOS executor/job. Both are free for public repositories & generally smooth to use.

@@ -1,12 +1,7 @@
package com.virtuslab.gitmachete.backend.integration;

import static com.virtuslab.gitmachete.backend.api.SyncToRemoteStatus.AheadOfRemote;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow weird that these imports weren't removed, despite removeUnusedImports() settings.

Lemme open an issue for fixing that - #2228

rootDirectoryPath.resolve("machete-post-slide-out-hook-executed")

fun Path.makeExecutable() {
if (System.getProperty("os.name").lowercase(getDefault()).contains("windows")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's extract this to some shared place in testCommon

String shell = "bash";
String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("windows")) {
String gitPath = runProcessAndReturnStdout(5, "where", "git").trim().split(System.lineSeparator())[0];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it just be where sh instead of where git? 🤔


String stdout = IOUtils.toString(process.getInputStream(), StandardCharsets.UTF_8);
String stderr = IOUtils.toString(process.getErrorStream(), StandardCharsets.UTF_8);
boolean completed = process.waitFor(timeoutSeconds, TimeUnit.SECONDS);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm now that waitFor is after getInputStream()... can String stderr = IOUtils.toString(process.getErrorStream(), ...) be restored? or is redirectErrorStream still required for some reason?

cd $dir || exit 1
shift
git init "$@"
if [[ "$(uname -s)" != *MINGW*_NT* ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 not needed anymore?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants