Skip to content

Commit

Permalink
Make PubSub integration tests more robust (#1288)
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard authored Sep 28, 2016
1 parent 8db5ed3 commit 0237ac0
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.cloud.pubsub.PubSub.MessageConsumer;
import com.google.cloud.pubsub.PubSub.MessageProcessor;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;

Expand Down Expand Up @@ -465,7 +466,18 @@ public void testPullMessagesAndAutoRenewDeadline() throws InterruptedException {
pubsub().publish(topic, message1);
pubsub().publish(topic, message2);
Iterator<ReceivedMessage> iterator = pubsub().pull(subscription, 2);
while (!iterator.hasNext()) {
Thread.sleep(500);
iterator = pubsub().pull(subscription, 2);
}
ReceivedMessage consumedMessage = iterator.next();
if (!iterator.hasNext()) {
iterator = pubsub().pull(subscription, 1);
while (!iterator.hasNext()) {
Thread.sleep(500);
iterator = pubsub().pull(subscription, 1);
}
}
Thread.sleep(15000);
// first message was consumed while second message is still being renewed
Iterator<ReceivedMessage> nextIterator = pubsub().pull(subscription, 2);
Expand Down Expand Up @@ -494,6 +506,10 @@ public void testPullMessagesAndModifyAckDeadline() throws InterruptedException {
pubsub().publish(topic, message2);
// Consume all messages and stop ack renewal
List<ReceivedMessage> receivedMessages = Lists.newArrayList(pubsub().pull(subscription, 2));
while (receivedMessages.size() < 2) {
Thread.sleep(500);
Iterators.addAll(receivedMessages, pubsub().pull(subscription, 2));
}
receivedMessages.get(0).modifyAckDeadline(60, TimeUnit.SECONDS);
Thread.sleep(15000);
// first message was renewed while second message should still be sent on pull requests
Expand Down

0 comments on commit 0237ac0

Please sign in to comment.