generated from salesforce/oss-template
-
Notifications
You must be signed in to change notification settings - Fork 11
test: remove timeouts for pubsub test run #203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Yaminik1996
wants to merge
3
commits into
salesforce:main
from
Yaminik1996:W-20494137/pubsubFlakyTest
Closed
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ | |
| import com.salesforce.multicloudj.pubsub.driver.AbstractTopic; | ||
| import com.salesforce.multicloudj.pubsub.driver.Message; | ||
| import com.salesforce.multicloudj.pubsub.driver.AckID; | ||
| import com.salesforce.multicloudj.pubsub.client.GetAttributeResult; | ||
| import com.salesforce.multicloudj.common.util.common.TestsUtil; | ||
| import com.salesforce.multicloudj.common.exceptions.InvalidArgumentException; | ||
|
|
||
|
|
@@ -17,12 +16,10 @@ | |
| import org.junit.jupiter.api.Disabled; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.TestInstance; | ||
| import org.junit.jupiter.api.Timeout; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| @TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
| public abstract class AbstractPubsubIT { | ||
|
|
@@ -109,7 +106,6 @@ public void testSendBatchMessages() throws Exception { | |
| } | ||
|
|
||
| @Test | ||
| @Timeout(30) // Integration test that calls receive() - fail fast if recordings are missing | ||
| public void testReceiveAfterSend() throws Exception { | ||
| try (AbstractTopic topic = harness.createTopicDriver(); | ||
| AbstractSubscription subscription = harness.createSubscriptionDriver()) { | ||
|
|
@@ -120,14 +116,7 @@ public void testReceiveAfterSend() throws Exception { | |
| .build(); | ||
| topic.send(toSend); | ||
|
|
||
| Message received = null; | ||
| for (int i = 0; i < 50; i++) { | ||
| received = subscription.receive(); | ||
| if (received != null) { | ||
| break; | ||
| } | ||
| TimeUnit.MILLISECONDS.sleep(200); | ||
| } | ||
| Message received = subscription.receive(); | ||
|
|
||
| Assertions.assertNotNull(received, "Should receive a message within timeout"); | ||
| Assertions.assertNotNull(received.getBody(), "Received message body should not be null"); | ||
|
|
@@ -136,7 +125,6 @@ public void testReceiveAfterSend() throws Exception { | |
| } | ||
|
|
||
| @Test | ||
| @Timeout(30) // Integration test that calls receive() - fail fast if recordings are missing | ||
| public void testAckAfterReceive() throws Exception { | ||
| try (AbstractTopic topic = harness.createTopicDriver(); | ||
| AbstractSubscription subscription = harness.createSubscriptionDriver()) { | ||
|
|
@@ -147,12 +135,7 @@ public void testAckAfterReceive() throws Exception { | |
| .build(); | ||
| topic.send(toSend); | ||
|
|
||
| Message received = null; | ||
| for (int i = 0; i < 50; i++) { | ||
| received = subscription.receive(); | ||
| if (received != null) break; | ||
| TimeUnit.MILLISECONDS.sleep(200); | ||
| } | ||
| Message received = subscription.receive(); | ||
|
|
||
| Assertions.assertNotNull(received, "Should receive a message to ack"); | ||
| Assertions.assertNotNull(received.getAckID(), "AckID must not be null"); | ||
|
|
@@ -162,7 +145,6 @@ public void testAckAfterReceive() throws Exception { | |
| } | ||
|
|
||
| @Test | ||
| @Timeout(30) // Integration test that calls receive() - fail fast if recordings are missing | ||
| public void testNackAfterReceive() throws Exception { | ||
| try (AbstractTopic topic = harness.createTopicDriver(); | ||
| AbstractSubscription subscription = harness.createSubscriptionDriver()) { | ||
|
|
@@ -173,12 +155,7 @@ public void testNackAfterReceive() throws Exception { | |
| .build(); | ||
| topic.send(toSend); | ||
|
|
||
| Message received = null; | ||
| for (int i = 0; i < 50; i++) { | ||
| received = subscription.receive(); | ||
| if (received != null) break; | ||
| TimeUnit.MILLISECONDS.sleep(200); | ||
| } | ||
| Message received = subscription.receive(); | ||
|
|
||
| Assertions.assertNotNull(received, "Should receive a message to nack"); | ||
| Assertions.assertNotNull(received.getAckID(), "AckID must not be null"); | ||
|
|
@@ -199,29 +176,12 @@ public void testBatchAck() throws Exception { | |
| ); | ||
| for (Message m : toSend) topic.send(m); | ||
|
|
||
| TimeUnit.MILLISECONDS.sleep(500); | ||
|
|
||
| List<AckID> ackIDs = new java.util.ArrayList<>(); | ||
| boolean isRecording = System.getProperty("record") != null; | ||
| long timeoutSeconds = isRecording ? 120 : 60; // Increased timeout for integration tests | ||
| long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(timeoutSeconds); | ||
|
|
||
| System.out.println("Starting to collect " + toSend.size() + " messages with timeout: " + timeoutSeconds + "s"); | ||
|
|
||
| while (ackIDs.size() < toSend.size() && System.nanoTime() < deadline) { | ||
| try { | ||
| Message r = subscription.receive(); | ||
| if (r != null && r.getAckID() != null) { | ||
| ackIDs.add(r.getAckID()); | ||
| System.out.println("Received message " + ackIDs.size() + "/" + toSend.size() + | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| " with AckID: " + r.getAckID()); | ||
| } else { | ||
| System.out.println("Received null message, waiting..."); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| TimeUnit.MILLISECONDS.sleep(100); | ||
| } | ||
| } catch (Exception e) { | ||
| System.err.println("Error receiving message: " + e.getMessage()); | ||
| TimeUnit.MILLISECONDS.sleep(100); | ||
|
|
||
| while (ackIDs.size() < toSend.size()) { | ||
| Message r = subscription.receive(); | ||
| if (r != null && r.getAckID() != null) { | ||
| ackIDs.add(r.getAckID()); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -232,7 +192,6 @@ public void testBatchAck() throws Exception { | |
| } | ||
|
|
||
| @Test | ||
| @Timeout(120) // Integration test with batch operations - allow time for message delivery | ||
| public void testBatchNack() throws Exception { | ||
| try (AbstractTopic topic = harness.createTopicDriver(); | ||
| AbstractSubscription subscription = harness.createSubscriptionDriver()) { | ||
|
|
@@ -244,29 +203,12 @@ public void testBatchNack() throws Exception { | |
| ); | ||
| for (Message m : toSend) topic.send(m); | ||
|
|
||
| TimeUnit.MILLISECONDS.sleep(500); | ||
|
|
||
| List<AckID> ackIDs = new java.util.ArrayList<>(); | ||
| boolean isRecording = System.getProperty("record") != null; | ||
| long timeoutSeconds = isRecording ? 120 : 60; // Increased timeout for integration tests | ||
| long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(timeoutSeconds); | ||
|
|
||
| System.out.println("Starting to collect " + toSend.size() + " messages with timeout: " + timeoutSeconds + "s"); | ||
|
|
||
| while (ackIDs.size() < toSend.size() && System.nanoTime() < deadline) { | ||
| try { | ||
| Message r = subscription.receive(); | ||
| if (r != null && r.getAckID() != null) { | ||
| ackIDs.add(r.getAckID()); | ||
| System.out.println("Received message " + ackIDs.size() + "/" + toSend.size() + | ||
| " with AckID: " + r.getAckID()); | ||
| } else { | ||
| System.out.println("Received null message, waiting..."); | ||
| TimeUnit.MILLISECONDS.sleep(100); | ||
| } | ||
| } catch (Exception e) { | ||
| System.err.println("Error receiving message: " + e.getMessage()); | ||
| TimeUnit.MILLISECONDS.sleep(100); | ||
|
|
||
| while (ackIDs.size() < toSend.size()) { | ||
| Message r = subscription.receive(); | ||
| if (r != null && r.getAckID() != null) { | ||
| ackIDs.add(r.getAckID()); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -300,14 +242,11 @@ public void testDoubleAck() throws Exception { | |
| } | ||
|
|
||
| List<Message> receivedMessages = new ArrayList<>(); | ||
| long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(30); | ||
|
|
||
| while (receivedMessages.size() < 3 && System.nanoTime() < deadline) { | ||
| while (receivedMessages.size() < 3) { | ||
| Message received = subscription.receive(); | ||
| if (received != null) { | ||
| receivedMessages.add(received); | ||
| } else { | ||
| TimeUnit.MILLISECONDS.sleep(100); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -351,14 +290,12 @@ public void testGetAttributes() throws Exception { | |
| } | ||
|
|
||
| @Test | ||
| @Timeout(30) | ||
| public void testMultipleSendReceiveWithoutBatch() throws Exception { | ||
| Assumptions.assumeFalse(AWS_PROVIDER_ID.equals(harness.getProviderId())); | ||
| try (AbstractTopic topic = harness.createTopicDriver(); | ||
| AbstractSubscription subscription = harness.createSubscriptionDriver()) { | ||
|
|
||
| int numMessages = 5; | ||
| List<Message> sentMessages = new ArrayList<>(); | ||
|
|
||
| // Send messages one by one (not in batch) | ||
| for (int i = 0; i < numMessages; i++) { | ||
|
|
@@ -367,29 +304,17 @@ public void testMultipleSendReceiveWithoutBatch() throws Exception { | |
| .withMetadata(Map.of("index", String.valueOf(i))) | ||
| .build(); | ||
| topic.send(message); | ||
| sentMessages.add(message); | ||
| TimeUnit.MILLISECONDS.sleep(100); // Small delay between sends | ||
| } | ||
|
|
||
| TimeUnit.MILLISECONDS.sleep(500); // Allow time for messages to be available | ||
|
|
||
| // Receive and ack messages one by one (not in batch) | ||
| List<Message> receivedMessages = new ArrayList<>(); | ||
|
|
||
| while (receivedMessages.size() < numMessages) { | ||
| try { | ||
| Message received = subscription.receive(); | ||
| if (received != null && received.getAckID() != null) { | ||
| receivedMessages.add(received); | ||
| // Ack immediately after receiving (not in batch) | ||
| subscription.sendAck(received.getAckID()); | ||
| System.out.println("Received and acked message " + receivedMessages.size() + "/" + numMessages); | ||
| } else { | ||
| TimeUnit.MILLISECONDS.sleep(100); | ||
| } | ||
| } catch (Exception e) { | ||
| System.err.println("Error receiving message: " + e.getMessage()); | ||
| TimeUnit.MILLISECONDS.sleep(100); | ||
| Message received = subscription.receive(); | ||
| if (received != null && received.getAckID() != null) { | ||
| receivedMessages.add(received); | ||
| // Ack immediately after receiving (not in batch) | ||
| subscription.sendAck(received.getAckID()); | ||
| } | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let’s remove this System.out.println from the code and use the logger instead.