11import { describe , test , expect } from "vitest" ;
2- import { mf } from "./mf" ;
2+ import { mf , mfUrl } from "./mf" ;
33
44describe ( "Panic Hook with WASM Reinitialization" , ( ) => {
55 test ( "panic recovery tests" , async ( ) => {
66 // basic panic recovery
77 {
8- const panicResp = await mf . dispatchFetch ( "http://fake.host/test-panic" ) ;
8+ await mf . dispatchFetch ( `${ mfUrl } durable/COUNTER` ) ;
9+ const resp = await mf . dispatchFetch ( `${ mfUrl } durable/COUNTER` ) ;
10+ expect ( await resp . text ( ) ) . toContain ( "unstored_count: 2" ) ;
11+
12+ const panicResp = await mf . dispatchFetch ( `${ mfUrl } test-panic` ) ;
913 expect ( panicResp . status ) . toBe ( 500 ) ;
1014
1115 const panicText = await panicResp . text ( ) ;
1216 expect ( panicText ) . toContain ( "Workers runtime canceled" ) ;
1317
14- const normalResp = await mf . dispatchFetch ( "http://fake.host/durable/hello" ) ;
15- expect ( normalResp . status ) . toBe ( 200 ) ;
16-
17- const normalText = await normalResp . text ( ) ;
18- expect ( normalText ) . toContain ( "Hello from my-durable-object!" ) ;
18+ const normalResp = await mf . dispatchFetch ( `${ mfUrl } durable/COUNTER` ) ;
19+ expect ( await normalResp . text ( ) ) . toContain ( "unstored_count: 1" ) ;
1920 }
2021
2122 // multiple requests after panic all succeed
2223 {
23- const panicResp = await mf . dispatchFetch ( "http://fake.host/ test-panic" ) ;
24+ const panicResp = await mf . dispatchFetch ( ` ${ mfUrl } test-panic` ) ;
2425 expect ( panicResp . status ) . toBe ( 500 ) ;
2526
2627 const requests = [
27- mf . dispatchFetch ( "http://fake.host/ durable/hello" ) ,
28- mf . dispatchFetch ( "http://fake.host/ durable/hello" ) ,
29- mf . dispatchFetch ( "http://fake.host/ durable/hello" ) ,
28+ mf . dispatchFetch ( ` ${ mfUrl } durable/hello` ) ,
29+ mf . dispatchFetch ( ` ${ mfUrl } durable/hello` ) ,
30+ mf . dispatchFetch ( ` ${ mfUrl } durable/hello` ) ,
3031 ] ;
3132
3233 const responses = await Promise . all ( requests ) ;
@@ -41,9 +42,9 @@ describe("Panic Hook with WASM Reinitialization", () => {
4142 // simultaneous requests during panic handling
4243 {
4344 const simultaneousRequests = [
44- mf . dispatchFetch ( "http://fake.host/ test-panic" ) , // This will panic
45- mf . dispatchFetch ( "http://fake.host/ durable/hello" ) , // This should succeed after reinitialization
46- mf . dispatchFetch ( "http://fake.host/ durable/hello" ) ,
45+ mf . dispatchFetch ( ` ${ mfUrl } test-panic` ) , // This will panic
46+ mf . dispatchFetch ( ` ${ mfUrl } durable/hello` ) , // This should succeed after reinitialization
47+ mf . dispatchFetch ( ` ${ mfUrl } durable/hello` ) ,
4748 ] ;
4849
4950 const responses = await Promise . all ( simultaneousRequests ) ;
@@ -64,12 +65,10 @@ describe("Panic Hook with WASM Reinitialization", () => {
6465 // worker continues to function normally after multiple panics
6566 {
6667 for ( let cycle = 1 ; cycle <= 3 ; cycle ++ ) {
67- const panicResp = await mf . dispatchFetch ( "http://fake.host/ test-panic" ) ;
68+ const panicResp = await mf . dispatchFetch ( ` ${ mfUrl } test-panic` ) ;
6869 expect ( panicResp . status ) . toBe ( 500 ) ;
6970
70- const recoveryResp = await mf . dispatchFetch (
71- "http://fake.host/durable/hello"
72- ) ;
71+ const recoveryResp = await mf . dispatchFetch ( `${ mfUrl } durable/hello` ) ;
7372 expect ( recoveryResp . status ) . toBe ( 200 ) ;
7473 }
7574 }
0 commit comments