Skip to content

Commit

Permalink
update "no active outbound stream" message
Browse files Browse the repository at this point in the history
update tests
  • Loading branch information
tbenr committed Oct 23, 2024
1 parent 61b25de commit f75b9e1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";

Expand All @@ -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);
}
}
Expand All @@ -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));
}
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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";
}
}

0 comments on commit f75b9e1

Please sign in to comment.