From de785cdb5d64c703dcefd8671980336cb124a7b8 Mon Sep 17 00:00:00 2001 From: Peter Kriens Date: Wed, 17 Aug 2022 11:02:01 +0200 Subject: [PATCH] [cached resolve] The test failed on Windows I think this was caused by faster window machines. The reason for the operation was USE_CACHE which can only happen if the bndrun file did not pick up the time of the included file. I've added a 100 ms delay before taking a time, this 100 ms should be more than the resolution of the file system. So setting the time on the included file was not seen as later than the project file. I also added checks to see what the cache reason is before we call getRunBundles(). Lets see what happens Signed-off-by: Peter Kriens --- .../src/biz/aQute/resolve/Bndrun.java | 31 +++++++++++-------- .../biz/aQute/resolve/RunResolutionTest.java | 24 ++++++++++++-- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/biz.aQute.resolve/src/biz/aQute/resolve/Bndrun.java b/biz.aQute.resolve/src/biz/aQute/resolve/Bndrun.java index 2e29cca56f..cfb2225fc2 100644 --- a/biz.aQute.resolve/src/biz/aQute/resolve/Bndrun.java +++ b/biz.aQute.resolve/src/biz/aQute/resolve/Bndrun.java @@ -212,19 +212,7 @@ private Collection 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; @@ -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 diff --git a/biz.aQute.resolve/test/biz/aQute/resolve/RunResolutionTest.java b/biz.aQute.resolve/test/biz/aQute/resolve/RunResolutionTest.java index 919ee35ae1..f5efbac370 100644 --- a/biz.aQute.resolve/test/biz/aQute/resolve/RunResolutionTest.java +++ b/biz.aQute.resolve/test/biz/aQute/resolve/RunResolutionTest.java @@ -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 { @@ -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); @@ -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); @@ -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; } }