Skip to content

Add tests for the time and auto save services - #167

Merged
dmccoystephenson merged 1 commit into
mainfrom
feature/time-and-autosave-service-tests
Nov 14, 2026
Merged

dmccoystephenson merged 1 commit into
mainfrom
feature/time-and-autosave-service-tests

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

This is a unit-test expansion cycle (Stage B). LocalTimeService and LocalAutoSaveService had no direct tests. Until now LocalTimeService was only reached indirectly, through ElapseCommandTest, and LocalAutoSaveService was not reached at all. The new tests describe what the code does today. No production code is changed.

  • LocalTimeServiceTest (5 tests) checks that each elapse adds one time partition of TIME_SLOT_LENGTH_IN_SECONDS * 1000 ms and that repeated calls add up. It checks the Time elapsed. Number of elapsed slots: <n> log line, and that dead actors are removed while living ones are kept. It also checks that run returns without elapsing when the application is not running.
  • LocalAutoSaveServiceTest (2 tests) checks that run neither saves nor logs when the application is not running. The second test runs the real thread loop with a storage service that only counts saves. It saves once and logs the save message. An interrupted wait is logged as Local Auto Save Service was interrupted. rather than ending the thread, and the loop stops once the running flag is cleared. The running flag is cleared before interrupt(), so the thread sees the change when it detects the interrupt.

Test plan

  • mvn clean test: 235 tests run, 0 failures, 0 errors (7 of them new)
  • mvn surefire:test -Dtest=LocalTimeServiceTest,LocalAutoSaveServiceTest: 7 run, 7 pass
  • The threaded LocalAutoSaveServiceTest was run three more times on its own and passed every time, with no flakiness seen

Issues not picked this cycle

No tracking issue. The coverage gap was found during triage.

This PR description was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).

🤖 Generated with Claude Code


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric

The anchors were mvn clean test (235 run, 0 failures) and the browser.yml CI job build-and-deploy, which passed on the PR head.

  • Scope: PASS. Only two new files were added, both under src/main/java/dansapps/interakt/tests/, and no production code was touched.
  • Tests-new: PASS. No new public production methods were added. 7 new tests cover LocalTimeService#elapse/#run and LocalAutoSaveService#run.
  • Tests-fix: N/A. No bug fix is included, so there was nothing to revert.
  • Sibling structure: PASS. Both files follow the existing test conventions: the dansapps.interakt.tests package, a class Javadoc describing what the tests characterize, org.junit.Assert, and a recording Logger subclass like the one in EntityRecordTest.
  • Sibling renames: N/A. Nothing was renamed.
  • Docs: PASS. The README's command list, build instructions and data-directory notes do not change. HelpCommand and Interakt#getCommands() are untouched.
  • Issue resolution: N/A. No Closes reference, because this is a gap found during triage.
  • No stale mvn claim / no singleton reintroduction / Help-commands parity: PASS. compile.sh, pom.xml and the README are untouched. PersistentData is passed in through constructors, and no command was added.
  • License header on new files: PASS (matches siblings). Like every other file under tests/, neither new file has a header. Whether headers should exist at all is the open question in Per-file copyright headers cite Apache License 2.0 while LICENSE is Stephenson-NC #104, so no header text was added.

Notes and limits

  • src/main/java/dansapps/interakt/tests/LocalTimeServiceTest.java:72: the dead-actor test only checks that the dead actor is removed. It cannot show that a dead actor is skipped when actions are chosen, because rest leaves a health of 0 unchanged and the other actions do nothing for an actor that has not been placed. The living actor is also unplaced, so the random action branch is only exercised in its no-op form. Covering the placed-actor branches would require controlling the new Random() inside handleEntityActions, which would change production code. That is left out of this test-only PR.
  • src/main/java/dansapps/interakt/tests/LocalAutoSaveServiceTest.java:41: the stub storage service still runs the real LocalStorageService constructor. That constructor initializes the JSON reader on the data directory, which is target/interakt-test-data under mvn test. Nothing is saved, because save() is overridden.
  • The threaded test is deterministic. Clearing the running flag happens before interrupt(), and the interrupted thread is guaranteed to see writes made before it was interrupted. If the interrupt arrives before sleep starts, the interrupt flag stays set and sleep throws right away. Three extra solo runs all passed.

Verdict: ready to merge.

This comment was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit 308a4d2 into main Nov 14, 2026
1 check passed
@dmccoystephenson
dmccoystephenson deleted the feature/time-and-autosave-service-tests branch November 14, 2026 04:23
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.

1 participant