|
19 | 19 | import static org.mockito.Mockito.mock; |
20 | 20 | import static org.mockito.Mockito.never; |
21 | 21 | import static org.mockito.Mockito.verify; |
| 22 | +import static org.mockito.Mockito.verifyNoInteractions; |
22 | 23 | import static org.mockito.Mockito.when; |
23 | 24 | import static tech.pegasys.teku.validator.coordinator.performance.DefaultPerformanceTracker.ATTESTATION_INCLUSION_RANGE; |
24 | 25 |
|
25 | 26 | import java.util.List; |
26 | 27 | import org.junit.jupiter.api.BeforeEach; |
27 | 28 | import org.junit.jupiter.api.Test; |
| 29 | +import tech.pegasys.infrastructure.logging.LogCaptor; |
28 | 30 | import tech.pegasys.teku.bls.BLSKeyGenerator; |
29 | 31 | import tech.pegasys.teku.bls.BLSKeyPair; |
30 | 32 | import tech.pegasys.teku.bls.BLSTestUtil; |
@@ -362,6 +364,41 @@ void shouldReportSyncCommitteePerformance() { |
362 | 364 | verify(validatorPerformanceMetrics).updateSyncCommitteePerformance(performance); |
363 | 365 | } |
364 | 366 |
|
| 367 | + @Test |
| 368 | + void shouldHandleErrorsWhenReportTasksFail() { |
| 369 | + chainUpdater.updateBestBlock(chainUpdater.advanceChainUntil(1)); |
| 370 | + final Attestation attestation = createAttestationForParentBlockOnSlot(1); |
| 371 | + final UInt64 slot = spec.computeStartSlotAtEpoch(ATTESTATION_INCLUSION_RANGE); |
| 372 | + |
| 373 | + performanceTracker.saveProducedAttestation(attestation); |
| 374 | + when(validatorTracker.getNumberOfValidatorsForEpoch(any())).thenThrow(new RuntimeException()); |
| 375 | + |
| 376 | + try (LogCaptor logCaptor = LogCaptor.forClass(DefaultPerformanceTracker.class)) { |
| 377 | + performanceTracker.onSlot(slot); |
| 378 | + |
| 379 | + // No attestation performance report on status logger because task failed |
| 380 | + verifyNoInteractions(log); |
| 381 | + assertThat(logCaptor.getErrorLogs()).hasSize(1); |
| 382 | + } |
| 383 | + } |
| 384 | + |
| 385 | + /** |
| 386 | + * Creates an attestation voting for block on the slot provided. The attestation will be included |
| 387 | + * in block slot + 1. |
| 388 | + * |
| 389 | + * @param slot the slot of the block being attested |
| 390 | + * @return the created attestation |
| 391 | + */ |
| 392 | + private Attestation createAttestationForParentBlockOnSlot(int slot) { |
| 393 | + Attestation attestationForBlock1 = createAttestation(slot + 1, slot); |
| 394 | + ChainBuilder.BlockOptions block2Options = ChainBuilder.BlockOptions.create(); |
| 395 | + block2Options.addAttestation(attestationForBlock1); |
| 396 | + SignedBlockAndState latestBlockAndState = chainBuilder.generateBlockAtSlot(2, block2Options); |
| 397 | + chainUpdater.saveBlock(latestBlockAndState); |
| 398 | + chainUpdater.updateBestBlock(latestBlockAndState); |
| 399 | + return attestationForBlock1; |
| 400 | + } |
| 401 | + |
365 | 402 | private Attestation createAttestation( |
366 | 403 | ChainBuilder chainBuilder, int validForBlockAtSlot, int vouchingForBlockAtSlot) { |
367 | 404 | return chainBuilder |
|
0 commit comments