From f75b9e139231535737c962545f81b76881feb0a7 Mon Sep 17 00:00:00 2001 From: Enrico Del Fante Date: Wed, 23 Oct 2024 12:41:20 +0200 Subject: [PATCH] update "no active outbound stream" message update tests --- .../eth2/gossip/GossipFailureLogger.java | 4 +- .../eth2/gossip/GossipFailureLoggerTest.java | 42 +++++++++++++------ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/gossip/GossipFailureLogger.java b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/gossip/GossipFailureLogger.java index 5da65069875..d266f19f26a 100644 --- a/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/gossip/GossipFailureLogger.java +++ b/networking/eth2/src/main/java/tech/pegasys/teku/networking/eth2/gossip/GossipFailureLogger.java @@ -50,14 +50,14 @@ public synchronized void logWithSuppression(final Throwable error, final UInt64 } else if (lastRootCause instanceof NoPeersForOutboundMessageException) { LOG.log( suppress ? Level.DEBUG : Level.WARN, - "Failed to publish {}(s) for slot {}; {}", + "Failed to publish {}(s) for slot {}: {}", messageType, lastErroredSlot, rootCause.getMessage()); } else if (lastRootCause instanceof SemiDuplexNoOutboundStreamException) { LOG.log( suppress ? Level.DEBUG : Level.WARN, - "Failed to publish {}(s) for slot {} because no peers were available on the required gossip topic", + "Failed to publish {}(s) for slot {} because no active outbound stream for the required gossip topic", messageType, lastErroredSlot); } else { diff --git a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/gossip/GossipFailureLoggerTest.java b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/gossip/GossipFailureLoggerTest.java index a5b83d565fb..24d97e96449 100644 --- a/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/gossip/GossipFailureLoggerTest.java +++ b/networking/eth2/src/test/java/tech/pegasys/teku/networking/eth2/gossip/GossipFailureLoggerTest.java @@ -15,6 +15,7 @@ import io.libp2p.core.SemiDuplexNoOutboundStreamException; import io.libp2p.pubsub.MessageAlreadySeenException; +import io.libp2p.pubsub.NoPeersForOutboundMessageException; import org.junit.jupiter.api.Test; import tech.pegasys.infrastructure.logging.LogCaptor; import tech.pegasys.teku.infrastructure.unsigned.UInt64; @@ -24,7 +25,12 @@ class GossipFailureLoggerTest { public static final String ALREADY_SEEN_MESSAGE = "Failed to publish thingy(s) for slot 1 because the message has already been seen"; public static final UInt64 SLOT = UInt64.ONE; + public static final SemiDuplexNoOutboundStreamException NO_ACTIVE_STREAM_EXCEPTION = + new SemiDuplexNoOutboundStreamException("So Lonely"); + public static final NoPeersForOutboundMessageException NO_PEERS_FOR_OUTBOUND_MESSAGE_EXCEPTION = + new NoPeersForOutboundMessageException("no peers"); public static final String NO_PEERS_MESSAGE = noPeersMessage(SLOT.intValue()); + public static final String NO_ACTIVE_STREAM_MESSAGE = noActiveStreamMessage(SLOT.intValue()); public static final String GENERIC_FAILURE_MESSAGE = "Failed to publish thingy(s) for slot 1"; @@ -43,22 +49,28 @@ void shouldLogAlreadySeenErrorsAtDebugLevel() { void shouldLogFirstNoPeersErrorsAtWarningLevel() { try (final LogCaptor logCaptor = LogCaptor.forClass(GossipFailureLogger.class)) { logger.logWithSuppression( - new RuntimeException("Foo", new SemiDuplexNoOutboundStreamException("So Lonely")), SLOT); + new RuntimeException("Foo", NO_PEERS_FOR_OUTBOUND_MESSAGE_EXCEPTION), SLOT); logCaptor.assertWarnLog(NO_PEERS_MESSAGE); } } + @Test + void shouldLogFirstNoActiveStreamErrorsAtWarningLevel() { + try (final LogCaptor logCaptor = LogCaptor.forClass(GossipFailureLogger.class)) { + logger.logWithSuppression(new RuntimeException("Foo", NO_ACTIVE_STREAM_EXCEPTION), SLOT); + logCaptor.assertWarnLog(NO_ACTIVE_STREAM_MESSAGE); + } + } + @Test void shouldLogRepeatedNoPeersErrorsAtDebugLevel() { try (final LogCaptor logCaptor = LogCaptor.forClass(GossipFailureLogger.class)) { logger.logWithSuppression( - new RuntimeException("Foo", new SemiDuplexNoOutboundStreamException("So Lonely")), SLOT); + new RuntimeException("Foo", NO_PEERS_FOR_OUTBOUND_MESSAGE_EXCEPTION), SLOT); logCaptor.clearLogs(); logger.logWithSuppression( - new IllegalStateException( - "Foo", new SemiDuplexNoOutboundStreamException("Not a friend in the world")), - SLOT); + new IllegalStateException("Foo", NO_PEERS_FOR_OUTBOUND_MESSAGE_EXCEPTION), SLOT); logCaptor.assertDebugLog(NO_PEERS_MESSAGE); } } @@ -67,12 +79,11 @@ void shouldLogRepeatedNoPeersErrorsAtDebugLevel() { void shouldLogNoPeersErrorsWithDifferentSlotsAtWarnLevel() { try (final LogCaptor logCaptor = LogCaptor.forClass(GossipFailureLogger.class)) { logger.logWithSuppression( - new RuntimeException("Foo", new SemiDuplexNoOutboundStreamException("So Lonely")), SLOT); + new RuntimeException("Foo", NO_PEERS_FOR_OUTBOUND_MESSAGE_EXCEPTION), SLOT); logCaptor.assertWarnLog(NO_PEERS_MESSAGE); logger.logWithSuppression( - new IllegalStateException( - "Foo", new SemiDuplexNoOutboundStreamException("Not a friend in the world")), + new IllegalStateException("Foo", NO_PEERS_FOR_OUTBOUND_MESSAGE_EXCEPTION), UInt64.valueOf(2)); logCaptor.assertWarnLog(noPeersMessage(2)); } @@ -82,16 +93,14 @@ void shouldLogNoPeersErrorsWithDifferentSlotsAtWarnLevel() { void shouldLogNoPeersErrorsAtWarnLevelWhenSeparatedByADifferentException() { try (final LogCaptor logCaptor = LogCaptor.forClass(GossipFailureLogger.class)) { logger.logWithSuppression( - new RuntimeException("Foo", new SemiDuplexNoOutboundStreamException("So Lonely")), SLOT); + new RuntimeException("Foo", NO_PEERS_FOR_OUTBOUND_MESSAGE_EXCEPTION), SLOT); logCaptor.assertWarnLog(NO_PEERS_MESSAGE); logCaptor.clearLogs(); logger.logWithSuppression(new MessageAlreadySeenException("Dupe"), SLOT); logger.logWithSuppression( - new IllegalStateException( - "Foo", new SemiDuplexNoOutboundStreamException("Not a friend in the world")), - SLOT); + new IllegalStateException("Foo", NO_PEERS_FOR_OUTBOUND_MESSAGE_EXCEPTION), SLOT); logCaptor.assertWarnLog(NO_PEERS_MESSAGE); } } @@ -136,6 +145,13 @@ void shouldLogMultipleGenericErrorsWithDifferentCausesAtErrorLevel() { private static String noPeersMessage(final int slot) { return "Failed to publish thingy(s) for slot " + slot - + " because no peers were available on the required gossip topic"; + + ": " + + NO_PEERS_FOR_OUTBOUND_MESSAGE_EXCEPTION.getMessage(); + } + + private static String noActiveStreamMessage(final int slot) { + return "Failed to publish thingy(s) for slot " + + slot + + " because no active outbound stream for the required gossip topic"; } }