Skip to content

✅ server: replace redis mock with in-memory redis in tests#882

Merged
cruzdanilo merged 7 commits intomainfrom
redis
Mar 13, 2026
Merged

✅ server: replace redis mock with in-memory redis in tests#882
cruzdanilo merged 7 commits intomainfrom
redis

Conversation

@mainqueg
Copy link
Contributor

@mainqueg mainqueg commented Mar 12, 2026


Open with Devin

Summary by CodeRabbit

  • Tests

    • Tests updated to run against an in-memory Redis instance instead of mocked Redis for more realistic test behavior.
  • Chores

    • Development tooling updated to use an in-memory Redis server; mock Redis dependency removed.
    • Test runner and build settings updated to start/point to the in-memory Redis during test setup.
  • Bug Fixes

    • Server shutdown now cleanly closes Redis connections on exit.

@changeset-bot
Copy link

changeset-bot bot commented Mar 12, 2026

🦋 Changeset detected

Latest commit: 5347cf3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@exactly/server Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the testing infrastructure by transitioning from a basic Redis mock to an in-memory Redis server. This change ensures that tests interact with a Redis instance that behaves more like a real one, leading to more reliable and accurate test results without the overhead of a full Redis server. The update also involves refactoring the Redis utility module and adjusting test suites to align with the new in-memory setup.

Highlights

  • Redis Mocking Strategy Update: Replaced the ioredis-mock library with redis-memory-server for in-memory Redis testing, providing a more robust and realistic testing environment.
  • Redis Module Refactoring: Refactored the server/utils/redis.ts module to use named exports for redis and queue instances, and introduced a closeRedis function for proper resource management.
  • Test Suite Modernization: Updated various test files (auth.test.ts, e2e.ts, block.test.ts, panda.test.ts) to remove references to the old ioredis-mock and integrate with the new redis-memory-server setup, including beforeEach and afterEach hooks for Redis state management.
  • Build Environment Configuration: Added REDISMS_DISABLE_POSTINSTALL=true to the Dockerfile to prevent redis-memory-server from attempting to download binaries during Docker image builds, improving build reliability.
Changelog
  • .changeset/wise-sites-add.md
    • Added a new changeset file.
  • server/Dockerfile
    • Added REDISMS_DISABLE_POSTINSTALL=true environment variable.
  • server/api/auth/authentication.ts
    • Updated Redis import to use named export.
  • server/api/auth/registration.ts
    • Updated Redis import to use named export.
  • server/hooks/block.ts
    • Updated Redis import to use named export.
  • server/package.json
    • Removed ioredis-mock dependency.
    • Added redis-memory-server dependency.
  • server/test/api/auth.test.ts
    • Removed import for ../mocks/redis.
    • Added beforeEach to Vitest imports.
    • Updated Redis import to use named export.
    • Added beforeEach hook to set a test session in Redis.
    • Modified afterEach hook to clear all mocks and delete the test session from Redis.
    • Replaced vi.mocked(redis).getdel.mock.calls assertions with await redis.exists.
    • Removed vi.mocked(redis).getdel.mockResolvedValueOnce calls.
    • Removed vi.mock for ../../utils/redis.
  • server/test/e2e.ts
    • Removed import for ../mocks/redis.
  • server/test/hooks/block.test.ts
    • Removed import for ../mocks/redis.
    • Updated Redis import to use named export.
  • server/test/hooks/panda.test.ts
    • Removed import for ../mocks/redis.
  • server/test/mocks/redis.ts
    • Removed the Redis mock file.
  • server/test/redis.ts
    • Added a new file to set up redis-memory-server globally for tests.
  • server/utils/redis.ts
    • Changed default Redis export to named exports queue and redis.
    • Added closeRedis asynchronous function to quit both Redis instances.
  • server/vitest.config.mts
    • Added test/redis.ts to the global setup array.
    • Updated REDIS_URL environment variable to point to redis://localhost:8479.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

gemini-code-assist[bot]

This comment was marked as resolved.

@mainqueg mainqueg marked this pull request as ready for review March 12, 2026 17:41
@coderabbitai
Copy link

coderabbitai bot commented Mar 12, 2026

Walkthrough

Migrates tests from an ioredis-mock to a redis-memory-server, refactors Redis exports to provide redis and queue plus a close() helper, updates tests to use the real in-memory Redis, and wires up test global setup and shutdown to start/stop the memory Redis instance.

Changes

Cohort / File(s) Summary
Test Redis Setup
server/test/redis.ts, server/test/mocks/redis.ts
Adds server/test/redis.ts to start a RedisMemoryServer (port 8479); removes the previous ioredis-mock file.
Tests — Mock Removal & Updates
server/test/api/auth.test.ts, server/test/e2e.ts, server/test/hooks/block.test.ts, server/test/hooks/panda.test.ts
Removes imports of the Redis mock and replaces mocked-call assertions with real Redis operations and lifecycle hooks (seed/delete test keys).
Redis Utility
server/utils/redis.ts
Refactors exports: introduces queue and redis named exports, provides close() to quit both instances; changes default export to the redis instance.
Vitest Config & Globals
server/vitest.config.mts
Adds test/redis.ts to globalSetup and sets ENV.REDIS_URL to redis://localhost:8479.
Dependencies & Docker
server/package.json, server/Dockerfile
Removes ioredis-mock devDependency, adds redis-memory-server; sets REDISMS_DISABLE_POSTINSTALL=true in Dockerfile.
Server Shutdown
server/index.ts
Invokes new Redis shutdown helper during server shutdown sequence.
Changesets
.changeset/wise-sites-add.md, .changeset/red-rat-pet.md
Adds changeset placeholders noting the Redis-related changes.

