Skip to content

Commit

Permalink
[plugin-email] Stabilize flaky unit tests (#2312)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikalinin1 authored Dec 22, 2021
1 parent ff5cf18 commit eb591ca
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ class ImapFetchServiceSystemTests
private static GreenMail mailServer;
private static GreenMailUser mailUser;

private final EmailFetchService service = new ImapFetchService(Duration.ofSeconds(30), 6, "INBOX",
new EmailMessageFactory());

@BeforeAll
static void initServer()
{
Expand Down Expand Up @@ -102,6 +99,7 @@ void cleanUp() throws FolderException
})
void testFetch(long deliveryDelay, long testTimeout) throws MessagingException
{
ImapFetchService service = serviceWith(90, 15);
String subject = GreenMailUtil.random();
FailablePredicate<Message, MessagingException> subjectPredicate = EmailParameterFilterFactory.SUBJECT
.createFilter(ComparisonRule.EQUAL_TO.name(), subject);
Expand Down Expand Up @@ -136,6 +134,7 @@ void testFetchNoEmailReceived()
.createFilter(ComparisonRule.EQUAL_TO.name(), subject);

List<EmailMessage> receivedMessages = new ArrayList<>();
ImapFetchService service = serviceWith(5, 1);
assertTimeout(Duration.ofMinutes(1),
() -> receivedMessages.addAll(service.fetch(List.of(subjectPredicate), getConfig())));

Expand All @@ -151,6 +150,11 @@ private static EmailServerConfiguration getConfig()
));
}

private ImapFetchService serviceWith(int waitTimeout, int retries)
{
return new ImapFetchService(Duration.ofSeconds(waitTimeout), retries, "INBOX", new EmailMessageFactory());
}

private static void scheduleSendEmail(long deliveryDelay, String subject)
{
try
Expand Down

0 comments on commit eb591ca

Please sign in to comment.