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

Expand test-index.js #409

Merged
merged 1 commit into from
Feb 23, 2017
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/tracing-policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ function TraceNonePolicy() {}
TraceNonePolicy.prototype.shouldTrace = function() { return false; };

module.exports = {
TraceAllPolicy: TraceAllPolicy,
TraceNonePolicy: TraceNonePolicy,
FilterPolicy: FilterPolicy,
createTracePolicy: function(config) {
var basePolicy;
if (config.samplingRate < 1) {
Expand Down
41 changes: 21 additions & 20 deletions test/test-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('index.js', function() {
});
});

it('should produce real root spans runInRootSpan async', function(done) {
it('should produce real root spans runInRootSpan', function(done) {
agent.runInRootSpan({name: 'root', url: 'root'}, function(rootSpan) {
rootSpan.addLabel('key', 'val');
var childSpan = agent.createChildSpan({name: 'sub'});
Expand All @@ -106,29 +106,17 @@ describe('index.js', function() {

it('should not allow nested root spans', function(done) {
agent.runInRootSpan({name: 'root', url: 'root'}, function(rootSpan1) {
var finished = false;
var finish = function () {
assert(!finished);
finished = true;
setTimeout(function() {
agent.runInRootSpan({name: 'root2', url: 'root2'}, function(rootSpan2) {
assert.strictEqual(rootSpan2, null);
});
rootSpan1.endSpan();
var spanPredicate = function(span) {
return span.name === 'root';
};
var matchingSpan = common.getMatchingSpan(agent, spanPredicate);
var duration = Date.parse(matchingSpan.endTime) - Date.parse(matchingSpan.startTime);
var span = common.getMatchingSpan(agent, function() { return true; });
assert.equal(span.name, 'root');
var duration = Date.parse(span.endTime) - Date.parse(span.startTime);
assert(duration > 190);
assert(duration < 300);
done();
};
setTimeout(function() {
agent.runInRootSpan({name: 'root2', url: 'root2'}, function(rootSpan2) {
setTimeout(function() {
// We shouldn't reach this point
rootSpan2.endSpan();
finish();
}, 200);
});
finish();
}, 200);
});
});
Expand All @@ -142,6 +130,19 @@ describe('index.js', function() {
});
});

it('should respect filter urls', function() {
var url = 'rootUrl';
var filterPolicy = new TracingPolicy.FilterPolicy(new TracingPolicy.TraceAllPolicy(), [url]);
var oldPolicy = common.replaceTracingPolicy(agent, filterPolicy);
agent.runInRootSpan({name: 'root1', url: url}, function(rootSpan) {
assert.strictEqual(rootSpan, null);
});
agent.runInRootSpan({name: 'root2', url: 'alternativeUrl'}, function(rootSpan) {
assert.strictEqual(rootSpan.span_.span.name, 'root2');
});
common.replaceTracingPolicy(agent, oldPolicy);
});

it('should set agent on global object', function() {
assert.equal(global._google_trace_agent, agent);
});
Expand Down