Skip to content

Commit

Permalink
Merge pull request #5339 from pkriens/master
Browse files Browse the repository at this point in the history
[cached resolve] The test failed on Windows
  • Loading branch information
pkriens committed Aug 17, 2022
2 parents 1f860ab + de785cd commit b133d60
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 16 deletions.
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

0 comments on commit b133d60

Please sign in to comment.