Skip to content

Commit 50f6cb8

Browse files
CSHARP-3947: Update serverless testing for load balancer fronting single proxy. (#791)
CSHARP-3947: Update serverless testing for load balancer fronting single proxy.
1 parent b00a225 commit 50f6cb8

File tree

4 files changed

+20
-9
lines changed

4 files changed

+20
-9
lines changed

evergreen/evergreen.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,7 @@ functions:
639639
FRAMEWORK=${FRAMEWORK} \
640640
SERVERLESS_ATLAS_USER="${SERVERLESS_ATLAS_USER}" \
641641
SERVERLESS_ATLAS_PASSWORD="${SERVERLESS_ATLAS_PASSWORD}" \
642-
SINGLE_ATLASPROXY_SERVERLESS_URI="${SINGLE_ATLASPROXY_SERVERLESS_URI}" \
643-
MULTI_ATLASPROXY_SERVERLESS_URI="${MULTI_ATLASPROXY_SERVERLESS_URI}" \
642+
SERVERLESS_URI="${SERVERLESS_URI}" \
644643
SSL=${SSL} \
645644
evergreen/run-serverless-tests.sh
646645

evergreen/run-serverless-tests.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ set -o errexit # Exit the script with error if any of the commands fail
99
# OS Operating system, must be set
1010
# SERVERLESS_ATLAS_USER Authentication user, must be set
1111
# SERVERLESS_ATLAS_PASSWORD Authentiction password, must be set
12-
# SINGLE_ATLASPROXY_SERVERLESS_URI Single atlas proxy serverless uri, must be set
13-
# MULTI_ATLASPROXY_SERVERLESS_URI Multi atlas proxy serverless uri, must be set
12+
# SERVERLESS_URI Single atlas proxy serverless uri, must be set
1413
# SSL TLS connection flag, must be "ssl"
1514
# Modified/exported environment variables:
1615
# MONGODB_URI MONGODB_URI for single host with auth details and TLS and compressor parameters
@@ -47,8 +46,8 @@ else
4746
done
4847
fi
4948

50-
export MONGODB_URI="mongodb://${SERVERLESS_ATLAS_USER}:${SERVERLESS_ATLAS_PASSWORD}@${SINGLE_ATLASPROXY_SERVERLESS_URI:10}"
51-
export MONGODB_URI_WITH_MULTIPLE_MONGOSES="mongodb+srv://${SERVERLESS_ATLAS_USER}:${SERVERLESS_ATLAS_PASSWORD}@${MULTI_ATLASPROXY_SERVERLESS_URI:14}"
49+
# Assume "mongodb+srv" protocol
50+
export MONGODB_URI="mongodb+srv://${SERVERLESS_ATLAS_USER}:${SERVERLESS_ATLAS_PASSWORD}@${SERVERLESS_URI:14}"
5251
export SERVERLESS="true"
5352

5453
if [ "Windows_NT" = "$OS" ]; then

src/MongoDB.Driver.Core/Core/Servers/LoadBalancedServer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,12 @@ protected override void InitializeSubClass()
105105
var oldDescription = Interlocked.CompareExchange(ref _currentDescription, value: newDescription, comparand: _currentDescription);
106106
var eventArgs = new ServerDescriptionChangedEventArgs(oldDescription, newDescription);
107107

108-
// propagate event to upper levels, this will be called only once
109-
TriggerServerDescriptionChanged(this, eventArgs);
110-
111108
// mark pool as ready, start the connection creation thread.
112109
// note that the pool can not be paused after it was marked as ready in LB mode.
113110
ConnectionPool.SetReady();
111+
112+
// propagate event to upper levels, this will be called only once
113+
TriggerServerDescriptionChanged(this, eventArgs);
114114
}
115115

116116
protected override void Invalidate(string reasonInvalidated, bool clearConnectionPool, TopologyVersion topologyVersion)

tests/MongoDB.Driver.Core.Tests/Core/Servers/LoadBalancedServerTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,19 @@ public void Invalidate_should_not_clear_the_connection_pool()
399399
_mockConnectionPool.Verify(p => p.Clear(It.IsAny<ObjectId>()), Times.Never);
400400
}
401401

402+
[Fact]
403+
public void InitializeSubClass_should_initialize_ConnectionPool_before_cluster_updating()
404+
{
405+
bool setReadyHasBeenCalled = false;
406+
_subject.DescriptionChanged += (s, args) =>
407+
{
408+
_mockConnectionPool.Verify(c => c.SetReady(), Times.Once());
409+
setReadyHasBeenCalled = true; // can be called only if the above check passed
410+
};
411+
_subject.Initialize();
412+
setReadyHasBeenCalled.Should().BeTrue();
413+
}
414+
402415
// private methods
403416
private Server SetupServer(bool exceptionOnConnectionOpen, bool exceptionOnConnectionAcquire)
404417
{

0 commit comments

Comments
 (0)