Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cached resolve] The test failed on Windows #5339

Merged
merged 1 commit into from Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 18 additions & 13 deletions biz.aQute.resolve/src/biz/aQute/resolve/Bndrun.java
Expand Up @@ -212,19 +212,7 @@ private Collection<Container> cache() throws Exception {
File ours = getPropertiesFile();
File cache = getCacheFile(ours);

long cacheLastModified = cache.lastModified();

CacheReason reason;
if (ws.getLayout() != WorkspaceLayout.BND)
reason = CacheReason.NOT_A_BND_LAYOUT;
else if (!cache.isFile())
reason = CacheReason.NO_CACHE_FILE;
else if (cacheLastModified < ws.lastModified())
reason = CacheReason.CACHE_STALE_WORKSPACE;
else if (cacheLastModified < lastModified())
reason = CacheReason.CACHE_STALE_PROJECT;
else
reason = CacheReason.USE_CACHE;
CacheReason reason = getCacheReason(cache);

testReason = reason;

Expand Down Expand Up @@ -273,6 +261,23 @@ else if (cacheLastModified < lastModified())
}
}

CacheReason getCacheReason(File cached) {
long cacheLastModified = cached.lastModified();

CacheReason reason;
if (getWorkspace().getLayout() != WorkspaceLayout.BND)
reason = CacheReason.NOT_A_BND_LAYOUT;
else if (!cached.isFile())
reason = CacheReason.NO_CACHE_FILE;
else if (cacheLastModified < getWorkspace().lastModified())
reason = CacheReason.CACHE_STALE_WORKSPACE;
else if (cacheLastModified < lastModified())
reason = CacheReason.CACHE_STALE_PROJECT;
else
reason = CacheReason.USE_CACHE;
return reason;
}


/**
* Return the file used to cache the resolved solution for the given file
Expand Down
24 changes: 21 additions & 3 deletions biz.aQute.resolve/test/biz/aQute/resolve/RunResolutionTest.java
Expand Up @@ -138,6 +138,7 @@ public void testResolveCached() throws Exception {
assertTrue(bndrun.check());
File cache = bndrun.getCacheFile(file);
File build = IO.getFile(ws.toFile(), "cnf/build.bnd");
File empty = IO.getFile(ws.toFile(), "test.simple/empty-included-in-resolve.bnd");

try {

Expand Down Expand Up @@ -190,16 +191,25 @@ public void testResolveCached() throws Exception {
assertThat(cached).isEmpty();
assertThat(bndrun.testReason).isEqualTo(CacheReason.USE_CACHE);

System.out.println("Make sure modified time granularity is < then passed time");
Thread.sleep(100);

System.out.println("Update an include file, refresh and check we still use the cache");
File empty = IO.getFile(ws.toFile(), "test.simple/empty-included-in-resolve.bnd");
long now = System.currentTimeMillis();
empty.setLastModified(now);
assertThat(bndrun.lastModified()).isLessThanOrEqualTo(now);
assertThat(cache.lastModified()).isLessThanOrEqualTo(now);
now = empty.lastModified();

assertThat(bndrun.getCacheReason(cache)).isEqualTo(CacheReason.USE_CACHE);

assertThat(bndrun.lastModified()).isLessThan(now);
assertThat(cache.lastModified()).isLessThan(now);
assertTrue(bndrun.refresh());
bndrun.setProperty("-resolve", "cache");
bndrun.unsetProperty("-runbundles");
assertThat(bndrun.getCacheReason(cache)).isEqualTo(CacheReason.CACHE_STALE_PROJECT);
assertThat(bndrun.lastModified()).isGreaterThanOrEqualTo(now);
bndrun.setPedantic(true);
bndrun.setTrace(true);
cached = bndrun.getRunbundles();
assertTrue(bndrun.check());
assertThat(cached).containsExactlyElementsOf(manual);
Expand All @@ -212,10 +222,17 @@ public void testResolveCached() throws Exception {
assertThat(cached).containsExactlyElementsOf(manual);
assertThat(bndrun.testReason).isEqualTo(CacheReason.USE_CACHE);

System.out.println("Make sure modified time granularity is < then passed time");
Thread.sleep(100);

System.out.println("Update the cnf/build file");
now = System.currentTimeMillis();
build.setLastModified(now);
now = build.lastModified();

System.out.println("Refresh the workspace");
assertTrue(workspace.refresh());
assertThat(bndrun.getCacheReason(cache)).isEqualTo(CacheReason.CACHE_STALE_WORKSPACE);
cached = bndrun.getRunbundles();
assertThat(bndrun.testReason).isEqualTo(CacheReason.CACHE_STALE_WORKSPACE);

Expand All @@ -229,6 +246,7 @@ public void testResolveCached() throws Exception {
System.out.println("cache = " + cache.lastModified());
System.out.println("workspace = " + workspace.lastModified());
System.out.println("build = " + build.lastModified());
System.out.println("empty = " + empty.lastModified());
throw e;
}
}
Expand Down