@@ -6,7 +6,6 @@ import { describe, expect, it } from "@effect/vitest";
66import * as Duration from "effect/Duration" ;
77import * as Effect from "effect/Effect" ;
88import * as Layer from "effect/Layer" ;
9- import * as Option from "effect/Option" ;
109import * as Stream from "effect/Stream" ;
1110import * as TestClock from "effect/testing/TestClock" ;
1211import { HttpClient , HttpClientResponse } from "effect/http" ;
@@ -92,6 +91,7 @@ describe("ConnectReachability stale connector recovery", () => {
9291 it . effect ( "restarts cloudflared when Cloudflare has no connector but it reports ready" , ( ) =>
9392 Effect . gen ( function * ( ) {
9493 const restarted : Array < number > = [ ] ;
94+ let status = 530 ;
9595 const reachability = yield * Effect . service ( ConnectReachability . ConnectReachability ) . pipe (
9696 Effect . provide (
9797 ConnectReachability . layer . pipe (
@@ -103,14 +103,14 @@ describe("ConnectReachability stale connector recovery", () => {
103103 restartConnector : ( pid ) => Effect . sync ( ( ) => restarted . push ( pid ) > 0 ) ,
104104 } ) ,
105105 Layer . mock ( ServerSecretStore . ServerSecretStore ) ( {
106- get : ( ) => Effect . succeed ( Option . some ( new Uint8Array ( ) ) ) ,
106+ get : ( ) => Effect . succeedSome ( new Uint8Array ( ) ) ,
107107 } ) ,
108108 // Cloudflare answers 530 while cloudflared still reports four ready connections.
109109 Layer . succeed (
110110 HttpClient . HttpClient ,
111111 HttpClient . make ( ( request ) =>
112112 Effect . succeed (
113- HttpClientResponse . fromWeb ( request , new Response ( null , { status : 530 } ) ) ,
113+ HttpClientResponse . fromWeb ( request , new Response ( null , { status } ) ) ,
114114 ) ,
115115 ) ,
116116 ) ,
@@ -132,6 +132,28 @@ describe("ConnectReachability stale connector recovery", () => {
132132 yield * TestClock . adjust ( Duration . minutes ( 1 ) ) ;
133133 yield * reachability . check ;
134134 expect ( restarted ) . toEqual ( [ connected . pid ] ) ;
135+
136+ yield * reachability . check ;
137+ yield * TestClock . adjust ( Duration . minutes ( 2 ) ) ;
138+ yield * reachability . check ;
139+ expect ( restarted ) . toEqual ( [ connected . pid ] ) ;
140+ yield * TestClock . adjust ( Duration . minutes ( 2 ) ) ;
141+ yield * reachability . check ;
142+ expect ( restarted ) . toEqual ( [ connected . pid , connected . pid ] ) ;
143+
144+ status = 200 ;
145+ expect ( yield * reachability . check ) . toMatchObject ( { status : "reachable" } ) ;
146+ status = 502 ;
147+ yield * reachability . check ;
148+ yield * TestClock . adjust ( Duration . minutes ( 2 ) ) ;
149+ yield * reachability . check ;
150+ expect ( restarted ) . toHaveLength ( 2 ) ;
151+
152+ status = 530 ;
153+ yield * reachability . check ;
154+ yield * TestClock . adjust ( Duration . minutes ( 2 ) ) ;
155+ yield * reachability . check ;
156+ expect ( restarted ) . toEqual ( [ connected . pid , connected . pid , connected . pid ] ) ;
135157 } ) ,
136158 ) ;
137159} ) ;
0 commit comments