Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions tests/test_collections_sharded.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,21 @@ def test_clone_document_sharded(t: Testing, phase: Runner.Phase):

t.compare_all_sharded()

@pytest.mark.parametrize("phase", [Runner.Phase.CLONE])
def test_clone_document_sharded_with_varying_sizes(t: Testing, phase: Runner.Phase):
with t.run(phase):
t.source["db_1"].create_collection("coll_1")
t.source.admin.command("shardCollection", "db_1.coll_1", key={"_id": "hashed"})
# insert documents with varying sizes to produce fractional avgObjSize
docs = [
{"_id": 1, "name": "Alice", "age": 30, "data": "x" * 15},
{"_id": 2, "name": "Bob", "age": 25, "data": "y" * 47},
{"_id": 3, "name": "Charlie", "age": 35, "data": "z" * 73},
{"_id": 4, "name": "Diana", "age": 28, "data": "a" * 22},
{"_id": 5, "name": "Eve", "age": 32, "data": "b" * 91},
]
t.source["db_1"]["coll_1"].insert_many(docs)
t.compare_all_sharded()

@pytest.mark.parametrize("phase", [Runner.Phase.APPLY])
def test_shard_key_update_duplicate_key_error(t: Testing, phase: Runner.Phase):
Expand Down
6 changes: 3 additions & 3 deletions topo/topo.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ type DBStats struct {
// CollStats represents the result of the [GetCollStats].
type CollStats struct {
// Count is the number of documents in the collection.
Count int64 `bson:"count"`
Count int64 `bson:"count,truncate"`
// Size is the total size of the collection.
Size int64 `bson:"size"`
Size int64 `bson:"size,truncate"`
// AvgObjSize is the average size of documents in the collection.
AvgObjSize int64 `bson:"avgObjSize"`
AvgObjSize int64 `bson:"avgObjSize,truncate"`
}

// SayHello runs the db.hello() command and returns the [Hello].
Expand Down
24 changes: 24 additions & 0 deletions topo/topo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,33 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
)

func TestCollStats_DecodeFromFloat64(t *testing.T) {
t.Parallel()

input := bson.M{
"count": 0.1,
"size": 73179136.2,
"avgObjSize": 0.3,
}

data, err := bson.Marshal(input)
require.NoError(t, err)

var stats CollStats
err = bson.Unmarshal(data, &stats)
require.NoError(t, err)

assert.Equal(t, int64(0), stats.Count)
assert.Equal(t, int64(73179136), stats.Size)
assert.Equal(t, int64(0), stats.AvgObjSize)
}

func TestRunWithRetry_NonTransientError(t *testing.T) {
t.Parallel()

Expand Down
Loading