Skip to content

Commit 30542e6

Browse files
authored
test: Fix flaky tests (#2221)
* test: Add logs to flaky OpenTelemetry test * test: Ensure publisher is shutdown before checking spans in test * test: Remove logs from test * test: Check that subscription is created in subscriber samples test * test: Use err to log for testing * test: Only setup and teardown before and after the entire test suite for SubscriberIT * test: Remove logs from test * test: Import AfterClass class * test: Fix errors in test * test: Add small change to GCS ingestion test
1 parent c447fe5 commit 30542e6

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/PublisherImplTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,7 @@ public void testPublishOpenTelemetryTracing() throws Exception {
13421342
fakeExecutor.advanceTime(Duration.ofSeconds(5));
13431343
assertEquals("1", publishFuture.get());
13441344
fakeExecutor.advanceTime(Duration.ofSeconds(5));
1345+
shutdownTestPublisher(publisher);
13451346

13461347
List<SpanData> allSpans = openTelemetryTesting.getSpans();
13471348
assertEquals(4, allSpans.size());

samples/snippets/src/test/java/pubsub/AdminIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ public class AdminIT {
8181
private static final String cloudStorageInputFormat = "text";
8282
private static final String cloudStorageTextDelimiter = ",";
8383
private static final String cloudStorageMatchGlob = "**.txt";
84-
private static final String cloudStorageMinimumObjectCreateTime = "1970-01-01T00:00:00Z";
85-
private static final String cloudStorageMinimumObjectCreateTimeSeconds = "0";
84+
private static final String cloudStorageMinimumObjectCreateTime = "1970-01-01T00:00:01Z";
85+
private static final String cloudStorageMinimumObjectCreateTimeSeconds = "seconds: 1";
8686

8787
private static final TopicName topicName = TopicName.of(projectId, topicId);
8888
private static final TopicName kinesisIngestionTopicName =

samples/snippets/src/test/java/pubsub/SubscriberIT.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,16 @@
3939
import java.util.List;
4040
import java.util.UUID;
4141
import org.junit.After;
42+
import org.junit.AfterClass;
4243
import org.junit.Before;
4344
import org.junit.BeforeClass;
4445
import org.junit.Rule;
4546
import org.junit.Test;
4647
import org.junit.rules.Timeout;
4748

4849
public class SubscriberIT {
49-
private ByteArrayOutputStream bout;
50-
private PrintStream out;
50+
private static ByteArrayOutputStream bout;
51+
private static PrintStream out;
5152

5253
private static final String projectId = System.getenv("GOOGLE_CLOUD_PROJECT");
5354
private static final String _suffix = UUID.randomUUID().toString();
@@ -129,8 +130,8 @@ public static void checkRequirements() {
129130
requireEnvVar("GOOGLE_CLOUD_PROJECT");
130131
}
131132

132-
@Before
133-
public void setUp() throws Exception {
133+
@BeforeClass
134+
public static void setUp() throws Exception {
134135
bout = new ByteArrayOutputStream();
135136
out = new PrintStream(bout);
136137
System.setOut(out);
@@ -162,8 +163,8 @@ public void setUp() throws Exception {
162163
}
163164
}
164165

165-
@After
166-
public void tearDown() throws Exception {
166+
@AfterClass
167+
public static void tearDown() throws Exception {
167168
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
168169
subscriptionAdminClient.deleteSubscription(subscriptionName.toString());
169170
subscriptionAdminClient.deleteSubscription(subscriptionEodName.toString());

0 commit comments

Comments
 (0)