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

[cmd] Add and use CommandScheduler.resetInstance() #7584

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ public static synchronized CommandScheduler getInstance() {
return instance;
}

/**
* Resets the Scheduler instance, which is useful for testing purposes. This should not be called
* from user code.
*/
public static synchronized void resetInstance() {
Starlight220 marked this conversation as resolved.
Show resolved Hide resolved
if (instance != null) {
instance.close();
}
instance = null;
}

private static final Optional<Command> kNoInterruptor = Optional.empty();

private final Map<Command, Exception> m_composedCommands = new WeakHashMap<>();
Expand Down Expand Up @@ -99,7 +110,7 @@ public static synchronized CommandScheduler getInstance() {

private final Watchdog m_watchdog = new Watchdog(TimedRobot.kDefaultPeriod, () -> {});

CommandScheduler() {
private CommandScheduler() {
HAL.report(tResourceType.kResourceType_Command, tInstances.kCommand2_Scheduler);
SendableRegistry.addLW(this, "Scheduler");
LiveWindow.setEnabledListener(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ CommandScheduler& CommandScheduler::GetInstance() {
return scheduler;
}

void CommandScheduler::ResetInstance() {
std::make_unique<Impl>().swap(GetInstance().m_impl);
Starlight220 marked this conversation as resolved.
Show resolved Hide resolved
KangarooKoala marked this conversation as resolved.
Show resolved Hide resolved
}

void CommandScheduler::SetPeriod(units::second_t period) {
m_watchdog.SetTimeout(period);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class CommandScheduler final : public wpi::Sendable,
*/
static CommandScheduler& GetInstance();

/** Resets the Scheduler instance, which is useful for testing purposes. This
* should not be called from user code. */
static void ResetInstance();

~CommandScheduler() override;
CommandScheduler(const CommandScheduler&) = delete;
CommandScheduler& operator=(const CommandScheduler&) = delete;
Expand Down Expand Up @@ -466,10 +470,5 @@ class CommandScheduler final : public wpi::Sendable,
std::unique_ptr<Impl> m_impl;

frc::Watchdog m_watchdog;

friend class CommandTestBase;

template <typename T>
friend class CommandTestBaseWithParam;
};
} // namespace frc2
Loading
Loading