Skip to content

Conversation

@seongjinyoon
Copy link
Contributor

What changes were proposed in this PR?

Fixed a test isolation issue where tests that use MockTexeraDB pass when run individually but fail when run together (e.g., sbt test).

The root cause is that resource classes cache the database connection on first access. When a test class shuts down its EmbeddedPostgres and the next test class starts a new one on a different port, the cached connection still points to the dead port, causing "Connection refused" errors.

The fix ensures the connection is looked up fresh form SqlServer each time instead of being cached, so it always reflects the current database.

Files changed across 4 modules: amber, file-service, computing-unit-managing-service, common/auth.

Any related issues, documentation, discussions?

Closes #4178

How was this PR tested?

Manually tested.

Was this PR authored or co-authored using generative AI tooling?

Revised with Claude Code.

@seongjinyoon seongjinyoon changed the title Fix/dynamic dsl context lookup fix(backend)/dynamic dsl context lookup Jan 27, 2026
@seongjinyoon seongjinyoon changed the title fix(backend)/dynamic dsl context lookup fix(backend): dynamic dsl context lookup Jan 27, 2026
@chenlica
Copy link
Contributor

@seongjinyoon Thanks for the PR. Please make the subject more informative.

@seongjinyoon seongjinyoon changed the title fix(backend): dynamic dsl context lookup fix(backend): use dynamic DSLContext lookup to fix stale DB connections in tests Jan 27, 2026
@seongjinyoon
Copy link
Contributor Author

@Xiao-zhen-Liu Please review this PR. Thank you!

Copy link
Contributor

@Xiao-zhen-Liu Xiao-zhen-Liu left a comment

Choose a reason for hiding this comment

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

LGTM. @seongjinyoon Could you add some doc in SqlServer to warn against caching the DSLContext, if there is no way to enforce dynamic lookup?

Copy link
Contributor

@Xiao-zhen-Liu Xiao-zhen-Liu left a comment

Choose a reason for hiding this comment

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

I think there are some other places in the codebase that have this usage pattern, e.g., AuthResource. Please do a global check of all usages of createDSLContext() so we do not miss them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test Case Failure When Accessing Singleton Resource and Embedded DB

3 participants