-
Notifications
You must be signed in to change notification settings - Fork 24
test: migrate SQLite tests to use in-memory databases #637
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
base: unstable
Are you sure you want to change the base?
Conversation
Updates database and eth test modules to use in-memory SQLite databases instead of temporary files for faster test execution and reduced I/O. - Add test-only connection customizer for in-memory schema initialization - Update TestFixture to use :memory: by default with file-based fallback - Keep persistence-dependent tests using file-based databases - Migrate slashing database tests to in-memory
0c23f64
to
68c7e1e
Compare
- Use Option<TempDir> in TestFixture to avoid unnecessary temp directory creation for in-memory tests - Change in-memory DB support from cfg(test) to feature="test-utils" to enable usage in integration tests - Fix restart-related tests to use file-based fixtures for persistence validation - Revert slashing database to use temp files (external crate limitation) - Add documentation for schema migration bypass in in-memory tests - Improve test comment clarity and remove redundant assertions
Renamed TestFixture constructor methods to better describe their behavior: - new() → new_in_memory() - in-memory database with populated cluster - new_empty() → new_in_memory_empty() - in-memory database, empty - new_with_file() - kept as is - file-based database with populated cluster - new_empty_with_file() - kept as is - file-based database, empty Updated all call sites in database and eth integration tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, thanks!
anchor/eth/tests/common/mod.rs
Outdated
// Keep temp_dir alive by leaking it - tests are short-lived anyway | ||
std::mem::forget(temp_dir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes the test run to leave behind files. This might be irrelevant for CI runs, but I want my developer machine cleaned up.
fn open_or_create(path: &Path, domain: DomainType) -> Result<Pool, DatabaseError> { | ||
schema::ensure_up_to_date(path, domain)?; | ||
Self::open_conn_pool(path) | ||
if path.to_string_lossy() != ":memory:" { | ||
schema::ensure_up_to_date(path, domain)?; | ||
} | ||
Self::open_conn_pool(path, domain) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not really like this or the conditional function below. Using the connection hook to create the schema also feels like a hack. What do you think about a separate function open_in_memory
that creates a pool with a connection that does not time out and creates the schema always?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pushed a new whole design, let me know what you think
…posability Simplified test fixture design with the following improvements: - Eliminated operator generation duplication by extracting generate_default_operators() helper This fixes a bug where operators were generated twice with different RSA keys - Removed legacy TestFixture type alias and updated all tests to use explicit InMemoryTestFixture/FileTestFixture types for clarity - Changed TestFixtureData.db to Arc<NetworkDatabase> to support tests requiring shared ownership (particularly eth integration tests) - Created ProcessorFixture combining InMemoryTestFixture with EventProcessor setup, eliminating the pattern of creating fixtures just to extract the database - Added comprehensive documentation explaining fixture state and design decisions All 38 database tests and 6 eth integration tests pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
638fb8e
to
0d79eeb
Compare
@claude review this PR |
Claude finished @diegomrsantos's task —— View job Code Review In Progress
Todo List
|
@claude review this PR |
Issue Addressed
N/A - Performance improvement and code quality enhancement for test suite
Proposed Changes
In-Memory Database Migration
new_in_memory()
API to replace magic:memory:
stringTest Fixture Refactoring
generate_default_operators()
helper to fix bug where operators were generated twice with different RSA keysTestFixture
type alias and updated all 38+ tests to use explicitInMemoryTestFixture
/FileTestFixture
for clarityTestFixtureData.db
toArc<NetworkDatabase>
to support tests requiring shared ownership (especially eth integration tests)InMemoryTestFixture
withEventProcessor
setup, eliminating awkward patterns in eth testsAdditional Info
This PR improves both test performance and code quality:
All 38 database tests and 6 eth integration tests pass successfully.