1- import { it } from "node:test" ;
1+ import { describe , it } from "node:test" ;
22import assert from "node:assert" ;
33import { useService } from "../src/service.ts" ;
44import { each , Err , Ok , run } from "effection" ;
@@ -16,24 +16,86 @@ it("test service", async () => {
1616 assert ( assertionCount > 0 ) ;
1717} ) ;
1818
19- it ( "test with wellness" , async ( ) => {
20- let assertionCount = 0 ;
21- await run ( function * ( ) {
22- yield * useService ( "test-service" , nodeScriptWorks , {
23- wellnessCheck : {
24- timeout : 200 ,
25- * operation ( stdio ) {
26- for ( let line of yield * each < string > ( stdio ) ) {
27- if ( line . includes ( "test service started" ) ) {
28- return Ok < void > ( void 0 ) ;
19+ describe ( "useService with wellness check" , ( ) => {
20+ it ( "test with short wellness timeout" , async ( ) => {
21+ let assertionCount = 0 ;
22+ let errored = false ;
23+ await run ( function * ( ) {
24+ yield * useService ( "test-service" , nodeScriptWorks , {
25+ wellnessCheck : {
26+ timeout : 2 ,
27+ * operation ( stdio ) {
28+ for ( let line of yield * each < string > ( stdio ) ) {
29+ console . log ( "wellness check got line:" , { line } ) ;
30+ if ( line . includes ( "test service started" ) ) {
31+ return Ok < void > ( void 0 ) ;
32+ }
33+ yield * each . next ( ) ;
2934 }
30- yield * each . next ( ) ;
31- }
32- return Err ( new Error ( "got sick of waiting" ) ) ;
35+ return Err ( new Error ( "got sick of waiting" ) ) ;
36+ } ,
3337 } ,
34- } ,
38+ } ) ;
39+ assertionCount ++ ;
40+ } ) . catch ( ( error ) => {
41+ assert . equal ( error . message , "service wellness check timed out" ) ;
42+ errored = true ;
43+ assertionCount ++ ;
3544 } ) ;
36- assertionCount ++ ;
45+ assert ( assertionCount > 0 ) ;
46+ assert ( errored ) ;
47+ } ) ;
48+
49+ it ( "test with long wellness timeout" , async ( ) => {
50+ let assertionCount = 0 ;
51+ await run ( function * ( ) {
52+ yield * useService ( "test-service" , nodeScriptWorks , {
53+ wellnessCheck : {
54+ timeout : 2000 ,
55+ * operation ( stdio ) {
56+ for ( let line of yield * each < string > ( stdio ) ) {
57+ console . log ( "wellness check got line:" , { line } ) ;
58+ if ( line . includes ( "test service started" ) ) {
59+ return Ok < void > ( void 0 ) ;
60+ }
61+ yield * each . next ( ) ;
62+ }
63+ return Err ( new Error ( "got sick of waiting" ) ) ;
64+ } ,
65+ } ,
66+ } ) ;
67+ assertionCount ++ ;
68+ } ) ;
69+ assert ( assertionCount > 0 ) ;
70+ } ) ;
71+
72+ it ( "test with mid-frequency wellness timeout" , async ( ) => {
73+ let assertionCount = 0 ;
74+ let errored = false ;
75+ await run ( function * ( ) {
76+ yield * useService ( "test-service" , nodeScriptWorks , {
77+ wellnessCheck : {
78+ timeout : 200 ,
79+ frequency : 100 ,
80+ * operation ( stdio ) {
81+ for ( let line of yield * each < string > ( stdio ) ) {
82+ console . log ( "wellness check got line:" , { line } ) ;
83+ if ( line . includes ( "test service started" ) ) {
84+ return Ok < void > ( void 0 ) ;
85+ }
86+ yield * each . next ( ) ;
87+ }
88+ return Err ( new Error ( "got sick of waiting" ) ) ;
89+ } ,
90+ } ,
91+ } ) ;
92+ assertionCount ++ ;
93+ } ) . catch ( ( error ) => {
94+ assert . equal ( error . message , "service wellness check timed out" ) ;
95+ errored = true ;
96+ assertionCount ++ ;
97+ } ) ;
98+ assert ( assertionCount > 0 ) ;
99+ assert ( errored ) ;
37100 } ) ;
38- assert ( assertionCount > 0 ) ;
39101} ) ;
0 commit comments