|
|
@ -2,7 +2,9 @@ package mongo
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/globalsign/mgo"
|
|
|
|
"github.com/globalsign/mgo"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
|
|
"github.com/golang/mock/gomock"
|
|
|
@ -266,6 +268,46 @@ func TestCollectionUpsert(t *testing.T) {
|
|
|
|
assert.Equal(t, errDummy, err)
|
|
|
|
assert.Equal(t, errDummy, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func Test_logDuration(t *testing.T) {
|
|
|
|
|
|
|
|
ctrl := gomock.NewController(t)
|
|
|
|
|
|
|
|
defer ctrl.Finish()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
col := internal.NewMockMgoCollection(ctrl)
|
|
|
|
|
|
|
|
c := decoratedCollection{
|
|
|
|
|
|
|
|
collection: col,
|
|
|
|
|
|
|
|
brk: breaker.NewBreaker(),
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var buf strings.Builder
|
|
|
|
|
|
|
|
w := logx.NewWriter(&buf)
|
|
|
|
|
|
|
|
o := logx.Reset()
|
|
|
|
|
|
|
|
logx.SetWriter(w)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
|
|
|
|
logx.Reset()
|
|
|
|
|
|
|
|
logx.SetWriter(o)
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buf.Reset()
|
|
|
|
|
|
|
|
c.logDuration("foo", time.Millisecond, nil, "bar")
|
|
|
|
|
|
|
|
assert.Contains(t, buf.String(), "foo")
|
|
|
|
|
|
|
|
assert.Contains(t, buf.String(), "bar")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buf.Reset()
|
|
|
|
|
|
|
|
c.logDuration("foo", time.Millisecond, errors.New("bar"), make(chan int))
|
|
|
|
|
|
|
|
assert.Contains(t, buf.String(), "bar")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buf.Reset()
|
|
|
|
|
|
|
|
c.logDuration("foo", slowThreshold.Load()+time.Millisecond, errors.New("bar"))
|
|
|
|
|
|
|
|
assert.Contains(t, buf.String(), "bar")
|
|
|
|
|
|
|
|
assert.Contains(t, buf.String(), "slowcall")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buf.Reset()
|
|
|
|
|
|
|
|
c.logDuration("foo", slowThreshold.Load()+time.Millisecond, nil)
|
|
|
|
|
|
|
|
assert.Contains(t, buf.String(), "foo")
|
|
|
|
|
|
|
|
assert.Contains(t, buf.String(), "slowcall")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type mockPromise struct {
|
|
|
|
type mockPromise struct {
|
|
|
|
accepted bool
|
|
|
|
accepted bool
|
|
|
|
reason string
|
|
|
|
reason string
|
|
|
|