@@ -7,7 +7,11 @@ import (
7
7
"reflect"
8
8
"testing"
9
9
10
+ "github.com/go-logr/logr"
11
+ "github.com/go-logr/logr/funcr"
10
12
"github.com/stretchr/testify/assert"
13
+
14
+ "go.opentelemetry.io/otel/internal/global"
11
15
)
12
16
13
17
func init () {
@@ -36,18 +40,25 @@ func TestCopy(t *testing.T) {
36
40
37
41
func TestDropCount (t * testing.T ) {
38
42
q := newEvictedQueueEvent (3 )
39
- var called bool
40
- q .logDropped = func () { called = true }
43
+
44
+ var called int
45
+ t .Cleanup (func (l logr.Logger ) func () {
46
+ return func () { global .SetLogger (l ) }
47
+ }(global .GetLogger ()))
48
+ global .SetLogger (funcr .New (func (prefix , args string ) {
49
+ called ++
50
+ }, funcr.Options {Verbosity : 1 }))
41
51
42
52
q .add (Event {Name : "value1" })
43
- assert .False ( t , called , `"value1" logged as dropped` )
53
+ assert .Equal ( t , 0 , called , `"value1" logged as dropped` )
44
54
q .add (Event {Name : "value2" })
45
- assert .False ( t , called , `"value2" logged as dropped` )
55
+ assert .Equal ( t , 0 , called , `"value2" logged as dropped` )
46
56
q .add (Event {Name : "value3" })
47
- assert .False ( t , called , `"value3" logged as dropped` )
57
+ assert .Equal ( t , 0 , called , `"value3" logged as dropped` )
48
58
q .add (Event {Name : "value1" })
49
- assert .True ( t , called , `"value2" not logged as dropped` )
59
+ assert .Equal ( t , 1 , called , `"value2" not logged as dropped` )
50
60
q .add (Event {Name : "value4" })
61
+ assert .Equal (t , 1 , called , `"value4" logged as dropped` )
51
62
if wantLen , gotLen := 3 , len (q .queue ); wantLen != gotLen {
52
63
t .Errorf ("got queue length %d want %d" , gotLen , wantLen )
53
64
}
0 commit comments