@@ -64,10 +64,10 @@ public void OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error_runnable()
6464 OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error ();
6565 }
6666
67- @ Ignore ("The wiremock snapshot files attached to this test method show what was sent to and from the server during a run, but they aren't re-runnable - not templated." )
67+ // @Ignore("The wiremock snapshot files attached to this test method show what was sent to and from the server during a run, but they aren't re-runnable - not templated.")
6868 @ Test
6969 public void OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error () throws Exception {
70-
70+ // ISSUE #669
7171 // requireProxy("For clarity. Will switch to snapshot shortly.");
7272 // snapshotNotAllowed();
7373
@@ -149,164 +149,25 @@ public void OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error() throws Ex
149149 // or until the cache ages out entry without the URL being requeried (which is why users report that refreshing
150150 // is now help).
151151
152- // Work arounds:
153-
154152 try {
155153 repo .getRef (testRefName );
156154 } catch (GHFileNotFoundException e ) {
157155 // Sanity check: ref exists and can be queried from other client
158156 getRepository (gitHub2 ).getRef (testRefName );
159157
160158 // We're going to fail, query again to see the incorrect ETAG cached from first query being used
161- // It is the same ETAG as the one returned to the other client.
159+ // It is the same ETAG as the one returned to the second client.
162160 // Now we're in trouble.
163161 repo .getRef (testRefName );
164162
165- }
166- }
167-
168-
169- @ Ignore ("Keeping for reference. Simpler repro above." )
170- @ Test
171- public void OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubContents_Error () throws Exception {
172-
173- // requireProxy("For clarity. Will switch to snapshot shortly.");
174- // snapshotNotAllowed();
175-
176- OkHttpClient client = createClient (true );
177- OkHttpConnector connector = new OkHttpConnector (client );
178-
179- this .gitHub = getGitHubBuilder ().withEndpoint (mockGitHub .apiServer ().baseUrl ())
180- .withConnector (connector )
181- .build ();
182-
183- // Create a branch from a known conflicting branch
184- GHRepository repo = getRepository (gitHub );
185-
186- // Try to get a non-existant ref (GHFileNotFound)
187- try {
188- repo .getRef ("heads/test/content_ref_cache" );
189- fail ();
190- } catch (GHFileNotFoundException e ) {
191- // ignore
192- } catch (GHException e ) {
193- // ignore
194- }
195-
196- // Try to get the root directory contents for non-existant ref (GHFileNotFound)
197- try {
198- repo .getDirectoryContent ("/" , "refs/heads/test/content_ref_cache" );
163+ // We should never fail the first query and pass the second,
164+ // the test has still failed if it get here.
199165 fail ();
200- } catch (GHFileNotFoundException e ) {
201- // ignore
202- } catch (GHException e ) {
203- // ignore
204- }
205-
206- GHRef ref = repo .createRef ("refs/heads/test/content_ref_cache" ,
207- repo .getRef ("heads/test/unmergeable" ).getObject ().getSha ());
208-
209- // Wait a little to make sure there's some time between queries
210- Thread .sleep (5000 );
211-
212- // Verify we can query the created ref
213- repo .getRef ("heads/test/content_ref_cache" );
214-
215- // Sanity check: ref exists and can be queried from uncached connection
216- // if (mockGitHub.isUseProxy()) {
217- // getRepository(this.gitHubBeforeAfter).getDirectoryContent("/", ref.getRef());
218- // }
219-
220- // Verify ref exists and can be queried from uncached connection
221- // Expected: success
222- // Actual: still GHFileNotFound due to caching: GitHub incorrectly returns 304
223- // even though contents of the ref have changed.
224- try {
225- repo .getDirectoryContent ("/" , ref .getRef ());
226- } catch (GHFileNotFoundException e ) {
227- // Useful for breakpoint when debugging
228- throw e ;
229- } catch (GHException e ) {
230- // Useful for breakpoint when debugging
231- throw e ;
232- }
233-
234- }
235-
236- @ Ignore ("Keeping for reference. Simpler repro above." )
237- @ Test
238- public void OkHttpConnector_Cache_MaxAgeDefault_Zero_PRGitHubContents_Error () throws Exception {
239-
240- OkHttpClient client = createClient (true );
241- OkHttpConnector connector = new OkHttpConnector (client );
242-
243- this .gitHub = getGitHubBuilder ().withEndpoint (mockGitHub .apiServer ().baseUrl ())
244- .withConnector (connector )
245- .build ();
246-
247- if (mockGitHub .isUseProxy ()) {
248- for (GHPullRequest pr : getRepository (this .gitHubBeforeAfter ).getPullRequests (GHIssueState .OPEN )) {
249- pr .close ();
250- }
251- try {
252- GHRef ref = getRepository (this .gitHubBeforeAfter ).getRef ("heads/test/content_ref_cache" );
253- ref .delete ();
254- } catch (IOException e ) {
255- }
256- }
257-
258- // Create a branch from a known conflicting branch
259- GHRepository repo = getRepository (gitHub );
260-
261- GHRef ref = repo .createRef ("refs/heads/test/content_ref_cache" ,
262- repo .getRef ("heads/test/unmergeable" ).getObject ().getSha ());
263-
264- // Ensure ref exists and can be queried
265- repo .getDirectoryContent ("/" , ref .getRef ());
266-
267- // Create a PR from the created (unmergeable) branch
268- GHPullRequest pr = repo .createPullRequest ("Title" , ref .getRef (), "master" , "" );
269-
270- // Verify branch is unmergable state true
271- while (pr .getMergeable () == null ) {
272- Thread .sleep (500 );
273- }
274- assertThat (pr .getMergeable (), is (false ));
275-
276- String mergeRefName = "pull/" + Integer .toString (pr .getNumber ()) + "/merge" ;
277-
278- // Try to get the root directory contents for non-existant merge ref (GHFileNotFound)
279- try {
280- repo .getDirectoryContent ("/" , "refs/" + mergeRefName );
281- fail ();
282- } catch (GHFileNotFoundException e ) {
283- // ignore
284- } catch (GHException e ) {
285- // ignore
286- }
287-
288- // Make PR mergeable
289- ref .updateTo (repo .getRef ("heads/test/mergeable_branch" ).getObject ().getSha (), true );
290- pr .refresh ();
291- // Verify mergable state true
292- while (pr .getMergeable () == null ) {
293- Thread .sleep (500 );
294- }
295- assertThat (pr .getMergeable (), is (true ));
296-
297- // Verify we can get the root directory contents for merge ref
298- // Expected: success
299- // Actual: still GHFileNotFound due to caching - GitHub server error
300- try {
301- List <GHContent > files = repo .getDirectoryContent ("/" , "refs/" + mergeRefName );
302- } catch (GHFileNotFoundException e ) {
303- // Useful for breakpoint when debugging
304- throw e ;
305- } catch (GHException e ) {
306- // Useful for breakpoint when debugging
307- throw e ;
308166 }
309167
168+ // OMG, the workaround succeeded!
169+ // This correct response should be generated from a 304.
170+ repo .getRef (testRefName );
310171 }
311172
312173 private static int clientCount = 0 ;
@@ -316,7 +177,7 @@ private OkHttpClient createClient(boolean useCache) throws IOException {
316177
317178 if (useCache ) {
318179 File cacheDir = new File ("target/cache/" + baseFilesClassPath + "/" + mockGitHub .getMethodName ()
319- + Integer . toString ( clientCount ++) );
180+ + clientCount ++);
320181 cacheDir .mkdirs ();
321182 FileUtils .cleanDirectory (cacheDir );
322183 Cache cache = new Cache (cacheDir , 100 * 1024L * 1024L );
0 commit comments