2020-10-26 12:20:49 -04:00
|
|
|
// Copyright The OpenTelemetry Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package trace
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-12-11 06:28:41 +01:00
|
|
|
"errors"
|
2020-10-26 12:20:49 -04:00
|
|
|
"testing"
|
2020-12-11 06:28:41 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-10-26 12:20:49 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type basicSpanProcesor struct {
|
2020-12-11 06:28:41 +01:00
|
|
|
running bool
|
|
|
|
injectShutdownError error
|
2020-10-26 12:20:49 -04:00
|
|
|
}
|
|
|
|
|
2020-10-27 05:06:55 +03:00
|
|
|
func (t *basicSpanProcesor) Shutdown(context.Context) error {
|
2020-10-26 12:20:49 -04:00
|
|
|
t.running = false
|
2020-12-11 06:28:41 +01:00
|
|
|
return t.injectShutdownError
|
2020-10-26 12:20:49 -04:00
|
|
|
}
|
|
|
|
|
2020-12-11 06:15:44 +01:00
|
|
|
func (t *basicSpanProcesor) OnStart(parent context.Context, s ReadWriteSpan) {}
|
|
|
|
func (t *basicSpanProcesor) OnEnd(s ReadOnlySpan) {}
|
|
|
|
func (t *basicSpanProcesor) ForceFlush() {}
|
2020-10-26 12:20:49 -04:00
|
|
|
|
|
|
|
func TestShutdownTraceProvider(t *testing.T) {
|
|
|
|
stp := NewTracerProvider()
|
|
|
|
sp := &basicSpanProcesor{}
|
|
|
|
stp.RegisterSpanProcessor(sp)
|
|
|
|
|
|
|
|
sp.running = true
|
|
|
|
|
|
|
|
_ = stp.Shutdown(context.Background())
|
|
|
|
|
|
|
|
if sp.running != false {
|
|
|
|
t.Errorf("Error shutdown basicSpanProcesor\n")
|
|
|
|
}
|
|
|
|
}
|
2020-12-11 06:28:41 +01:00
|
|
|
|
|
|
|
func TestFailedProcessorShutdown(t *testing.T) {
|
|
|
|
handler.Reset()
|
|
|
|
stp := NewTracerProvider()
|
|
|
|
spErr := errors.New("basic span processor shutdown failure")
|
|
|
|
sp := &basicSpanProcesor{
|
|
|
|
running: true,
|
|
|
|
injectShutdownError: spErr,
|
|
|
|
}
|
|
|
|
stp.RegisterSpanProcessor(sp)
|
|
|
|
|
|
|
|
_ = stp.Shutdown(context.Background())
|
|
|
|
|
|
|
|
assert.Contains(t, handler.errs, spErr)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFailedProcessorShutdownInUnregister(t *testing.T) {
|
|
|
|
handler.Reset()
|
|
|
|
stp := NewTracerProvider()
|
|
|
|
spErr := errors.New("basic span processor shutdown failure")
|
|
|
|
sp := &basicSpanProcesor{
|
|
|
|
running: true,
|
|
|
|
injectShutdownError: spErr,
|
|
|
|
}
|
|
|
|
stp.RegisterSpanProcessor(sp)
|
|
|
|
stp.UnregisterSpanProcessor(sp)
|
|
|
|
|
|
|
|
assert.Contains(t, handler.errs, spErr)
|
|
|
|
|
|
|
|
handler.errs = nil
|
|
|
|
_ = stp.Shutdown(context.Background())
|
|
|
|
assert.Empty(t, handler.errs)
|
|
|
|
}
|