11package org .kohsuke .github .extras ;
22
3+ import com .github .tomakehurst .wiremock .core .WireMockConfiguration ;
4+ import com .github .tomakehurst .wiremock .extension .responsetemplating .ResponseTemplateTransformer ;
35import com .github .tomakehurst .wiremock .matching .RequestPatternBuilder ;
46import com .squareup .okhttp .OkUrlFactory ;
57import com .squareup .okhttp .Cache ;
@@ -65,6 +67,17 @@ public OkHttpConnectorTest() {
6567
6668 private GHRateLimit rateLimitBefore ;
6769
70+ @ Override
71+ protected WireMockConfiguration getWireMockOptions () {
72+ return super .getWireMockOptions ()
73+ .extensions (ResponseTemplateTransformer .builder ()
74+ .global (true )
75+ .maxCacheEntries (0L )
76+ .build ()
77+ //new ResponseTemplateTransformer(true)
78+ );
79+ }
80+
6881 @ Before
6982 public void setupRepo () throws Exception {
7083 if (githubApi .isUseProxy ()) {
@@ -118,16 +131,10 @@ public void OkHttpConnector_NoCache() throws Exception {
118131
119132 @ Test
120133 public void OkHttpConnector_Cache_MaxAgeNone () throws Exception {
121- // TODO: (bitiwseman) These tests work locally when proxying but run in to some kind of issue
122- // when running via snapshot. I think part of it is cache aging but there is also some
123- // other issue which I do not have the bandwidth to track down right now.
124- // For the moment, I'm committing this code as documentation of testing.
125-
126- // NOTE: Tried removing "Date" from mappings.
127- // That made MaxAgeNon pass but disabled max-age detection, so it is not a valid data.
128- // Likely need to dynamically construct mapping for these three tests
129- assumeFalse ("Test only valid when not taking a snapshot" , githubApi .isTakeSnapshot ());
130- assumeTrue ("Test only valid when proxying (-Dtest.github.useProxy to enable)" , githubApi .isUseProxy ());
134+ // The responses were recorded from github, but the Date headers
135+ // have been templated to make caching behavior work as expected.
136+ // This is reasonable as long as the number of network requests matches up.
137+ snapshotNotAllowed ();
131138
132139 OkHttpClient client = createClient (true );
133140 OkHttpConnector connector = new OkHttpConnector (new OkUrlFactory (client ), -1 );
@@ -155,14 +162,9 @@ public void OkHttpConnector_Cache_MaxAgeNone() throws Exception {
155162
156163 @ Test
157164 public void OkHttpConnector_Cache_MaxAge_Three () throws Exception {
158- // TODO: (bitiwseman) These tests work locally when proxying but run in to some kind of issue
159- // when running via snapshot. I think part of it is cache aging but there is also some
160- // other issue which I do not have the bandwidth to track down right now.
161- // For the moment, I'm committing this code as documentation of testing.
162-
163- // NOTE: Tried removing "Date" from mappings.
164- // That made MaxAgeNon pass but disabled max-age detection, so it is not a valid data.
165- // Likely need to dynamically construct mapping for these three tests
165+
166+ // NOTE: This test is very timing sensitive.
167+ // It can be run locally to verify behavior but snapshot data is to touchy
166168 assumeFalse ("Test only valid when not taking a snapshot" , githubApi .isTakeSnapshot ());
167169 assumeTrue ("Test only valid when proxying (-Dtest.github.useProxy to enable)" , githubApi .isUseProxy ());
168170
@@ -177,7 +179,7 @@ public void OkHttpConnector_Cache_MaxAge_Three() throws Exception {
177179
178180 doTestActions ();
179181
180- // Due to max-age=5 this eventually checks the site and gets updated information. Yay?
182+ // Due to max-age=3 this eventually checks the site and gets updated information. Yay?
181183 assertThat (getRepository (gitHub ).getDescription (), is ("Tricky" ));
182184
183185 checkRequestAndLimit (maxAgeThreeNetworkRequestCount , maxAgeThreeRateLimitUsed );
@@ -188,16 +190,10 @@ public void OkHttpConnector_Cache_MaxAge_Three() throws Exception {
188190
189191 @ Test
190192 public void OkHttpConnector_Cache_MaxAgeDefault_Zero () throws Exception {
191- // TODO: (bitiwseman) These tests work locally when proxying but run in to some kind of issue
192- // when running via snapshot. I think part of it is cache aging but there is also some
193- // other issue which I do not have the bandwidth to track down right now.
194- // For the moment, I'm committing this code as documentation of testing.
195-
196- // NOTE: Tried removing "Date" from mappings.
197- // That made MaxAgeNon pass but disabled max-age detection, so it is not a valid data.
198- // Likely need to dynamically construct mapping for these three tests
199- assumeFalse ("Test only valid when not taking a snapshot" , githubApi .isTakeSnapshot ());
200- assumeTrue ("Test only valid when proxying (-Dtest.github.useProxy to enable)" , githubApi .isUseProxy ());
193+ // The responses were recorded from github, but the Date headers
194+ // have been templated to make caching behavior work as expected.
195+ // This is reasonable as long as the number of network requests matches up.
196+ snapshotNotAllowed ();
201197
202198 OkHttpClient client = createClient (true );
203199 OkHttpConnector connector = new OkHttpConnector (new OkUrlFactory (client ));
0 commit comments