Skip to content

Commit f3b2fdc

Browse files
committed
Update test and resources using new workaround
1 parent 16d34f3 commit f3b2fdc

30 files changed

Lines changed: 253 additions & 789 deletions

File tree

src/test/java/org/kohsuke/github/extras/okhttp3/GitHubCachingTest.java

Lines changed: 9 additions & 148 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

src/test/java/org/kohsuke/github/junit/GitHubWireMockRule.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ protected void after() {
115115
.snapshotRecord(recordSpec().forTarget("https://api.github.com")
116116
.captureHeader("If-None-Match")
117117
.captureHeader("If-Modified-Since")
118+
.captureHeader("Cache-Control")
118119
.captureHeader("Accept")
119120
.extractTextBodiesOver(255));
120121

@@ -126,6 +127,7 @@ protected void after() {
126127
.snapshotRecord(recordSpec().forTarget("https://raw.githubusercontent.com")
127128
.captureHeader("If-None-Match")
128129
.captureHeader("If-Modified-Since")
130+
.captureHeader("Cache-Control")
129131
.captureHeader("Accept")
130132
.extractTextBodiesOver(255));
131133

@@ -138,6 +140,7 @@ protected void after() {
138140
.snapshotRecord(recordSpec().forTarget("https://uploads.github.com")
139141
.captureHeader("If-None-Match")
140142
.captureHeader("If-Modified-Since")
143+
.captureHeader("Cache-Control")
141144
.captureHeader("Accept")
142145
.extractTextBodiesOver(255));
143146

src/test/resources/org/kohsuke/github/extras/okhttp3/GitHubCachingTest/wiremock/OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error/__files/orgs_github-api-test-org-50896d2e-4cd0-4abd-a6bd-f68d2b50bea2.json renamed to src/test/resources/org/kohsuke/github/extras/okhttp3/GitHubCachingTest/wiremock/OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error/__files/orgs_github-api-test-org-18671a38-8d77-4242-9519-3503350cf496.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"is_verified": false,
1515
"has_organization_projects": true,
1616
"has_repository_projects": true,
17-
"public_repos": 10,
17+
"public_repos": 11,
1818
"public_gists": 0,
1919
"followers": 0,
2020
"following": 0,

src/test/resources/org/kohsuke/github/extras/okhttp3/GitHubCachingTest/wiremock/OkHttpConnector_Cache_MaxAgeDefault_Zero_GitHubRef_Error/__files/orgs_github-api-test-org-762c3914-8a53-4a5e-b45a-ff346c0eeaa4.json

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)