Skip to content

Commit 9f14d34

Browse files
committed
- fixed issue with _primary being null in sharded systems.
1 parent 0ed4fcf commit 9f14d34

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

MongoDB.DriverUnitTests/MongoCollectionTests.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ private class TestClass
4444
public void Setup()
4545
{
4646
_server = Configuration.TestServer;
47-
_primary = Configuration.TestServer.Primary;
47+
_primary = _server.Instances.First(x => ReadPreference.Primary.MatchesInstance(x));
4848
_database = Configuration.TestDatabase;
4949
_collection = Configuration.TestCollection;
5050
}
@@ -1752,7 +1752,7 @@ public void TestGetMore()
17521752
using (_server.RequestStart(_database))
17531753
{
17541754
_collection.RemoveAll();
1755-
var count = _server.Primary.MaxMessageLength / 1000000;
1755+
var count = _primary.MaxMessageLength / 1000000;
17561756
for (int i = 0; i < count; i++)
17571757
{
17581758
var document = new BsonDocument("data", new BsonBinaryData(new byte[1000000]));
@@ -2763,27 +2763,30 @@ public void TestStrictWrite()
27632763
}
27642764

27652765
[Test]
2766-
public void TestTextIndex()
2766+
public void TestTextSearch()
27672767
{
27682768
if (_primary.Supports(FeatureId.TextSearchCommand))
27692769
{
2770-
Configuration.EnableTextSearch(_primary);
2771-
using (_server.RequestStart(null, _primary))
2770+
if (_primary.InstanceType != MongoServerInstanceType.ShardRouter)
27722771
{
2773-
_collection.Drop();
2774-
_collection.Insert(new BsonDocument("x", "The quick brown fox"));
2775-
_collection.Insert(new BsonDocument("x", "jumped over the fence"));
2776-
_collection.CreateIndex(IndexKeys.Text("x"));
2772+
Configuration.EnableTextSearch(_primary);
2773+
using (_server.RequestStart(null, _primary))
2774+
{
2775+
_collection.Drop();
2776+
_collection.Insert(new BsonDocument("x", "The quick brown fox"));
2777+
_collection.Insert(new BsonDocument("x", "jumped over the fence"));
2778+
_collection.CreateIndex(IndexKeys.Text("x"));
27772779

2778-
var textSearchCommand = new CommandDocument
2780+
var textSearchCommand = new CommandDocument
27792781
{
27802782
{ "text", _collection.Name },
27812783
{ "search", "fox" }
27822784
};
2783-
var commandResult = _database.RunCommand(textSearchCommand);
2784-
var response = commandResult.Response;
2785-
Assert.AreEqual(1, response["stats"]["n"].ToInt32());
2786-
Assert.AreEqual("The quick brown fox", response["results"][0]["obj"]["x"].AsString);
2785+
var commandResult = _database.RunCommand(textSearchCommand);
2786+
var response = commandResult.Response;
2787+
Assert.AreEqual(1, response["stats"]["n"].ToInt32());
2788+
Assert.AreEqual("The quick brown fox", response["results"][0]["obj"]["x"].AsString);
2789+
}
27872790
}
27882791
}
27892792
}

0 commit comments

Comments
 (0)