@livestore/common-cf 0.0.0-snapshot-dfbad33b758f4c1709d6e294083bfb190a8230b2 โ 0.0.0-snapshot-392264be848c261bb65082bacfccb8818144da92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -1
- package/dist/do-rpc/rpc.test.js +35 -31
- package/dist/do-rpc/rpc.test.js.map +1 -1
- package/dist/ws-rpc/ws-rpc.test.js +35 -31
- package/dist/ws-rpc/ws-rpc.test.js.map +1 -1
- package/package.json +4 -4
- package/src/do-rpc/rpc.test.ts +47 -52
- package/src/ws-rpc/ws-rpc.test.ts +52 -58
|
@@ -1,58 +1,59 @@
|
|
|
1
1
|
import { Chunk, Effect, Layer, Option, RpcClient, RpcSerialization, Socket, Stream } from '@livestore/utils/effect'
|
|
2
|
-
import {
|
|
2
|
+
import { PlatformNode } from '@livestore/utils/node'
|
|
3
|
+
import { WranglerDevServerService } from '@livestore/utils-dev/node'
|
|
3
4
|
import { Vitest } from '@livestore/utils-dev/node-vitest'
|
|
4
|
-
import {
|
|
5
|
+
import { expect } from 'vitest'
|
|
5
6
|
import { TestRpcs } from './test-fixtures/rpc-schema.ts'
|
|
6
7
|
|
|
7
|
-
|
|
8
|
+
const testTimeout = 60_000
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const withWranglerTest = Vitest.makeWithTestCtx({
|
|
11
|
+
timeout: testTimeout,
|
|
12
|
+
makeLayer: () =>
|
|
13
|
+
WranglerDevServerService.Default({
|
|
14
|
+
cwd: `${import.meta.dirname}/test-fixtures`,
|
|
15
|
+
}).pipe(Layer.provide(PlatformNode.NodeContext.layer)),
|
|
14
16
|
})
|
|
15
17
|
|
|
16
18
|
const ProtocolLive = Layer.suspend(() =>
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
Effect.gen(function* () {
|
|
20
|
+
const server = yield* WranglerDevServerService
|
|
21
|
+
return RpcClient.layerProtocolSocket().pipe(
|
|
22
|
+
Layer.provide(Socket.layerWebSocket(`ws://localhost:${server.port}`)),
|
|
23
|
+
Layer.provide(Socket.layerWebSocketConstructorGlobal),
|
|
24
|
+
Layer.provide(RpcSerialization.layerJson),
|
|
25
|
+
)
|
|
26
|
+
}).pipe(Layer.unwrapEffect),
|
|
22
27
|
)
|
|
23
28
|
|
|
24
|
-
Vitest.describe('Durable Object WebSocket RPC', { timeout:
|
|
29
|
+
Vitest.describe('Durable Object WebSocket RPC', { timeout: testTimeout }, () => {
|
|
25
30
|
// Direct HTTP RPC client tests
|
|
26
|
-
Vitest.scopedLive(
|
|
27
|
-
|
|
28
|
-
Effect.fn(function* () {
|
|
31
|
+
Vitest.scopedLive('should call ping method', (test) =>
|
|
32
|
+
Effect.gen(function* () {
|
|
29
33
|
const client = yield* RpcClient.make(TestRpcs)
|
|
30
34
|
const result = yield* client.Ping({ message: 'Hello HTTP RPC' })
|
|
31
35
|
expect(result).toEqual({ response: 'Pong: Hello HTTP RPC' })
|
|
32
|
-
}
|
|
36
|
+
}).pipe(Effect.provide(ProtocolLive), withWranglerTest(test)),
|
|
33
37
|
)
|
|
34
38
|
|
|
35
|
-
Vitest.scopedLive(
|
|
36
|
-
|
|
37
|
-
Effect.fn(function* () {
|
|
39
|
+
Vitest.scopedLive('should call echo method', (test) =>
|
|
40
|
+
Effect.gen(function* () {
|
|
38
41
|
const client = yield* RpcClient.make(TestRpcs)
|
|
39
42
|
const result = yield* client.Echo({ text: 'Echo' })
|
|
40
43
|
expect(result).toEqual({ echo: 'Echo: Echo' })
|
|
41
|
-
}
|
|
44
|
+
}).pipe(Effect.provide(ProtocolLive), withWranglerTest(test)),
|
|
42
45
|
)
|
|
43
46
|
|
|
44
|
-
Vitest.scopedLive(
|
|
45
|
-
|
|
46
|
-
Effect.fn(function* () {
|
|
47
|
+
Vitest.scopedLive('should call add method', (test) =>
|
|
48
|
+
Effect.gen(function* () {
|
|
47
49
|
const client = yield* RpcClient.make(TestRpcs)
|
|
48
50
|
const result = yield* client.Add({ a: 15, b: 25 })
|
|
49
51
|
expect(result).toEqual({ result: 40 })
|
|
50
|
-
}
|
|
52
|
+
}).pipe(Effect.provide(ProtocolLive), withWranglerTest(test)),
|
|
51
53
|
)
|
|
52
54
|
|
|
53
|
-
Vitest.scopedLive(
|
|
54
|
-
|
|
55
|
-
Effect.fn(function* () {
|
|
55
|
+
Vitest.scopedLive('should handle RPC fail method', (test) =>
|
|
56
|
+
Effect.gen(function* () {
|
|
56
57
|
const client = yield* RpcClient.make(TestRpcs)
|
|
57
58
|
const error = yield* client.Fail({ message: 'test http failure' }).pipe(Effect.exit)
|
|
58
59
|
expect(error.toString()).toMatchInlineSnapshot(`
|
|
@@ -66,12 +67,11 @@ Vitest.describe('Durable Object WebSocket RPC', { timeout: 5000 }, () => {
|
|
|
66
67
|
}
|
|
67
68
|
}"
|
|
68
69
|
`)
|
|
69
|
-
}
|
|
70
|
+
}).pipe(Effect.provide(ProtocolLive), withWranglerTest(test)),
|
|
70
71
|
)
|
|
71
72
|
|
|
72
|
-
Vitest.scopedLive(
|
|
73
|
-
|
|
74
|
-
Effect.fn(function* () {
|
|
73
|
+
Vitest.scopedLive('should handle defect method', (test) =>
|
|
74
|
+
Effect.gen(function* () {
|
|
75
75
|
const client = yield* RpcClient.make(TestRpcs)
|
|
76
76
|
const error = yield* client.Defect({ message: 'test http defect' }).pipe(Effect.exit)
|
|
77
77
|
expect(error.toString()).toMatchInlineSnapshot(`
|
|
@@ -85,12 +85,11 @@ Vitest.describe('Durable Object WebSocket RPC', { timeout: 5000 }, () => {
|
|
|
85
85
|
}
|
|
86
86
|
}"
|
|
87
87
|
`)
|
|
88
|
-
}
|
|
88
|
+
}).pipe(Effect.provide(ProtocolLive), withWranglerTest(test)),
|
|
89
89
|
)
|
|
90
90
|
|
|
91
|
-
Vitest.scopedLive(
|
|
92
|
-
|
|
93
|
-
Effect.fn(function* () {
|
|
91
|
+
Vitest.scopedLive('should handle streaming RPC via HTTP', (test) =>
|
|
92
|
+
Effect.gen(function* () {
|
|
94
93
|
const client = yield* RpcClient.make(TestRpcs)
|
|
95
94
|
const stream = client.Stream({}).pipe(
|
|
96
95
|
Stream.take(4),
|
|
@@ -98,12 +97,11 @@ Vitest.describe('Durable Object WebSocket RPC', { timeout: 5000 }, () => {
|
|
|
98
97
|
)
|
|
99
98
|
const chunks = yield* Stream.runCollect(stream)
|
|
100
99
|
expect(Chunk.toReadonlyArray(chunks)).toEqual([1, 4, 9, 16]) // squares of 1,2,3,4
|
|
101
|
-
}
|
|
100
|
+
}).pipe(Effect.provide(ProtocolLive), withWranglerTest(test)),
|
|
102
101
|
)
|
|
103
102
|
|
|
104
|
-
Vitest.scopedLive(
|
|
105
|
-
|
|
106
|
-
Effect.fn(function* () {
|
|
103
|
+
Vitest.scopedLive('should handle streaming RPC with error via HTTP', (test) =>
|
|
104
|
+
Effect.gen(function* () {
|
|
107
105
|
const client = yield* RpcClient.make(TestRpcs)
|
|
108
106
|
const stream = client.StreamError({ count: 5, errorAfter: 4 })
|
|
109
107
|
const error = yield* Stream.runCollect(stream).pipe(Effect.exit)
|
|
@@ -118,12 +116,11 @@ Vitest.describe('Durable Object WebSocket RPC', { timeout: 5000 }, () => {
|
|
|
118
116
|
}
|
|
119
117
|
}"
|
|
120
118
|
`)
|
|
121
|
-
}
|
|
119
|
+
}).pipe(Effect.provide(ProtocolLive), withWranglerTest(test)),
|
|
122
120
|
)
|
|
123
121
|
|
|
124
|
-
Vitest.scopedLive(
|
|
125
|
-
|
|
126
|
-
Effect.fn(function* () {
|
|
122
|
+
Vitest.scopedLive('should handle streaming RPC with defect via HTTP', (test) =>
|
|
123
|
+
Effect.gen(function* () {
|
|
127
124
|
const client = yield* RpcClient.make(TestRpcs)
|
|
128
125
|
const stream = client.StreamDefect({ count: 4, defectAfter: 1 })
|
|
129
126
|
const error = yield* Stream.runCollect(stream).pipe(Effect.exit)
|
|
@@ -138,24 +135,22 @@ Vitest.describe('Durable Object WebSocket RPC', { timeout: 5000 }, () => {
|
|
|
138
135
|
}
|
|
139
136
|
}"
|
|
140
137
|
`)
|
|
141
|
-
}
|
|
138
|
+
}).pipe(Effect.provide(ProtocolLive), withWranglerTest(test)),
|
|
142
139
|
)
|
|
143
140
|
|
|
144
|
-
Vitest.scopedLive(
|
|
145
|
-
|
|
146
|
-
Effect.fn(function* () {
|
|
141
|
+
Vitest.scopedLive('should handle stream interruption via HTTP', (test) =>
|
|
142
|
+
Effect.gen(function* () {
|
|
147
143
|
const client = yield* RpcClient.make(TestRpcs)
|
|
148
144
|
const stream = client.StreamInterruptible({ delay: 50, interruptAfterCount: 3 }).pipe(Stream.take(3))
|
|
149
145
|
const chunks = yield* Stream.runCollect(stream)
|
|
150
146
|
expect(Chunk.toReadonlyArray(chunks)).toEqual([1, 2, 3])
|
|
151
|
-
}
|
|
147
|
+
}).pipe(Effect.provide(ProtocolLive), withWranglerTest(test)),
|
|
152
148
|
)
|
|
153
149
|
})
|
|
154
150
|
|
|
155
151
|
Vitest.describe('Hibernation Tests', { timeout: 25000 }, () => {
|
|
156
|
-
Vitest.scopedLive(
|
|
157
|
-
|
|
158
|
-
Effect.fn(function* () {
|
|
152
|
+
Vitest.scopedLive('should maintain RPC functionality after hibernation', (test) =>
|
|
153
|
+
Effect.gen(function* () {
|
|
159
154
|
console.log('๐งช Testing RPC server persistence across hibernation...')
|
|
160
155
|
|
|
161
156
|
// Step 1: Create client and test initial functionality
|
|
@@ -214,12 +209,11 @@ Vitest.describe('Hibernation Tests', { timeout: 25000 }, () => {
|
|
|
214
209
|
console.log('โ
Streaming after hibernation successful')
|
|
215
210
|
|
|
216
211
|
console.log('๐ All RPC operations successful after hibernation!')
|
|
217
|
-
}
|
|
212
|
+
}).pipe(Effect.provide(ProtocolLive), withWranglerTest(test)),
|
|
218
213
|
)
|
|
219
214
|
|
|
220
|
-
Vitest.scopedLive(
|
|
221
|
-
|
|
222
|
-
Effect.fn(function* () {
|
|
215
|
+
Vitest.scopedLive('should handle rapid operations after hibernation', (test) =>
|
|
216
|
+
Effect.gen(function* () {
|
|
223
217
|
console.log('๐งช Testing rapid operations after hibernation...')
|
|
224
218
|
|
|
225
219
|
console.log('Step 1: Establishing initial connection...')
|
|
@@ -266,6 +260,6 @@ Vitest.describe('Hibernation Tests', { timeout: 25000 }, () => {
|
|
|
266
260
|
results.map((r) => r.operation),
|
|
267
261
|
)
|
|
268
262
|
console.log('๐ Rapid operations work correctly after hibernation!')
|
|
269
|
-
}
|
|
263
|
+
}).pipe(Effect.provide(ProtocolLive), withWranglerTest(test)),
|
|
270
264
|
)
|
|
271
265
|
})
|