Skip to content
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

Fix flakiness of Logging integration tests #1195

Merged
merged 1 commit into from
Aug 25, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterators;
import com.google.common.collect.Sets;
import com.google.protobuf.Any;
import com.google.protobuf.StringValue;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.Timeout;

import java.util.HashSet;
import java.util.Iterator;
Expand All @@ -69,6 +71,9 @@ public abstract class BaseSystemTest {
@Rule
public ExpectedException thrown = ExpectedException.none();

@Rule
public Timeout globalTimeout = Timeout.seconds(300);

/**
* Returns the Logging service used to issue requests. This service can be such that it interacts
* with the remote Logging service (for integration tests) or with an emulator (for local
Expand Down Expand Up @@ -99,12 +104,11 @@ public void testCreateGetUpdateAndDeleteSink() {
assertEquals("dataset", datasetDestination.dataset());
assertEquals(sink, logging().getSink(name));
sink = sink.update(sink.toBuilder()
.versionFormat(SinkInfo.VersionFormat.V1)
.filter("metadata.serviceName=appengine.googleapis.com")
.filter("severity<=ERROR")
.build());
assertEquals(name, sink.name());
assertEquals(SinkInfo.VersionFormat.V1, sink.versionFormat());
assertEquals("metadata.serviceName=appengine.googleapis.com", sink.filter());
assertEquals(SinkInfo.VersionFormat.V2, sink.versionFormat());
assertEquals("severity<=ERROR", sink.filter());
assertTrue(sink.delete());
}

Expand All @@ -125,12 +129,11 @@ public void testCreateGetUpdateAndDeleteSinkAsync()
assertEquals("dataset", datasetDestination.dataset());
assertEquals(sink, logging().getSinkAsync(name).get());
sink = sink.updateAsync(sink.toBuilder()
.versionFormat(SinkInfo.VersionFormat.V1)
.filter("metadata.serviceName=appengine.googleapis.com")
.filter("severity<=ERROR")
.build()).get();
assertEquals(name, sink.name());
assertEquals(SinkInfo.VersionFormat.V1, sink.versionFormat());
assertEquals("metadata.serviceName=appengine.googleapis.com", sink.filter());
assertEquals(SinkInfo.VersionFormat.V2, sink.versionFormat());
assertEquals("severity<=ERROR", sink.filter());
assertTrue(sink.deleteAsync().get());
}

Expand Down Expand Up @@ -171,18 +174,18 @@ public void testUpdateNonExistingSinkAsync() throws ExecutionException, Interrup
}

@Test
public void testListSinks() {
public void testListSinks() throws InterruptedException {
String firstName = formatForTest("test-list-sinks-1");
String secondName = formatForTest("test-list-sinks-2");
Sink firstSink = logging().create(SinkInfo.of(firstName, DatasetDestination.of("dataset")));
Sink secondSink = logging().create(SinkInfo.of(secondName, DatasetDestination.of("dataset")));
Set<String> sinkNames = new HashSet<>();
Iterator<Sink> sinkIterator = logging().listSinks(Logging.ListOption.pageSize(1)).iterateAll();
while (sinkIterator.hasNext()) {
sinkNames.add(sinkIterator.next().name());
Logging.ListOption[] options = {Logging.ListOption.pageSize(1)};
Page<Sink> sinkPage = logging().listSinks(options);
Set<Sink> sinks = Sets.newHashSet(sinkPage.iterateAll());
while (!sinks.contains(firstSink) || !sinks.contains(secondSink)) {
Thread.sleep(500);
sinks = Sets.newHashSet(logging().listSinks(options).iterateAll());
}
assertTrue(sinkNames.contains(firstName));
assertTrue(sinkNames.contains(secondName));
firstSink.delete();
secondSink.delete();
}
Expand All @@ -193,14 +196,13 @@ public void testListSinksAsync() throws ExecutionException, InterruptedException
String secondName = formatForTest("test-list-sinks-async-2");
Sink firstSink = logging().create(SinkInfo.of(firstName, DatasetDestination.of("dataset")));
Sink secondSink = logging().create(SinkInfo.of(secondName, DatasetDestination.of("dataset")));
Set<String> sinkNames = new HashSet<>();
Iterator<Sink> sinkIterator =
logging().listSinksAsync(Logging.ListOption.pageSize(1)).get().iterateAll();
while (sinkIterator.hasNext()) {
sinkNames.add(sinkIterator.next().name());
Logging.ListOption[] options = {Logging.ListOption.pageSize(1)};
AsyncPage<Sink> sinkPage = logging().listSinksAsync(options).get();
Set<Sink> sinks = Sets.newHashSet(sinkPage.iterateAll());
while (!sinks.contains(firstSink) || !sinks.contains(secondSink)) {
Thread.sleep(500);
sinks = Sets.newHashSet(logging().listSinksAsync(options).get().iterateAll());
}
assertTrue(sinkNames.contains(firstName));
assertTrue(sinkNames.contains(secondName));
firstSink.delete();
secondSink.delete();
}
Expand Down Expand Up @@ -304,37 +306,35 @@ public void testUpdateNonExistingMetricAsync() throws ExecutionException, Interr
}

@Test
public void testListMetrics() {
public void testListMetrics() throws InterruptedException {
String firstName = formatForTest("test-list-metrics-1");
String secondName = formatForTest("test-list-metrics-2");
Metric firstMetric = logging().create(MetricInfo.of(firstName, "severity>=ERROR"));
Metric secondMetric = logging().create(MetricInfo.of(secondName, "severity>=ERROR"));
Set<String> metricNames = new HashSet<>();
Iterator<Metric> metricIterator =
logging().listMetrics(Logging.ListOption.pageSize(1)).iterateAll();
while (metricIterator.hasNext()) {
metricNames.add(metricIterator.next().name());
Logging.ListOption[] options = {Logging.ListOption.pageSize(1)};
Page<Metric> metricPage = logging().listMetrics(options);
Set<Metric> metrics = Sets.newHashSet(metricPage.iterateAll());
while (!metrics.contains(firstMetric) || !metrics.contains(secondMetric)) {
Thread.sleep(500);
metrics = Sets.newHashSet(logging().listMetrics(options).iterateAll());
}
assertTrue(metricNames.contains(firstName));
assertTrue(metricNames.contains(secondName));
firstMetric.delete();
secondMetric.delete();
}

@Test
public void testListMetricsAsync() {
public void testListMetricsAsync() throws ExecutionException, InterruptedException {
String firstName = formatForTest("test-list-metrics-async-1");
String secondName = formatForTest("test-list-metrics-async-2");
Metric firstMetric = logging().create(MetricInfo.of(firstName, "severity>=ERROR"));
Metric secondMetric = logging().create(MetricInfo.of(secondName, "severity>=ERROR"));
Set<String> metricNames = new HashSet<>();
Iterator<Metric> metricIterator =
logging().listMetrics(Logging.ListOption.pageSize(1)).iterateAll();
while (metricIterator.hasNext()) {
metricNames.add(metricIterator.next().name());
Logging.ListOption[] options = {Logging.ListOption.pageSize(1)};
AsyncPage<Metric> metricPage = logging().listMetricsAsync(options).get();
Set<Metric> metrics = Sets.newHashSet(metricPage.iterateAll());
while (!metrics.contains(firstMetric) || !metrics.contains(secondMetric)) {
Thread.sleep(500);
metrics = Sets.newHashSet(logging().listMetricsAsync(options).get().iterateAll());
}
assertTrue(metricNames.contains(firstName));
assertTrue(metricNames.contains(secondName));
firstMetric.delete();
secondMetric.delete();
}
Expand Down