feat(backend): improve reliability and test coverage#1285
Merged
Yunusabdul38 merged 2 commits intoJun 28, 2026
Merged
Conversation
Closes Web3Novalabs#1172 Closes Web3Novalabs#1173 Closes Web3Novalabs#1174 Closes Web3Novalabs#1175
|
@rhoggs-bot-test-account is attempting to deploy a commit to the shola's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@software321dev Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Yunusabdul38
approved these changes
Jun 28, 2026
Yunusabdul38
left a comment
Collaborator
There was a problem hiding this comment.
LGTM
Thanks for your contributon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat(backend): clean up unused imports, CORS whitelist tests, configurable DB connect timeout, and Redis cache-miss unit tests
Summary
This PR resolves four backend improvement issues targeting code quality, observability, and test coverage in the Axum-based Rust backend:
server.rsChanges
Issue #1172 — Clean up unused imports in
server.rsFile:
backend/src/server.rsserver.rspreviously importedtokio::time::Durationunder the aliasTokioDurationwhile also importingstd::time::Duration. This created redundant, potentially confusing dualDurationtypes in the same scope. The fix removes theDuration as TokioDurationalias from the tokio import and updates the single usage site to use the already-importedstd::time::Durationdirectly:This reduces cognitive overhead for contributors reading the file — there is now only one
Durationtype in scope.Issue #1173 — CORS whitelist checks from config
File:
backend/src/server.rs(new#[cfg(test)] mod testsblock)The
build_corsfunction already readsconfig.cors_allowed_originsto build theCorsLayer, enforcing the whitelist set at startup. However, there were no unit tests exercising this path. This PR adds a dedicatedtestsmodule inserver.rswith 6 tests covering:build_cors_accepts_valid_https_origin— validhttps://origin is accepted without panicbuild_cors_default_origins_are_all_valid_header_values— all 3 default origins parse into validHeaderValues (none silently dropped)build_cors_accepts_origin_with_port—http://localhost:5173parses correctlybuild_cors_accepts_multiple_origins— multiple simultaneous origins all acceptedbuild_cors_with_empty_origins_does_not_panic— empty list produces a restrictive layer without crashingbuild_cors_uses_config_origins_not_hardcoded_list— confirmsbuild_corsis parametric over the config (reads from struct, not a hardcoded list)These tests run entirely without network access and complete in milliseconds.
Issue #1174 — Configurable connect delay for Postgres database pool
Files:
backend/src/config.rs,backend/src/db.rs,backend/.env.exampleProblem
The Postgres pool had
acquire_timeout(max wait for a slot in an already-open pool) but no separateconnect_timeout— the per-connection TCP/TLS handshake timeout. In slow network environments or when Postgres is behind a load balancer, individual connections could hang for the full OS TCP timeout (several minutes) before failing, causing cascading startup delays.Implementation
Config: Addeddb_connect_timeout_secs: u64field (default10) loaded fromPREDIFI_DB_CONNECT_TIMEOUT_SECSenv var.db.rs: Wiresconfig.db_connect_timeout_secsintoPgPoolOptions::connect_timeout()so each individual connection is bounded..env.example: Documents the new variable with a clear comment distinguishing it fromPREDIFI_DB_ACQUIRE_TIMEOUT_SECS.Tests added in
db.rsbackoff_delay_with_zero_base_is_zero— zero base delay always yields zerobackoff_delay_saturates_at_max— high attempt counts are cappedretry_with_backoff_treats_zero_max_as_one—max_attempts = 0clamped to 1retry_with_backoff_succeeds_on_first_attempt— fast path: success on attempt 1 skips retriesconfig_connect_timeout_is_independent_from_acquire_timeout— the two timeout fields are independently set and non-zeroIssue #1175 — Unit tests for Redis cache cache-miss scenarios
File:
backend/src/redis_cache.rsThe existing test suite only verified the disabled-cache no-op path at a surface level. This PR adds comprehensive cache-miss tests across three categories:
Disabled-cache / cache-miss tests
cache_miss_on_disabled_cache_returns_none_for_any_keyNonecache_miss_after_set_on_disabled_cacheNone(no backing store)cache_miss_delete_on_disabled_cache_is_noopdeleteanddelete_patternon disabled cache don't panicdisabled_cache_is_not_availableis_available()returnsfalsedisabled_cache_ping_returns_falseping()returnsfalsecache_miss_is_none_not_empty_collectionNone, notSome(vec![])cache_miss_after_ttl_simulated_via_disabled_cacheCache-key uniqueness tests
pools_cache_keys_differ_by_offsetpool_details_keys_differ_by_iduser_predictions_keys_differ_by_addresscache_key_generation_is_deterministicAll tests use
RedisCache::disabled()— no live Redis instance required, making them safe for CI environments.How to Verify
All new tests are unit tests that run without any external services (no Postgres, no Redis).
To verify the configurable connect timeout works end-to-end:
With an unreachable Postgres host, the connection attempt will now fail after ~2 seconds per try rather than waiting for the OS TCP timeout.
Closes
Closes #1172
Closes #1173
Closes #1174
Closes #1175