Skip to content

Commit 093c235

Browse files
olavloitesduskis
authored andcommitted
---
yaml --- r: 25623 b: refs/heads/autosynth-trace c: bab445b h: refs/heads/master i: 25621: 2b178af 25619: e7e6dd6 25615: 3ef21f3
1 parent 8e4ab35 commit 093c235

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ refs/heads/autosynth-spanner: cbd30ccc550e9d0419ce4e5e6cfef4951ea170b1
141141
refs/heads/autosynth-speech: 64692f6db11364f663921be02c08072b966b6e7b
142142
refs/heads/autosynth-tasks: eb03eeab747e925175890db923945384d89b273a
143143
refs/heads/autosynth-texttospeech: 2c442fe0b7f089fbab266edfe4dd83c532e82dd0
144-
refs/heads/autosynth-trace: 554c109518b4d70e6264a1cd2b1a13be65e230f9
144+
refs/heads/autosynth-trace: bab445bc0653297ef94543cb97e6c8c440b806a3
145145
refs/heads/autosynth-websecurityscanner: a3c778316a0f78f7ad4bac3dc3721da5ca832d3c
146146
refs/heads/bigquerystorage: 06db74d123d7f8a3ef48755c2fcabed09faf8e64
147147
refs/heads/elharo-patch-1: ce159ef828d3c545991ff78e7b6e0d912a9453e9

branches/autosynth-trace/google-cloud-clients/google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/v1/OpenCensusUtilTest.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
import static com.google.cloud.pubsub.v1.OpenCensusUtil.TRACE_CONTEXT_KEY;
2323
import static org.junit.Assert.assertEquals;
2424
import static org.junit.Assert.assertNotEquals;
25+
import static org.junit.Assert.fail;
2526

27+
import com.google.common.base.Stopwatch;
2628
import com.google.protobuf.ByteString;
2729
import com.google.pubsub.v1.PubsubMessage;
2830
import io.opencensus.common.Scope;
@@ -40,6 +42,7 @@
4042
import io.opencensus.trace.export.SpanData;
4143
import java.util.Collection;
4244
import java.util.List;
45+
import java.util.concurrent.TimeUnit;
4346
import org.junit.Test;
4447

4548
/** Tests for {@link OpenCensusUtil}. */
@@ -123,8 +126,8 @@ private TestMessageReceiver(SpanContext parentLinkedSpan, TagContext originalTag
123126
@Override
124127
public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) {
125128
assertEquals(originalTagContext, tagger.getCurrentTagContext());
129+
assertSpanCount(1);
126130
Collection<SpanData> spanDatas = runningSpanStore.getRunningSpans(RECEIVER_FILTER);
127-
assertEquals(spanDatas.size(), 1);
128131
for (SpanData spanData : spanDatas) {
129132
List<Link> links = spanData.getLinks().getLinks();
130133
assertEquals(links.size(), 1);
@@ -135,5 +138,19 @@ public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) {
135138
}
136139
consumer.ack();
137140
}
141+
142+
private void assertSpanCount(int expected) {
143+
Stopwatch watch = Stopwatch.createStarted();
144+
while (true) {
145+
Collection<SpanData> spanDatas = runningSpanStore.getRunningSpans(RECEIVER_FILTER);
146+
if (spanDatas.size() == 1) {
147+
break;
148+
}
149+
Thread.yield();
150+
if (watch.elapsed(TimeUnit.SECONDS) >= 5) {
151+
fail();
152+
}
153+
}
154+
}
138155
}
139156
}

0 commit comments

Comments
 (0)