Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { createClient } from 'redis';

const redisClient = createClient({ url: process.env.REDIS_URL || 'redis://localhost:6379' });

test('Redis client connects successfully', async () => {
await redisClient.connect();
expect(redisClient.isOpen).toBe(true);
await redisClient.quit();
});

test('calls connect after quit', async () => {
await redisClient.connect();
expect(redisClient.isOpen).toBe(true);
await redisClient.quit();

await redisClient.connect();
expect(redisClient.isOpen).toBe(true);
await redisClient.quit();
});

test('calls quit before connect is resolved', async () => {
const client = createClient({ url: process.env.REDIS_URL || 'redis://localhost:6379' });
const connectPromise = client.connect();
await client.quit();
await connectPromise;
expect(client.isOpen).toBe(false);
});

test('multiple connect calls', async () => {
const client = createClient({ url: process.env.REDIS_URL || 'redis://localhost:6379' });
const connectPromise1 = client.connect();
const connectPromise2 = client.connect();
await expect(connectPromise2).rejects.toThrow('Socket already opened');
await expect(connectPromise1).resolves.toMatchObject({});
expect(client.isOpen).toBe(true);
await client.quit();
});
Comment on lines +16 to +48
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Guarantee Redis client cleanup even on assertion failures.

If an expectation throws before you hit quit(), Jest keeps the socket open and the suite hangs on teardown. Wrap each test’s connect logic in a try/finally (or add shared afterEach/afterAll cleanup) so we always close the client—even when assertions fail.

 test('Redis client connects successfully', async () => {
-  await redisClient.connect();
-  expect(redisClient.isOpen).toBe(true);
-  await redisClient.quit();
+  await redisClient.connect();
+  try {
+    expect(redisClient.isOpen).toBe(true);
+  } finally {
+    await redisClient.quit().catch(() => redisClient.disconnect());
+  }
 });

Please apply the same pattern to the other tests that open their own clients.

Committable suggestion skipped: line range outside the PR's diff.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const ErrorComponent = ({ error }: { error: Error }) => {
<div>
<h1>Error happened while rendering RSC Page</h1>
<p>{error.message}</p>
<p>{error.stack}</p>
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import RSCPostsPage from '../components/RSCPostsPage/Main';
import { listenToRequestData } from '../utils/redisReceiver';

const RSCPostsPageOverRedis = ({ requestId, ...props }, railsContext) => {
const { getValue, close } = listenToRequestData(requestId);
const { getValue, destroy } = listenToRequestData(requestId);

const fetchPosts = () => getValue('posts');
const fetchComments = (postId) => getValue(`comments:${postId}`);
const fetchUser = (userId) => getValue(`user:${userId}`);

if ('addPostSSRHook' in railsContext) {
railsContext.addPostSSRHook(close);
railsContext.addPostSSRHook(destroy);
}

return () => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ const AsyncToggleContainer = async ({ children, childrenTitle, getValue }) => {
};

const RedisReceiver = ({ requestId, asyncToggleContainer }, railsContext) => {
const { getValue, close } = listenToRequestData(requestId);
const { getValue, destroy } = listenToRequestData(requestId);

if ('addPostSSRHook' in railsContext) {
railsContext.addPostSSRHook(close);
railsContext.addPostSSRHook(destroy);
}

const UsedToggleContainer = asyncToggleContainer ? AsyncToggleContainer : ToggleContainer;
Expand Down
Loading
Loading