@@ -11,8 +11,7 @@ import {
11
11
createServiceClient ,
12
12
createServiceHandler ,
13
13
} from "@cocalc/conat/service/typed" ;
14
- import { once } from "@cocalc/util/async-utils" ;
15
- import { before , after , connect } from "@cocalc/backend/conat/test/setup" ;
14
+ import { before , after } from "@cocalc/backend/conat/test/setup" ;
16
15
import { wait } from "@cocalc/backend/conat/test/util" ;
17
16
import { is_date as isDate } from "@cocalc/util/misc" ;
18
17
import { delay } from "awaiting" ;
@@ -23,14 +22,11 @@ beforeAll(before);
23
22
24
23
describe ( "create a service and test it out" , ( ) => {
25
24
let s ;
26
- let subject ;
27
25
it ( "creates a service" , async ( ) => {
28
26
s = createConatService ( {
29
27
service : "echo" ,
30
28
handler : ( mesg ) => mesg . repeat ( 2 ) ,
31
29
} ) ;
32
- subject = s . subject ;
33
- await once ( s , "running" ) ;
34
30
expect ( await callConatService ( { service : "echo" , mesg : "hello" } ) ) . toBe (
35
31
"hellohello" ,
36
32
) ;
@@ -42,16 +38,6 @@ describe("create a service and test it out", () => {
42
38
await callConatService ( { service : "echo" , mesg : "hi" , timeout : 250 } ) ;
43
39
} ) . rejects . toThrowError ( "timeout" ) ;
44
40
} ) ;
45
-
46
- // [ ] TODO: broken!
47
- it . skip ( "creates a listener on the same subject and try to call to verify timeout works" , async ( ) => {
48
- const client = connect ( ) ;
49
- const sub = await client . subscribe ( subject ) ;
50
- await expect ( async ( ) => {
51
- await callConatService ( { service : "echo" , mesg : "hi" , timeout : 250 } ) ;
52
- } ) . rejects . toThrowError ( "timeout" ) ;
53
- sub . close ( ) ;
54
- } ) ;
55
41
} ) ;
56
42
57
43
describe ( "verify that you can create a service AFTER calling it and things to still work fine" , ( ) => {
@@ -231,4 +217,42 @@ describe("create a service with specified client, stop and start the server, and
231
217
} ) ;
232
218
} ) ;
233
219
220
+ describe ( "create a slow service and check that the timeout parameter works" , ( ) => {
221
+ let s ;
222
+ it ( "creates a slow service" , async ( ) => {
223
+ s = createConatService ( {
224
+ service : "slow" ,
225
+ handler : async ( d ) => {
226
+ await delay ( d ) ;
227
+ return { delay : d } ;
228
+ } ,
229
+ } ) ;
230
+ } ) ;
231
+
232
+ it ( "confirms it works" , async ( ) => {
233
+ const t0 = Date . now ( ) ;
234
+ const r = await callConatService ( {
235
+ service : s . name ,
236
+ mesg : 50 ,
237
+ } ) ;
238
+ expect ( r ) . toEqual ( { delay : 50 } ) ;
239
+ expect ( Date . now ( ) - t0 ) . toBeGreaterThan ( 45 ) ;
240
+ expect ( Date . now ( ) - t0 ) . toBeLessThan ( 500 ) ;
241
+ } ) ;
242
+
243
+ it ( "confirms it throws a timeout error" , async ( ) => {
244
+ await expect ( async ( ) => {
245
+ await callConatService ( {
246
+ service : s . name ,
247
+ mesg : 5000 ,
248
+ timeout : 75 ,
249
+ } ) ;
250
+ } ) . rejects . toThrowError ( "imeout" ) ;
251
+ } ) ;
252
+
253
+ it ( "clean up" , async ( ) => {
254
+ s . close ( ) ;
255
+ } ) ;
256
+ } ) ;
257
+
234
258
afterAll ( after ) ;
0 commit comments