Skip to content

test(durable): close the Spring context before the temp directory is removed - #4177

Closed
ningmao-hlyz wants to merge 1 commit into
agentscope-ai:mainfrom
ningmao-hlyz:test/http-server-tempdir
Closed

ningmao-hlyz wants to merge 1 commit into
agentscope-ai:mainfrom
ningmao-hlyz:test/http-server-tempdir

Conversation

@ningmao-hlyz

Copy link
Copy Markdown
Contributor

Problem

HttpServerApplicationTest puts the runtime's data directory inside a static @TempDir:

@TempDir static Path directory;

JUnit deletes that directory when the class finishes. The Spring context, however, is cached and stays open, so the SQLite file and the server threads are still using the directory at that moment. On Linux the deletion fails and the build fails with an error that names neither the test nor the runtime:

Failed to delete temp directory /tmp/junit-...: the following paths could not be deleted: <root>
Caused by: org.junit.platform.commons.JUnitException: Failed to close extension context

Observed in #4170 (run 43576293746), where the failing module is agentscope-examples/durable/integrated/http-server and the PR under test does not touch it.

This is invisible on Windows because the durable example modules are skipped there (-DskipDurableWindowsTests=true), so Linux CI is the only place this test runs, and the only place it fails.

Change

Dirty the context after the class, so Spring closes it and destroys its beans before JUnit removes the directory:

@DirtiesContext(classMode = ClassMode.AFTER_CLASS)

One annotation, no change to the test body, and no change to production code. JUnit runs the built-in @TempDir cleanup after user-registered extensions' afterAll callbacks, so the context is closed first.

Verification

  • The module's test passes locally with the annotation in place (Windows does execute it when -DskipDurableWindowsTests is absent).
  • spotless:check passes.
  • The failure itself only reproduces on Linux, so the real check is the Linux CI job of this PR — the annotation cannot make a passing run fail, because the context is closed either way when the JVM exits.

…removed

`HttpServerApplicationTest` puts the runtime's data directory inside a static
`@TempDir`. JUnit deletes that directory when the class finishes, but the Spring
context is cached and stays open, so the SQLite file and the server threads are
still there. On Linux the deletion then fails:

  Failed to delete temp directory /tmp/junit-...: the following paths could not be deleted

and the build fails with an error that names neither the test's own assertion nor
the runtime. Windows never showed it because the durable example modules are
skipped there (`-DskipDurableWindowsTests=true`), so Linux CI is the only place
this test runs.

Dirty the context after the class so it is closed, and its beans destroyed,
before JUnit removes the directory. The test itself is unchanged.
@ningmao-hlyz
ningmao-hlyz force-pushed the test/http-server-tempdir branch from b0270d2 to e6add77 Compare November 14, 2026 17:17
@ningmao-hlyz

Copy link
Copy Markdown
Contributor Author

Consolidated into #4176, so all the flaky-test fixes land as one change instead of several overlapping PRs.

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