|
28 | 28 | import hudson.FilePath;
|
29 | 29 | import hudson.model.Job;
|
30 | 30 | import hudson.model.Result;
|
| 31 | +import hudson.model.queue.QueueTaskFuture; |
31 | 32 | import hudson.plugins.git.BranchSpec;
|
32 | 33 | import hudson.plugins.git.GitSCM;
|
33 | 34 | import hudson.plugins.git.SubmoduleConfig;
|
|
36 | 37 | import hudson.slaves.WorkspaceList;
|
37 | 38 | import hudson.scm.SubversionSCM;
|
38 | 39 | import hudson.scm.ChangeLogSet;
|
| 40 | + |
| 41 | +import java.time.ZonedDateTime; |
39 | 42 | import java.util.Collection;
|
40 | 43 | import java.util.Collections;
|
41 | 44 | import java.util.Iterator;
|
@@ -472,4 +475,41 @@ public void correctLibraryDirectoryUsedWhenResumingOldBuild() throws Exception {
|
472 | 475 | r.assertLogContains("called Foo", b);
|
473 | 476 | }
|
474 | 477 |
|
| 478 | + @Issue("JENKINS-66898") |
| 479 | + @Test |
| 480 | + public void parallelBuildsDontInterfereWithExpiredCache() throws Throwable { |
| 481 | + // Add a few files to the library so the deletion is not too fast |
| 482 | + // Before fixing JENKINS-66898 this test was failing almost always |
| 483 | + sampleRepo.init(); |
| 484 | + sampleRepo.write("vars/foo.groovy", "def call() { echo 'foo' }"); |
| 485 | + sampleRepo.write("vars/bar.groovy", "def call() { echo 'bar' }"); |
| 486 | + sampleRepo.write("vars/foo2.groovy", "def call() { echo 'foo2' }"); |
| 487 | + sampleRepo.write("vars/foo3.groovy", "def call() { echo 'foo3' }"); |
| 488 | + sampleRepo.write("vars/foo4.groovy", "def call() { echo 'foo4' }"); |
| 489 | + sampleRepo.git("add", "vars"); |
| 490 | + sampleRepo.git("commit", "--message=init"); |
| 491 | + LibraryConfiguration config = new LibraryConfiguration("library", |
| 492 | + new SCMSourceRetriever(new GitSCMSource(null, sampleRepo.toString(), "", "*", "", true))); |
| 493 | + config.setDefaultVersion("master"); |
| 494 | + config.setImplicit(true); |
| 495 | + config.setCachingConfiguration(new LibraryCachingConfiguration(30, null)); |
| 496 | + GlobalLibraries.get().getLibraries().add(config); |
| 497 | + WorkflowJob p1 = r.createProject(WorkflowJob.class); |
| 498 | + WorkflowJob p2 = r.createProject(WorkflowJob.class); |
| 499 | + p1.setDefinition(new CpsFlowDefinition("foo()", true)); |
| 500 | + p2.setDefinition(new CpsFlowDefinition("foo()", true)); |
| 501 | + WorkflowRun b1 = r.buildAndAssertSuccess(p1); |
| 502 | + LibrariesAction action = b1.getAction(LibrariesAction.class); |
| 503 | + LibraryRecord record = action.getLibraries().get(0); |
| 504 | + FilePath cache = LibraryCachingConfiguration.getGlobalLibrariesCacheDir().child(record.getDirectoryName()); |
| 505 | + //Expire the cache |
| 506 | + long oldMillis = ZonedDateTime.now().minusMinutes(35).toInstant().toEpochMilli(); |
| 507 | + cache.touch(oldMillis); |
| 508 | + QueueTaskFuture<WorkflowRun> f1 = p1.scheduleBuild2(0); |
| 509 | + QueueTaskFuture<WorkflowRun> f2 = p2.scheduleBuild2(0); |
| 510 | + WorkflowRun r1 = r.assertBuildStatus(Result.SUCCESS, f1); |
| 511 | + WorkflowRun r2 = r.assertBuildStatus(Result.SUCCESS, f2); |
| 512 | + r.assertLogContains("is due for a refresh after", r1); |
| 513 | + r.assertLogContains("Library library@master is cached. Copying from home.", r2); |
| 514 | + } |
475 | 515 | }
|
0 commit comments