Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only restart if a machine is running #3491

Merged
merged 1 commit into from Aug 29, 2023

Conversation

cdrage
Copy link
Contributor

@cdrage cdrage commented Aug 10, 2023

fix: only restart if a machine is running

What does this PR do?

No matter what, it would try to restart regardless if a machine was
running or not.

This is because the if statement was: if (isRunning !== '') which will
always return true even if isRunning was undefined.

The if statement has now been changes to if (isRunning) meaning it
will only run if isRunning is defined (not '').

Screenshot/screencast of this PR

N/A. The prompt will not appear when trying to restart it if there is no
machine running.

What issues does this PR fix or reference?

Closes #3321

How to test this PR?

Click on Docker Compatibility with a Podman Machine stopped. You should
not get the prompt to restart the podman machine.

Signed-off-by: Charlie Drage charlie@charliedrage.com

@cdrage cdrage requested review from benoitf and a team as code owners August 10, 2023 18:48
@cdrage cdrage requested review from dgolovin and jeffmaury and removed request for a team August 10, 2023 18:48
@cdrage cdrage marked this pull request as draft August 10, 2023 19:23
@cdrage cdrage force-pushed the compat-on-off branch 2 times, most recently from 67d918e to aa66ca3 Compare August 10, 2023 20:28
@deboer-tim
Copy link
Collaborator

findRunningMachine() says it returns a boolean, maybe fix that too?

@cdrage
Copy link
Contributor Author

cdrage commented Aug 11, 2023

Ready for review! 💯 had to figure out what was happening inside the tests and then realized it wasn't being mocked correctly (even for an old test too).

Updated and ready 👍

Copy link
Contributor

@dgolovin dgolovin left a comment

Choose a reason for hiding this comment

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

Verified on mac and it works for me now. No requests to restart machine if it does not exist or is not started.

disable() and enable() functions can be improved (optional).

LGTM

extensions/podman/src/compatibility-mode.ts Outdated Show resolved Hide resolved
extensions/podman/src/compatibility-mode.ts Outdated Show resolved Hide resolved
@cdrage
Copy link
Contributor Author

cdrage commented Aug 14, 2023

Thank you for the suggestion @dgolovin ! Totally makes the code a lot cleaner. Pushed your suggestion 👍

@cdrage
Copy link
Contributor Author

cdrage commented Aug 14, 2023

@dgolovin

Unfortunately return findRunningMachine().then(machine => this.promptRestart(machine)); does not work compared to:

    const isRunning = await findRunningMachine();
    if (isRunning) {
      await this.promptRestart(isRunning);
    }

    return Promise.resolve();

As even when it returns undefined in findRunningMachine, promptRestart is still ran in the function: return findRunningMachine().then(machine => this.promptRestart(machine));

If you replace the code, you'll see that the tests now fail.

I've updated the code back to the previous change.

Copy link
Contributor

@dgolovin dgolovin left a comment

Choose a reason for hiding this comment

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

@cdrage I was suggesting to do this as a fix.

Please remove at least

return Promise.resolve();

it is not needed and result is going to be the same.

@cdrage
Copy link
Contributor Author

cdrage commented Aug 15, 2023

@cdrage I was suggesting to do this as a fix.

Please remove at least

return Promise.resolve();

it is not needed and result is going to be the same.

Hi, I commented on the PR. Bit confused on return Promise.Resolve suggestion, it's added to the tests in order to mock the functionality.

@cdrage
Copy link
Contributor Author

cdrage commented Aug 15, 2023

@dgolovin Ready for another review / I've pushed your changes! :)

@cdrage cdrage force-pushed the compat-on-off branch 3 times, most recently from 53823cf to 5128223 Compare August 16, 2023 13:53
@cdrage
Copy link
Contributor Author

cdrage commented Aug 16, 2023

Getting some weird errors with smoke testing @odockal @dgolovin any ideas? Rebased + it works fine with yarn watch, but unsure why it's causing these tests to fail.

@cdrage cdrage force-pushed the compat-on-off branch 2 times, most recently from dd07b3a to 6074e77 Compare August 17, 2023 12:39
@cdrage
Copy link
Contributor Author

cdrage commented Aug 17, 2023

Tests pass now 💯

@cdrage cdrage requested a review from dgolovin August 21, 2023 13:16
### What does this PR do?

No matter what, it would try to restart regardless if a machine was
running or not.

This is because the if statement was: `if (isRunning !== '')` which will
always return true even if isRunning was undefined.

The if statement has now been changes to `if (isRunning)` meaning it
will only run if isRunning is defined (not '').

### Screenshot/screencast of this PR

<!-- Please include a screenshot or a screencast
explaining what is doing this PR -->

N/A. The prompt will not appear when trying to restart it if there is no
machine running.

### What issues does this PR fix or reference?

<!-- Include any related issues from Podman Desktop
repository (or from another issue tracker). -->

Closes containers#3321

### How to test this PR?

<!-- Please explain steps to reproduce -->

Click on Docker Compatibility with a Podman Machine stopped. You should
not get the prompt to restart the podman machine.

Signed-off-by: Charlie Drage <charlie@charliedrage.com>
@cdrage cdrage merged commit 51b6ac3 into containers:main Aug 29, 2023
8 checks passed
@podman-desktop-bot podman-desktop-bot added this to the 1.4.0 milestone Aug 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants