/** * Persists the current state of {@link CpsThreadGroup}. */ @CpsVmThreadOnly void saveProgram() throws IOException { File f = execution.getProgramDataFile(); saveProgram(f); }
loadProgramAsync(getProgramDataFile()); } else {
Util.deleteFile(execution.getProgramDataFile()); } catch (IOException x) { LOGGER.log(Level.WARNING, "Failed to delete program.dat in " + execution, x);
@Test public void loaderReleased() throws Exception { WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p"); r.jenkins.getWorkspaceFor(p).child("lib.groovy").write(CpsFlowExecutionMemoryTest.class.getName() + ".register(this)", null); p.setDefinition(new CpsFlowDefinition(CpsFlowExecutionMemoryTest.class.getName() + ".register(this); node {load 'lib.groovy'; evaluate(readFile('lib.groovy'))}", false)); WorkflowRun b = r.assertBuildStatusSuccess(p.scheduleBuild2(0)); assertFalse(((CpsFlowExecution) b.getExecution()).getProgramDataFile().exists()); assertFalse(LOADERS.isEmpty()); { // TODO it seems that the call to CpsFlowExecutionMemoryTest.register(Object) on a Script1 parameter creates a MetaMethodIndex.Entry.cachedStaticMethod. // In other words any call to a foundational API might leak classes. Why does Groovy need to do this? // Unclear whether this is a problem in a realistic environment; for the moment, suppressing it so the test can run with no SoftReference. MetaClass metaClass = ClassInfo.getClassInfo(CpsFlowExecutionMemoryTest.class).getMetaClass(); Method clearInvocationCaches = metaClass.getClass().getDeclaredMethod("clearInvocationCaches"); clearInvocationCaches.setAccessible(true); clearInvocationCaches.invoke(metaClass); } for (WeakReference<ClassLoader> loaderRef : LOADERS) { MemoryAssert.assertGC(loaderRef, false); } }
@Test /** Build okay but program fails to load */ public void inProgressButProgramLoadFailure() throws Exception { final int[] build = new int[1]; story.thenWithHardShutdown( j -> { WorkflowRun run = runBasicPauseOnInput(j, DEFAULT_JOBNAME, build); CpsFlowExecution cpsExec = (CpsFlowExecution)(run.getExecution()); cpsExec.getProgramDataFile().delete(); }); story.then( j->{ WorkflowJob r = j.jenkins.getItemByFullName(DEFAULT_JOBNAME, WorkflowJob.class); WorkflowRun run = r.getBuildByNumber(build[0]); assertCompletedCleanly(run); }); }