Sequence Diagram(s)

mermaid
sequenceDiagram
participant Vitest as Test Runner
participant Global as GlobalSetup (test/redis.ts)
participant RedisMS as RedisMemoryServer
participant App as Server / Tests
Vitest->>Global: run globalSetup
Global->>RedisMS: start (port 8479)
Global-->>Vitest: return (ENV.REDIS_URL set)
Vitest->>App: run tests (use redis client)
App->>RedisMS: SET/GET/DEL (test lifecycle)
Vitest->>App: complete tests
Vitest->>Global: run globalTeardown / call close()
Global->>RedisMS: stop

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • nfmelendez
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: replacing a Redis mock with in-memory Redis in tests, which aligns with the majority of file changes (dependency swap, test infrastructure updates, and mock removal).

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch redis
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

sentry[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
server/package.json (1)

69-69: 🛠️ Refactor suggestion | 🟠 Major

Remove stale type package @types/ioredis-mock.

Since ioredis-mock was removed in favor of redis-memory-server, the corresponding type package @types/ioredis-mock is now unused and should be removed.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 20b390f7-2944-4df0-9a35-42117eb28e2e

📥 Commits

Reviewing files that changed from the base of the PR and between 641a8df and 7ae83f8.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (14)
  • .changeset/wise-sites-add.md
  • server/Dockerfile
  • server/api/auth/authentication.ts
  • server/api/auth/registration.ts
  • server/hooks/block.ts
  • server/package.json
  • server/test/api/auth.test.ts
  • server/test/e2e.ts
  • server/test/hooks/block.test.ts
  • server/test/hooks/panda.test.ts
  • server/test/mocks/redis.ts
  • server/test/redis.ts
  • server/utils/redis.ts
  • server/vitest.config.mts
💤 Files with no reviewable changes (3)
  • server/test/hooks/panda.test.ts
  • server/test/e2e.ts
  • server/test/mocks/redis.ts

Comment on lines +10 to +12
return async function teardown() {
await server.stop();
};
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Check if closeRedis is exported from server/utils/redis.ts
# Expect: closeRedis function to be exported

ast-grep --pattern 'export function closeRedis() {
  $$$
}'

# Also check with const export pattern
rg -n "export.*closeRedis" server/utils/redis.ts

Repository: exactly/exa

Length of output: 257


🏁 Script executed:

cat -n server/test/redis.ts

Repository: exactly/exa

Length of output: 542


Close Redis connections before stopping the server in teardown.

Import closeRedis from server/utils/redis.ts and call it before server.stop() to ensure Redis client connections are properly closed. Without this, connections may be left open or abruptly terminated when the server stops.

devin-ai-integration[bot]

This comment was marked as resolved.

@sentry
Copy link

sentry bot commented Mar 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.24%. Comparing base (a9d14e2) to head (5347cf3).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #882      +/-   ##
==========================================
+ Coverage   71.23%   71.24%   +0.01%     
==========================================
  Files         212      212              
  Lines        8378     8381       +3     
  Branches     2741     2741              
==========================================
+ Hits         5968     5971       +3     
  Misses       2132     2132              
  Partials      278      278              
Flag Coverage Δ
e2e 71.24% <100.00%> (+4.35%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

coderabbitai[bot]

This comment was marked as resolved.

sentry[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5347cf38cc

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
server/index.ts (1)

325-331: ⚠️ Potential issue | 🟠 Major

Add a shutdown timeout and preserve failure reasons.

Line 325 waits on multiple external closers without a timeout; one hung promise can block shutdown indefinitely. Also, the generic rejection message loses actionable cause details.

🔧 Proposed fix
 export async function close() {
   return new Promise((resolve, reject) => {
     server.close((error) => {
-      Promise.allSettled([closeSentry(), closeRedis(), closeSegment(), database.$client.end()])
+      const closing = Promise.allSettled([closeSentry(), closeRedis(), closeSegment(), database.$client.end()]);
+      const timeout = new Promise<never>((_, timeoutReject) =>
+        setTimeout(() => timeoutReject(new Error("closing services timed out")), 10_000),
+      );
+      Promise.race([closing, timeout])
         .then((results) => {
           if (error) reject(error);
-          else if (results.some((result) => result.status === "rejected")) reject(new Error("closing services failed"));
+          else if (Array.isArray(results) && results.some((result) => result.status === "rejected")) {
+            const reasons = results
+              .filter((result): result is PromiseRejectedResult => result.status === "rejected")
+              .map((result) => String(result.reason))
+              .join("; ");
+            reject(new Error(`closing services failed: ${reasons}`));
+          }
           else resolve(null);
         })
         .catch(reject);
     });
   });
 }

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7534e5f5-73af-4844-8ff5-36bfa822b947

📥 Commits

Reviewing files that changed from the base of the PR and between c65c11f and 5347cf3.

📒 Files selected for processing (2)
  • .changeset/red-rat-pet.md
  • server/index.ts

@cruzdanilo cruzdanilo merged commit 5347cf3 into main Mar 13, 2026
15 of 16 checks passed
@cruzdanilo cruzdanilo deleted the redis branch March 13, 2026 21:08
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.

3 participants