Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit ed08da1

Browse files
Vizeraig-easy
authored andcommitted
Fix double-export bug in local_span_store_test. (#72)
1 parent f1c961d commit ed08da1

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

opencensus/trace/internal/local_span_store_test.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ class SpanTestPeer {
2727
static void End(absl::Duration latency, Span* span) {
2828
// Set latency.
2929
span->span_impl_for_test()->EndWithLatencyForTesting(latency);
30-
// Then call Span::End to get into stores.
31-
span->End();
30+
// Call Span::ExportSpanForTesting to get span into stores.
31+
span->span_impl_for_test()->ExportSpanForTesting(
32+
span->span_impl_for_test());
3233
}
3334
};
3435

opencensus/trace/internal/span_impl.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
#include "opencensus/trace/attribute_value_ref.h"
2424
#include "opencensus/trace/exporter/attribute_value.h"
2525
#include "opencensus/trace/exporter/message_event.h"
26+
#include "opencensus/trace/internal/local_span_store_impl.h"
27+
#include "opencensus/trace/internal/running_span_store_impl.h"
28+
#include "opencensus/trace/internal/span_exporter_impl.h"
2629
#include "opencensus/trace/span.h"
2730

2831
namespace opencensus {
@@ -134,6 +137,12 @@ void SpanImpl::SetStatus(exporter::Status&& status) {
134137
}
135138
}
136139

140+
void SpanImpl::ExportSpanForTesting(const std::shared_ptr<SpanImpl>& span) {
141+
exporter::RunningSpanStoreImpl::Get()->RemoveSpan(span);
142+
exporter::LocalSpanStoreImpl::Get()->AddSpan(span);
143+
exporter::SpanExporterImpl::Get()->AddSpan(span);
144+
}
145+
137146
void SpanImpl::End() { EndWithTime(absl::Now()); }
138147

139148
bool SpanImpl::HasEnded() const {
@@ -142,7 +151,9 @@ bool SpanImpl::HasEnded() const {
142151
}
143152

144153
void SpanImpl::EndWithLatencyForTesting(absl::Duration latency) {
145-
EndWithTime(start_time_ + latency);
154+
absl::MutexLock l(&mu_);
155+
has_ended_ = true;
156+
end_time_ = start_time_ + latency;
146157
}
147158

148159
void SpanImpl::EndWithTime(absl::Time end_time) {

opencensus/trace/internal/span_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ class SpanImpl final {
106106
friend class ::opencensus::trace::exporter::SpanExporterImpl;
107107
friend class ::opencensus::trace::SpanTestPeer;
108108

109+
void ExportSpanForTesting(const std::shared_ptr<SpanImpl>& span);
109110
void EndWithLatencyForTesting(absl::Duration latency) LOCKS_EXCLUDED(mu_);
110111
void EndWithTime(absl::Time end_time) LOCKS_EXCLUDED(mu_);
111112

0 commit comments

Comments
 (0)