55import okhttp3 .OkHttpClient ;
66import okhttp3 .mockwebserver .MockResponse ;
77import okhttp3 .mockwebserver .MockWebServer ;
8+ import okhttp3 .mockwebserver .SocketPolicy ;
89import org .junit .jupiter .api .AfterEach ;
910import org .junit .jupiter .api .BeforeEach ;
1011import org .junit .jupiter .api .Test ;
@@ -86,7 +87,7 @@ public void fetchException() throws IOException, ExecutionException, Interrupted
8687 }
8788
8889 @ Test
89- public void fetchExceptionContainsCFRayIdIfPresented () throws IOException , ExecutionException , InterruptedException {
90+ public void fetchTimeOutExceptionContainsCFRayIdIfPresented () throws IOException , ExecutionException , InterruptedException {
9091
9192 ConfigFetcher fetch = new ConfigFetcher (new OkHttpClient .Builder ()
9293 .readTimeout (1 , TimeUnit .SECONDS )
@@ -103,6 +104,41 @@ public void fetchExceptionContainsCFRayIdIfPresented() throws IOException, Execu
103104 assertTrue (response .entry ().isEmpty ());
104105 assertTrue (response .entry ().getConfig ().isEmpty ());
105106
107+ assertTrue (response .error ().toString ().contains ("Request timed out while trying to fetch config JSON." ));
108+ assertTrue (response .error ().toString ().contains ("(Ray ID: 12345)" ));
109+ assertEquals ("12345" , response .cfRayId ());
110+
111+ fetch .close ();
112+ }
113+
114+ @ Test
115+ public void fetchUnexpectedErrorExceptionContainsCFRayIdIfPresented () throws IOException , ExecutionException , InterruptedException {
116+
117+ ConfigFetcher fetch = new ConfigFetcher (
118+ new OkHttpClient
119+ .Builder ()
120+ .readTimeout (1 , TimeUnit .SECONDS )
121+ .build (),
122+ logger ,
123+ "" ,
124+ this .server .url ("/" ).toString (),
125+ false ,
126+ PollingModes .manualPoll ().getPollingIdentifier ());
127+
128+ this .server .enqueue (
129+ new MockResponse ()
130+ .setResponseCode (200 )
131+ .setHeader ("CF-RAY" , "12345" )
132+ .setBody ("test" )
133+ .setSocketPolicy (SocketPolicy .DISCONNECT_DURING_RESPONSE_BODY ));
134+
135+ FetchResponse response = fetch .fetchAsync (null ).get ();
136+ assertTrue (response .isFailed ());
137+ assertTrue (response .entry ().isEmpty ());
138+ assertTrue (response .entry ().getConfig ().isEmpty ());
139+
140+ assertTrue (response .error ().toString ().contains ("Unexpected error occurred while trying to fetch config JSON." ));
141+ assertTrue (response .error ().toString ().contains ("(Ray ID: 12345)" ));
106142 assertEquals ("12345" , response .cfRayId ());
107143
108144 fetch .close ();
0 commit comments