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-file-locking #91

Merged
merged 2 commits into from
Jul 6, 2024
Merged

Fix-file-locking #91

merged 2 commits into from
Jul 6, 2024

Conversation

brettle
Copy link
Member

@brettle brettle commented Jul 6, 2024

Move file locking to WebotsSimulator to fix #90 and ensure endCompetition() is always called to at least partially fix #85.

Also makes WebotsSimulator constructor take the robot class instead of making the run() method take a robot instance. That helps discourage the test code from instantiating a robot because doing so might cause WPILib to try to start a NetworkTables server when another test already has one running.

…tion() is always called to at least partially fix #85.

Also makes WebotsSimulator constructor take the robot class instead of making the run() method take a robot instance. That helps discourage the test code from instantiating a robot because doing so might cause WPILib to try to start a NetworkTables server when another test already has one running.
@brettle brettle requested a review from a team as a code owner July 6, 2024 23:00
@brettle brettle enabled auto-merge July 6, 2024 23:00
Copy link
Member

@CoolSpy3 CoolSpy3 left a comment

Choose a reason for hiding this comment

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

Nice! You opened this while I was writing you a mattermost message about tests not working on my machine. This PR fixes that! :D

Side note: The first time I ran this, testShaftRotatesInAutonomous failed, but I've tried it again, and it seems to work now, so it may just be a case of a non-ideal testing environment (i.e. me running too many programs at once).

*/
public WebotsSimulator(String worldFilePath) throws FileNotFoundException {
public WebotsSimulator(String worldFilePath,
Class<? extends TimedRobot> cls)
Copy link
Member

Choose a reason for hiding this comment

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

I'd recommend taking a Supplier<TimedRobot> instead, and then passing Robot::new instead of Robot.class. This would allow you to avoid the reflection later and support robot classes with non-default constructors.

}
}

static private synchronized void acquireFileLock()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
static private synchronized void acquireFileLock()
private static synchronized void acquireFileLock()

@brettle brettle merged commit 13e25f9 into master Jul 6, 2024
4 checks passed
@brettle brettle deleted the fix-file-locking branch July 6, 2024 23:31
@CoolSpy3
Copy link
Member

CoolSpy3 commented Jul 6, 2024

Whoops, I hit approve while forgetting that I had suggestions (too excited about getting tests working) :/ My bad.

@CoolSpy3 CoolSpy3 mentioned this pull request Jul 7, 2024
@brettle
Copy link
Member Author

brettle commented Jul 7, 2024

The first time I ran this, testShaftRotatesInAutonomous failed, but I've tried it again, and it seems to work now, so it may just be a case of a non-ideal testing environment

Opened issue #94 to cover this.

CoolSpy3 added a commit that referenced this pull request Jul 7, 2024
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.

Build hangs when previous build interrupted CI sometimes hangs
2 participants