Skip to content

Commit 5aeb91a

Browse files
rewrite redisReceiver module to be simpler
1 parent 10f1644 commit 5aeb91a

File tree

5 files changed

+162
-299
lines changed

5 files changed

+162
-299
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { createClient } from 'redis';
2+
3+
const redisClient = createClient({ url: process.env.REDIS_URL || 'redis://localhost:6379' });
4+
5+
test('Redis client connects successfully', async () => {
6+
await redisClient.connect();
7+
expect(redisClient.isOpen).toBe(true);
8+
await redisClient.quit();
9+
});
10+
11+
test('calls connect after quit', async () => {
12+
await redisClient.connect();
13+
expect(redisClient.isOpen).toBe(true);
14+
await redisClient.quit();
15+
16+
await redisClient.connect();
17+
expect(redisClient.isOpen).toBe(true);
18+
await redisClient.quit();
19+
});
20+
21+
test('calls quit before connect is resolved', async () => {
22+
const client = createClient({ url: process.env.REDIS_URL || 'redis://localhost:6379' });
23+
const connectPromise = client.connect();
24+
await client.quit();
25+
await connectPromise;
26+
expect(client.isOpen).toBe(false);
27+
});
28+
29+
test('multiple connect calls', async () => {
30+
const client = createClient({ url: process.env.REDIS_URL || 'redis://localhost:6379' });
31+
const connectPromise1 = client.connect();
32+
const connectPromise2 = client.connect();
33+
await expect(connectPromise2).rejects.toThrow('Socket already opened');
34+
await expect(connectPromise1).resolves.toMatchObject({});
35+
expect(client.isOpen).toBe(true);
36+
await client.quit();
37+
});

react_on_rails_pro/spec/dummy/client/app/components/ErrorComponent.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const ErrorComponent = ({ error }: { error: Error }) => {
77
<div>
88
<h1>Error happened while rendering RSC Page</h1>
99
<p>{error.message}</p>
10+
<p>{error.stack}</p>
1011
</div>
1112
);
1213
};

react_on_rails_pro/spec/dummy/client/app/ror-auto-load-components/RSCPostsPageOverRedis.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import RSCPostsPage from '../components/RSCPostsPage/Main';
33
import { listenToRequestData } from '../utils/redisReceiver';
44

55
const RSCPostsPageOverRedis = ({ requestId, ...props }, railsContext) => {
6-
const { getValue, close } = listenToRequestData(requestId);
6+
const { getValue, destroy } = listenToRequestData(requestId);
77

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

1212
if ('addPostSSRHook' in railsContext) {
13-
railsContext.addPostSSRHook(close);
13+
railsContext.addPostSSRHook(destroy);
1414
}
1515

1616
return () => (

react_on_rails_pro/spec/dummy/client/app/ror-auto-load-components/RedisReceiver.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ const AsyncToggleContainer = async ({ children, childrenTitle, getValue }) => {
3434
};
3535

3636
const RedisReceiver = ({ requestId, asyncToggleContainer }, railsContext) => {
37-
const { getValue, close } = listenToRequestData(requestId);
37+
const { getValue, destroy } = listenToRequestData(requestId);
3838

3939
if ('addPostSSRHook' in railsContext) {
40-
railsContext.addPostSSRHook(close);
40+
railsContext.addPostSSRHook(destroy);
4141
}
4242

4343
const UsedToggleContainer = asyncToggleContainer ? AsyncToggleContainer : ToggleContainer;

0 commit comments

Comments
 (0)