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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #53 Unable to delete file on windows #306

Merged
merged 8 commits into from May 15, 2022
Merged

Fix #53 Unable to delete file on windows #306

merged 8 commits into from May 15, 2022

Conversation

badoualy
Copy link
Contributor

@badoualy badoualy commented May 7, 2022

馃搶 References

馃帺 What is the goal?

Attempt to fix issues with gradle process locking files on windows.

How is it being implemented?

  • Move the removeProjectTemporalScreenshotsFolder call below generateVerificationReport to avoid crashing before the report is generated
  • Use a uid suffix for the pulled screenshot folders
  • Wrap each delete call in a try/catch to not crash

How can it be tested?

No particular step. But I didn't test yet, I need to try publishing it on my local maven repo or use jitpack.

Note

  • I kept an empty suffix for the tests to avoid breaking everything. I'm not sure how you'd want to handle it. Maybe add new specific cases for this case?
  • Small doubt about the System.currentTimeMillis().toString part, first time writing scala, not sure if the timestamp will be generated at each run, or once when the plugin is configured.

The PR is more of a draft/suggestion to help the author rather than a ready-to-merge PR.
If you have feedbacks I can try improving it.

@badoualy
Copy link
Contributor Author

@pedrovgs It should be fine now.

When I run the command locally, every scala file is reported as Files incorrectly formatted 馃 (even the ones I didn't edit)
So if it's still not OK, not sure what's wrong.

Copy link
Owner

@pedrovgs pedrovgs left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution @badoualy 馃憦 Apart form the comments in the code, I'm going to try to answer your questions here:

I kept an empty suffix for the tests to avoid breaking everything. I'm not sure how you'd want to handle it. Maybe add new specific cases for this case?

We should add specific coverage yeap.

Small doubt about the System.currentTimeMillis().toString part, first time writing scala, not sure if the timestamp will be generated at each run, or once when the plugin is configured.

Why don't we replace this with a UUID? I think the timestamp is going to be generated for each run btw.

We should test these changes from a windows machine before merging. Remember there are commands you can use in order to install the artifact locally and test.

FileUtils.deleteDirectory(new File(shotFolder.pulledComposeOrchestratedScreenshotsFolder()))
} catch {
case e: Throwable => println(Console.RED + s"Shot error: $e")
}
Copy link
Owner

Choose a reason for hiding this comment

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

Instead of duplicating all these lines, can we extract common code to a function? I don't remember if there was a file to handle file management tasks, but at least we could use a private function for this.

@@ -9,10 +9,12 @@ case class ShotFolder(
private val flavor: Option[String],
private val directorySuffix: Option[String],
private val separator: String,
private val orchestrated: Boolean
private val orchestrated: Boolean,
private val uid: String
Copy link
Owner

Choose a reason for hiding this comment

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

Is this UUD something we really need to fix this bug? Or just the previous change is enough?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous change will ensure that when the files are locked by the process, calling delete won't crash and make the task fail.

But since the files might not be deleted, attempting to re-run the task will fail because the file already exist, and can't be deleted.

@badoualy
Copy link
Contributor Author

badoualy commented May 10, 2022

We should add specific coverage yeap.

I'll see what I can do

Why don't we replace this with a UUID? I think the timestamp is going to be generated for each run btw.

We can

Edit: I tested, the try/catch part is ok, the directory suffix is NOK, looks like files are not renamed when copied from device, I'll attempt to fix when I have more time

Edit2: pullScreenshots is not taking in account shotFolder.pulledScreenshotsFolder() 馃槃

@badoualy
Copy link
Contributor Author

@pedrovgs The UUID solution won't work, because the UUID will be different between the downloadScreenshots task and the ExecuteScreenshotTests task as they are run separately.

So we can keep the try/catch to avoid having the task fail and still generate the report. But the next run will still fail unless the file is deleted manually 馃し

@badoualy badoualy requested a review from pedrovgs May 14, 2022 17:10
Copy link
Owner

@pedrovgs pedrovgs left a comment

Choose a reason for hiding this comment

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

@badoualy I'm approving and merging this PR. It will be included in the next release I'm about to publish. I'm wondering if there is something we can do to ensure we don't break windows support in the future. Different users reported in the past this library wasn't working for windows, others reported that it worked and some PRs were merged in order to fix this but looks like it wasn't always fully working. Can we do something to improve this situation and ensure we validate windows integration at least for the recording and verification tasks?

@pedrovgs pedrovgs merged commit 957c19e into pedrovgs:master May 15, 2022
@sergio-sastre
Copy link

@pedrovgs what about GithubActions? Have no experience with it, but I see in this blog post that one could run tests on specific machines?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants