Skip to content

Commit

Permalink
GODRIVER-2348 merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
prestonvasquez committed Jan 16, 2024
2 parents a2f0c9a + df800a9 commit d10ced0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
5 changes: 2 additions & 3 deletions bson/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@
// 2. int8, int16, and int32 marshal to a BSON int32.
// 3. int marshals to a BSON int32 if the value is between math.MinInt32 and math.MaxInt32, inclusive, and a BSON int64
// otherwise.
// 4. int64 marshals to BSON int64.
// 4. int64 marshals to BSON int64 (unless [Encoder.IntMinSize] is set).
// 5. uint8 and uint16 marshal to a BSON int32.
// 6. uint, uint32, and uint64 marshal to a BSON int32 if the value is between math.MinInt32 and math.MaxInt32,
// inclusive, and BSON int64 otherwise.
// 6. uint, uint32, and uint64 marshal to a BSON int64 (unless [Encoder.IntMinSize] is set).
// 7. BSON null and undefined values will unmarshal into the zero value of a field (e.g. unmarshalling a BSON null or
// undefined value into a string will yield the empty string.).
//
Expand Down
30 changes: 30 additions & 0 deletions bson/encoder_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,33 @@ func ExampleEncoder_multipleExtendedJSONDocuments() {
// {"x":{"$numberInt":"3"},"y":{"$numberInt":"4"}}
// {"x":{"$numberInt":"4"},"y":{"$numberInt":"5"}}
}

func ExampleEncoder_IntMinSize() {
// Create an encoder that will marshal integers as the minimum BSON int size
// (either 32 or 64 bits) that can represent the integer value.
type foo struct {
Bar uint32
}

buf := new(bytes.Buffer)
vw, err := bsonrw.NewBSONValueWriter(buf)
if err != nil {
panic(err)
}

enc, err := bson.NewEncoder(vw)
if err != nil {
panic(err)
}

enc.IntMinSize()

err = enc.Encode(foo{2})
if err != nil {
panic(err)
}

fmt.Println(bson.Raw(buf.Bytes()).String())
// Output:
// {"bar": {"$numberInt":"2"}}
}
23 changes: 23 additions & 0 deletions x/mongo/driver/topology/rtt_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,29 @@ func TestRTTMonitor(t *testing.T) {
rtt.Min())
})

t.Run("can connect and disconnect repeatedly", func(t *testing.T) {
t.Parallel()

dialer := DialerFunc(func(_ context.Context, _, _ string) (net.Conn, error) {
return newMockSlowConn(makeHelloReply(), 10*time.Millisecond), nil
})
rtt := newRTTMonitor(&rttConfig{
interval: 10 * time.Second,
createConnectionFn: func() *connection {
return newConnection("", WithDialer(func(Dialer) Dialer {
return dialer
}))
},
createOperationFn: func(conn driver.Connection) *operation.Hello {
return operation.NewHello().Deployment(driver.SingleConnectionDeployment{C: conn})
},
})
for i := 0; i < 100; i++ {
rtt.connect()
rtt.disconnect()
}
})

t.Run("works after reset", func(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit d10ced0

Please sign in to comment.