Skip to content

Commit

Permalink
test: Fix flaky tests (googleapis#2221)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
michaelpri10 authored Oct 8, 2024
1 parent c447fe5 commit 30542e6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,7 @@ public void testPublishOpenTelemetryTracing() throws Exception {
fakeExecutor.advanceTime(Duration.ofSeconds(5));
assertEquals("1", publishFuture.get());
fakeExecutor.advanceTime(Duration.ofSeconds(5));
shutdownTestPublisher(publisher);

List<SpanData> allSpans = openTelemetryTesting.getSpans();
assertEquals(4, allSpans.size());
Expand Down
4 changes: 2 additions & 2 deletions samples/snippets/src/test/java/pubsub/AdminIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public class AdminIT {
private static final String cloudStorageInputFormat = "text";
private static final String cloudStorageTextDelimiter = ",";
private static final String cloudStorageMatchGlob = "**.txt";
private static final String cloudStorageMinimumObjectCreateTime = "1970-01-01T00:00:00Z";
private static final String cloudStorageMinimumObjectCreateTimeSeconds = "0";
private static final String cloudStorageMinimumObjectCreateTime = "1970-01-01T00:00:01Z";
private static final String cloudStorageMinimumObjectCreateTimeSeconds = "seconds: 1";

private static final TopicName topicName = TopicName.of(projectId, topicId);
private static final TopicName kinesisIngestionTopicName =
Expand Down
13 changes: 7 additions & 6 deletions samples/snippets/src/test/java/pubsub/SubscriberIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@
import java.util.List;
import java.util.UUID;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;

public class SubscriberIT {
private ByteArrayOutputStream bout;
private PrintStream out;
private static ByteArrayOutputStream bout;
private static PrintStream out;

private static final String projectId = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String _suffix = UUID.randomUUID().toString();
Expand Down Expand Up @@ -129,8 +130,8 @@ public static void checkRequirements() {
requireEnvVar("GOOGLE_CLOUD_PROJECT");
}

@Before
public void setUp() throws Exception {
@BeforeClass
public static void setUp() throws Exception {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
System.setOut(out);
Expand Down Expand Up @@ -162,8 +163,8 @@ public void setUp() throws Exception {
}
}

@After
public void tearDown() throws Exception {
@AfterClass
public static void tearDown() throws Exception {
try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) {
subscriptionAdminClient.deleteSubscription(subscriptionName.toString());
subscriptionAdminClient.deleteSubscription(subscriptionEodName.toString());
Expand Down

0 comments on commit 30542e6

Please sign in to comment.