Skip to content

Commit

Permalink
Add and use CommandScheduler.resetInstance()
Browse files Browse the repository at this point in the history
  • Loading branch information
KangarooKoala committed Dec 23, 2024
1 parent 76625fa commit 4c568c9
Show file tree
Hide file tree
Showing 60 changed files with 1,579 additions and 1,961 deletions.
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() {
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);
}

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

0 comments on commit 4c568c9

Please sign in to comment.