use of com.thoughtworks.go.util.ProcessManager in project gocd by gocd.
the class MaterialUpdateServiceTest method shouldUpdateServerHealthMessageWhenHung.
@Test
void shouldUpdateServerHealthMessageWhenHung() {
// given
service = spy(service);
systemEnvironment.set(SystemEnvironment.MATERIAL_UPDATE_INACTIVE_TIMEOUT, 1);
ProcessManager processManager = mock(ProcessManager.class);
Material material = mock(Material.class);
service.updateMaterial(material);
when(service.getProcessManager()).thenReturn(processManager);
when(material.getFingerprint()).thenReturn("fingerprint");
when(material.getUriForDisplay()).thenReturn("uri");
when(material.getLongDescription()).thenReturn("details to uniquely identify a material");
when(material.isAutoUpdate()).thenReturn(true);
when(processManager.getIdleTimeFor(new MaterialFingerprintTag("fingerprint"))).thenReturn(60010L);
// when
service.updateMaterial(material);
// then
verify(serverHealthService).removeByScope(HealthStateScope.forMaterialUpdate(material));
ArgumentCaptor<ServerHealthState> argumentCaptor = ArgumentCaptor.forClass(ServerHealthState.class);
verify(serverHealthService).update(argumentCaptor.capture());
assertThat(argumentCaptor.getValue().getMessage()).isEqualTo("Material update for uri hung:");
assertThat(argumentCaptor.getValue().getDescription()).isEqualTo("Material update is currently running but has not shown any activity in the last 1 minute(s). This may be hung. Details - details to uniquely identify a material");
assertThat(argumentCaptor.getValue().getType()).isEqualTo(HealthStateType.general(HealthStateScope.forMaterialUpdate(material)));
}
Aggregations