Skip to content

Commit

Permalink
chore: update mongo/mongoc packages
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan committed Jan 16, 2023
1 parent 4f802c6 commit 5ef4081
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
2 changes: 1 addition & 1 deletion mongo/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/globalsign/mgo"
"github.com/zeromicro/go-zero/core/breaker"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/stores/mongo/internal"
"github.com/zeromicro/go-zero/core/timex"
"github.com/zeromicro/zero-legacy/mongo/internal"
)

const defaultSlowThreshold = time.Millisecond * 500
Expand Down
48 changes: 43 additions & 5 deletions mongo/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ package mongo

import (
"errors"
"strings"
"testing"
"time"

"github.com/globalsign/mgo"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/zeromicro/go-zero/core/breaker"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/stores/mongo/internal"
"github.com/zeromicro/go-zero/core/stringx"
"github.com/zeromicro/zero-legacy/mongo/internal"
)

var errDummy = errors.New("dummy")

func init() {
logx.Disable()
}

func TestKeepPromise_accept(t *testing.T) {
p := new(mockPromise)
kp := keepablePromise{
Expand Down Expand Up @@ -266,6 +264,46 @@ func TestCollectionUpsert(t *testing.T) {
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 {
accepted bool
reason string
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions mongoc/cachedcollection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package mongoc
import (
"encoding/json"
"errors"
"io/ioutil"
"io"
"log"
"os"
"runtime"
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestStat(t *testing.T) {

func TestStatCacheFails(t *testing.T) {
resetStats()
log.SetOutput(ioutil.Discard)
log.SetOutput(io.Discard)
defer log.SetOutput(os.Stdout)

r := redis.New("localhost:59999")
Expand Down

0 comments on commit 5ef4081

Please sign in to comment.