Skip to content

Commit 2b69d85

Browse files
author
rstam
committed
CSHARP-715: Add unit test for InsertBatch with small final subbatch.
1 parent 7e7b57a commit 2b69d85

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

MongoDB.DriverUnitTests/MongoCollectionTests.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,36 @@ public void TestInsertBatchMultipleBatchesWriteConcernDisabledContinueOnErrorTru
11881188
}
11891189
}
11901190

1191+
[Test]
1192+
public void TestInsertBatchSmallFinalSubbatch()
1193+
{
1194+
var collectionName = Configuration.TestCollection.Name;
1195+
var collectionSettings = new MongoCollectionSettings { WriteConcern = WriteConcern.Unacknowledged };
1196+
var collection = Configuration.TestDatabase.GetCollection<BsonDocument>(collectionName, collectionSettings);
1197+
if (collection.Exists()) { collection.Drop(); }
1198+
1199+
using (Configuration.TestDatabase.RequestStart())
1200+
{
1201+
var maxMessageLength = Configuration.TestServer.RequestConnection.ServerInstance.MaxMessageLength;
1202+
var documentCount = maxMessageLength / (1024 * 1024) + 1; // 1 document will overflow to second sub batch
1203+
1204+
var documents = new BsonDocument[documentCount];
1205+
for (var i = 0; i < documentCount; i++)
1206+
{
1207+
var document = new BsonDocument
1208+
{
1209+
{ "_id", i },
1210+
{ "filler", new string('x', 1024 * 1024) }
1211+
};
1212+
documents[i] = document;
1213+
}
1214+
1215+
collection.InsertBatch(documents);
1216+
1217+
Assert.AreEqual(documentCount, collection.Count());
1218+
}
1219+
}
1220+
11911221
[Test]
11921222
public void TestIsCappedFalse()
11931223
{

0 commit comments

Comments
 (0)