|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -import { SpanKind, SpanOptions } from '@opencensus/web-types'; |
| 17 | +import { SpanKind } from '@opencensus/web-types'; |
18 | 18 | import { RootSpan } from '../src/trace/model/root-span'; |
19 | 19 | import { Tracer } from '../src/trace/model/tracer'; |
20 | 20 |
|
@@ -51,40 +51,6 @@ describe('RootSpan', () => { |
51 | 51 | }); |
52 | 52 | }); |
53 | 53 |
|
54 | | - describe('startChildSpan', () => { |
55 | | - it('appends to spans list based on root id and state', () => { |
56 | | - root.traceId = '00000000000000000000000000000001'; |
57 | | - root.traceState = 'a=b'; |
58 | | - |
59 | | - const childSpan = root.startChildSpan('child1', SpanKind.CLIENT); |
60 | | - |
61 | | - expect(childSpan.traceId).toBe('00000000000000000000000000000001'); |
62 | | - expect(childSpan.traceState).toBe('a=b'); |
63 | | - expect(childSpan.name).toBe('child1'); |
64 | | - expect(childSpan.kind).toBe(SpanKind.CLIENT); |
65 | | - expect(childSpan.parentSpanId).toBe(root.id); |
66 | | - expect(root.spans).toEqual([childSpan]); |
67 | | - }); |
68 | | - |
69 | | - it('allows specifying SpanOptions object with name and kind', () => { |
70 | | - root.traceId = '00000000000000000000000000000001'; |
71 | | - root.traceState = 'a=b'; |
72 | | - |
73 | | - const spanOptions: SpanOptions = { |
74 | | - name: 'child1', |
75 | | - kind: SpanKind.CLIENT, |
76 | | - }; |
77 | | - const childSpan = root.startChildSpan(spanOptions); |
78 | | - |
79 | | - expect(childSpan.traceId).toBe('00000000000000000000000000000001'); |
80 | | - expect(childSpan.traceState).toBe('a=b'); |
81 | | - expect(childSpan.name).toBe('child1'); |
82 | | - expect(childSpan.kind).toBe(SpanKind.CLIENT); |
83 | | - expect(childSpan.parentSpanId).toBe(root.id); |
84 | | - expect(root.spans).toEqual([childSpan]); |
85 | | - }); |
86 | | - }); |
87 | | - |
88 | 54 | describe('start', () => { |
89 | 55 | it('sets start time and calls onStartSpan for tracer', () => { |
90 | 56 | spyOn(tracer, 'onStartSpan'); |
@@ -121,18 +87,36 @@ describe('RootSpan', () => { |
121 | 87 | }); |
122 | 88 | }); |
123 | 89 |
|
124 | | - describe('get numberOfChildren()', () => { |
125 | | - it('should get numberOfChildren from rootspan instance', () => { |
126 | | - root = new RootSpan(tracer); |
| 90 | + describe('nested spans', () => { |
| 91 | + it('should get nested spans from rootspan instance', () => { |
127 | 92 | root.start(); |
128 | 93 | expect(root.numberOfChildren).toBe(0); |
129 | | - root.startChildSpan('spanName', SpanKind.UNSPECIFIED); |
| 94 | + const child1 = root.startChildSpan('child1', SpanKind.UNSPECIFIED); |
130 | 95 | expect(root.numberOfChildren).toBe(1); |
| 96 | + expect(child1.numberOfChildren).toBe(0); |
| 97 | + const child2 = root.startChildSpan('child2', SpanKind.UNSPECIFIED); |
| 98 | + expect(root.numberOfChildren).toBe(2); |
| 99 | + const grandchild1 = child1.startChildSpan({ |
| 100 | + name: 'grandchild1', |
| 101 | + kind: SpanKind.UNSPECIFIED, |
| 102 | + }); |
| 103 | + expect(root.numberOfChildren).toBe(2); |
| 104 | + expect(child1.numberOfChildren).toBe(1); |
| 105 | + expect(child2.numberOfChildren).toBe(0); |
| 106 | + expect(grandchild1.numberOfChildren).toBe(0); |
| 107 | + |
| 108 | + expect(child1).toBe(root.spans[0]); |
| 109 | + expect(child2).toBe(root.spans[1]); |
| 110 | + expect(grandchild1.parentSpanId).toBe(child1.id); |
| 111 | + |
| 112 | + expect(child1.spans.length).toBe(1); |
| 113 | + expect(grandchild1).toBe(child1.spans[0]); |
| 114 | + |
| 115 | + expect(child2.spans.length).toBe(0); |
| 116 | + expect(child2.spans.length).toBe(0); |
| 117 | + expect(grandchild1.spans.length).toBe(0); |
131 | 118 |
|
132 | | - for (let i = 0; i < 10; i++) { |
133 | | - root.startChildSpan('spanName' + i, SpanKind.UNSPECIFIED); |
134 | | - } |
135 | | - expect(root.numberOfChildren).toBe(11); |
| 119 | + expect(root.allDescendants().length).toBe(3); |
136 | 120 | }); |
137 | 121 | }); |
138 | 122 | }); |
0 commit comments