2022-04-19 14:03:04 +08:00
|
|
|
package mon
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2023-01-05 22:14:50 +08:00
|
|
|
mopt "go.mongodb.org/mongo-driver/mongo/options"
|
2022-04-19 14:03:04 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestSetSlowThreshold(t *testing.T) {
|
|
|
|
|
assert.Equal(t, defaultSlowThreshold, slowThreshold.Load())
|
|
|
|
|
SetSlowThreshold(time.Second)
|
|
|
|
|
assert.Equal(t, time.Second, slowThreshold.Load())
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-05 22:14:50 +08:00
|
|
|
func Test_defaultTimeoutOption(t *testing.T) {
|
|
|
|
|
opts := mopt.Client()
|
|
|
|
|
defaultTimeoutOption()(opts)
|
|
|
|
|
assert.Equal(t, defaultTimeout, *opts.Timeout)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestWithTimeout(t *testing.T) {
|
|
|
|
|
opts := mopt.Client()
|
|
|
|
|
WithTimeout(time.Second)(opts)
|
|
|
|
|
assert.Equal(t, time.Second, *opts.Timeout)
|
2022-04-19 14:03:04 +08:00
|
|
|
}
|