Skip to content

Commit a563175

Browse files
CSHARP-3387: Serverless testing (mongodb#583)
1 parent abe8da1 commit a563175

File tree

72 files changed

+1163
-197
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1163
-197
lines changed

build.cake

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ Task("Test")
167167
case "testnetstandard15": settings.Framework = "netcoreapp1.1"; break;
168168
case "testnetstandard20": settings.Framework = "netcoreapp2.1"; break;
169169
case "testnetstandard21": settings.Framework = "netcoreapp3.0"; break;
170+
default: throw new ArgumentException($"Unexpected target: \"{target}\".");
170171
}
171172
DotNetCoreTest(
172173
testProject.FullPath,
@@ -319,7 +320,7 @@ Task("TestGssapi")
319320
.DoesForEach(
320321
GetFiles("./**/MongoDB.Driver.Tests.csproj"),
321322
testProject =>
322-
{
323+
{
323324
var settings = new DotNetCoreTestSettings
324325
{
325326
NoBuild = true,
@@ -334,18 +335,52 @@ Task("TestGssapi")
334335
case "testgssapinetstandard15": settings.Framework = "netcoreapp1.1"; break;
335336
case "testgssapinetstandard20": settings.Framework = "netcoreapp2.1"; break;
336337
case "testgssapinetstandard21": settings.Framework = "netcoreapp3.0"; break;
338+
default: throw new ArgumentException($"Unexpected target: \"{target}\".");
337339
}
338-
DotNetCoreTest(
339-
testProject.FullPath,
340+
DotNetCoreTest(
341+
testProject.FullPath,
340342
settings
341-
);
342-
});
343+
);
344+
});
343345

344346
Task("TestGssapiNet452").IsDependentOn("TestGssapi");
345347
Task("TestGssapiNetStandard15").IsDependentOn("TestGssapi");
346348
Task("TestGssapiNetStandard20").IsDependentOn("TestGssapi");
347349
Task("TestGssapiNetStandard21").IsDependentOn("TestGssapi");
348350

351+
Task("TestServerless")
352+
.IsDependentOn("Build")
353+
.DoesForEach(
354+
GetFiles("./**/MongoDB.Driver.Tests.csproj"),
355+
testProject =>
356+
{
357+
var settings = new DotNetCoreTestSettings
358+
{
359+
NoBuild = true,
360+
NoRestore = true,
361+
Configuration = configuration,
362+
ArgumentCustomization = args => args.Append("-- RunConfiguration.TargetPlatform=x64"),
363+
Filter = "Category=\"Serverless\""
364+
};
365+
switch (target.ToLowerInvariant())
366+
{
367+
case "testserverlessnet452": settings.Framework = "net452"; break;
368+
case "testserverlessnetstandard15": settings.Framework = "netcoreapp1.1"; break;
369+
case "testserverlessnetstandard20": settings.Framework = "netcoreapp2.1"; break;
370+
case "testserverlessnetstandard21": settings.Framework = "netcoreapp3.0"; break;
371+
default: throw new ArgumentException($"Unexpected target: \"{target}\".");
372+
}
373+
DotNetCoreTest(
374+
testProject.FullPath,
375+
settings
376+
);
377+
});
378+
379+
Task("TestServerlessNet452").IsDependentOn("TestServerless");
380+
Task("TestServerlessNetStandard15").IsDependentOn("TestServerless");
381+
Task("TestServerlessNetStandard20").IsDependentOn("TestServerless");
382+
Task("TestServerlessNetStandard21").IsDependentOn("TestServerless");
383+
349384
Task("TestLoadBalanced")
350385
.IsDependentOn("Build")
351386
.DoesForEach(

evergreen/evergreen.yml

Lines changed: 110 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,47 @@ functions:
593593
-v \
594594
--fault revoked
595595
596+
run-serverless-tests:
597+
- command: shell.exec
598+
type: test
599+
params:
600+
working_dir: mongo-csharp-driver
601+
script: |
602+
AUTH=${AUTH} \
603+
COMPRESSOR=${COMPRESSOR} \
604+
FRAMEWORK=${FRAMEWORK} \
605+
MONGODB_URI="${MONGODB_URI}" \
606+
SERVERLESS_ATLAS_USER="${SERVERLESS_ATLAS_USER}" \
607+
SERVERLESS_ATLAS_PASSWORD="${SERVERLESS_ATLAS_PASSWORD}" \
608+
SSL=${SSL} \
609+
evergreen/run-serverless-tests.sh
610+
611+
create-serverless-instance:
612+
- command: shell.exec
613+
params:
614+
script: |
615+
${PREPARE_SHELL}
616+
set +o xtrace # Disable tracing
617+
SERVERLESS_DRIVERS_GROUP=${SERVERLESS_DRIVERS_GROUP} \
618+
SERVERLESS_API_PUBLIC_KEY=${SERVERLESS_API_PUBLIC_KEY} \
619+
SERVERLESS_API_PRIVATE_KEY=${SERVERLESS_API_PRIVATE_KEY} \
620+
bash ${DRIVERS_TOOLS}/.evergreen/serverless/create-instance.sh
621+
- command: expansions.update
622+
params:
623+
file: serverless-expansion.yml
624+
625+
delete-serverless-instance:
626+
- command: shell.exec
627+
params:
628+
script: |
629+
${PREPARE_SHELL}
630+
set +o xtrace # Disable tracing
631+
SERVERLESS_DRIVERS_GROUP=${SERVERLESS_DRIVERS_GROUP} \
632+
SERVERLESS_API_PUBLIC_KEY=${SERVERLESS_API_PUBLIC_KEY} \
633+
SERVERLESS_API_PRIVATE_KEY=${SERVERLESS_API_PRIVATE_KEY} \
634+
SERVERLESS_INSTANCE_NAME=${SERVERLESS_INSTANCE_NAME} \
635+
bash ${DRIVERS_TOOLS}/.evergreen/serverless/delete-instance.sh
636+
596637
publish-snapshot:
597638
- command: shell.exec
598639
type: test
@@ -632,13 +673,15 @@ functions:
632673
- command: shell.exec
633674
params:
634675
script: |
635-
${PREPARE_SHELL}
636-
for i in $(find ${DRIVERS_TOOLS}/.evergreen ${PROJECT_DIRECTORY}/evergreen -name \*.sh); do
637-
cat $i | tr -d '\r' > $i.new
638-
mv $i.new $i
639-
done
640-
# Copy client certificate because symlinks do not work on Windows.
641-
cp ${DRIVERS_TOOLS}/.evergreen/x509gen/client.pem ${MONGO_ORCHESTRATION_HOME}/lib/client.pem
676+
if [ "Windows_NT" = "$OS" ]; then
677+
${PREPARE_SHELL}
678+
for i in $(find ${DRIVERS_TOOLS}/.evergreen ${PROJECT_DIRECTORY}/evergreen -name \*.sh); do
679+
cat $i | tr -d '\r' > $i.new
680+
mv $i.new $i
681+
done
682+
# Copy client certificate because symlinks do not work on Windows.
683+
cp ${DRIVERS_TOOLS}/.evergreen/x509gen/client.pem ${MONGO_ORCHESTRATION_HOME}/lib/client.pem
684+
fi
642685
643686
make-files-executable:
644687
- command: shell.exec
@@ -667,6 +710,7 @@ pre:
667710
post:
668711
# Removed, causing timeouts
669712
# - func: upload-working-dir
713+
- func: delete-serverless-instance
670714
- func: upload-mo-artifacts
671715
- func: upload-test-results
672716
- func: cleanup
@@ -843,6 +887,38 @@ tasks:
843887
commands:
844888
- func: publish-snapshot
845889

890+
- name: test-serverless-net452
891+
exec_timeout_secs: 2700 # 45 minutes: 15 for setup + 30 for tests
892+
commands:
893+
- func: create-serverless-instance
894+
- func: run-serverless-tests
895+
vars:
896+
FRAMEWORK: net452
897+
898+
- name: test-serverless-netstandard15
899+
exec_timeout_secs: 2700 # 45 minutes: 15 for setup + 30 for tests
900+
commands:
901+
- func: create-serverless-instance
902+
- func: run-serverless-tests
903+
vars:
904+
FRAMEWORK: netstandard15
905+
906+
- name: test-serverless-netstandard20
907+
exec_timeout_secs: 2700 # 45 minutes: 15 for setup + 30 for tests
908+
commands:
909+
- func: create-serverless-instance
910+
- func: run-serverless-tests
911+
vars:
912+
FRAMEWORK: netstandard20
913+
914+
- name: test-serverless-netstandard21
915+
exec_timeout_secs: 2700 # 45 minutes: 15 for setup + 30 for tests
916+
commands:
917+
- func: create-serverless-instance
918+
- func: run-serverless-tests
919+
vars:
920+
FRAMEWORK: netstandard21
921+
846922
- name: test-ocsp-rsa-valid-cert-server-staples-ca-responder
847923
tags: ["ocsp"]
848924
commands:
@@ -1440,22 +1516,45 @@ buildvariants:
14401516
tasks:
14411517
- name: plain-auth-tests
14421518

1443-
- matrix_name: tests-load-balancer
1519+
- matrix_name: load-balancer-tests
14441520
matrix_spec: { version: ["5.0", "latest"], auth: "noauth", ssl: "nossl", topology: "sharded-cluster", os: "ubuntu-1804" }
14451521
display_name: "Load Balancer ${version} ${auth} ${ssl} ${os}"
14461522
tasks:
14471523
- name: "test-load-balancer-netstandard15"
14481524
- name: "test-load-balancer-netstandard20"
1449-
- name: "test-load-balancer-netstandard21"
1450-
1451-
- matrix_name: tests-load-balancer-secure
1525+
- name: "test-load-balancer-netstandard21"
1526+
1527+
- matrix_name: load-balancer-tests-secure
14521528
matrix_spec: { version: ["5.0", "latest"], auth: "auth", ssl: "ssl", topology: "sharded-cluster", os: "ubuntu-1804" }
14531529
display_name: "Load Balancer ${version} ${auth} ${ssl} ${os}"
14541530
tasks:
14551531
- name: "test-load-balancer-netstandard15"
14561532
- name: "test-load-balancer-netstandard20"
14571533
- name: "test-load-balancer-netstandard21"
14581534

1535+
- matrix_name: serverless-tests-windows
1536+
matrix_spec: { auth: "auth", ssl: "ssl", compressor: "zlib", os: "windows-64" }
1537+
display_name: "Serverless ${compressor} ${auth} ${ssl} ${os}"
1538+
tasks:
1539+
- name: test-serverless-net452
1540+
- name: test-serverless-netstandard15
1541+
- name: test-serverless-netstandard20
1542+
- name: test-serverless-netstandard21
1543+
1544+
- matrix_name: serverless-tests-macos
1545+
matrix_spec: { auth: "auth", ssl: "ssl", compressor: "zlib", os: "macos-1014" }
1546+
display_name: "Serverless ${compressor} ${auth} ${ssl} ${os}"
1547+
tasks:
1548+
- name: test-serverless-netstandard20
1549+
- name: test-serverless-netstandard21
1550+
1551+
- matrix_name: serverless-tests-ubuntu
1552+
matrix_spec: { auth: "auth", ssl: "ssl", compressor: "zlib", os: "ubuntu-1804" }
1553+
display_name: "Serverless ${compressor} ${auth} ${ssl} ${os}"
1554+
tasks:
1555+
- name: test-serverless-netstandard20
1556+
- name: test-serverless-netstandard21
1557+
14591558
- name: atlas-connectivity-tests
14601559
display_name: "Atlas Connectivity Tests"
14611560
run_on:

evergreen/run-serverless-tests.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bash
2+
3+
# Don't trace since the URI contains a password that shouldn't show up in the logs
4+
set -o errexit # Exit the script with error if any of the commands fail
5+
6+
# Supported/used environment variables:
7+
# AUTH Authentication flag, must be "auth"
8+
# COMPRESSOR Field level compressor, must be set
9+
# FRAMEWORK Used in build.cake "TestServerless" task, must be set
10+
# MONGODB_URI URI with mulpiple mongoses, produced by create-instance.sh script, must be set
11+
# OS Operating system, must be set
12+
# SERVERLESS_ATLAS_USER Authentication user, must be set
13+
# SERVERLESS_ATLAS_PASSWORD Authentiction password, must be set
14+
# SSL TLS connection flag, must be "ssl"
15+
# Modified/exported environment variables:
16+
# MONGODB_URI MONGODB_URI for single host with auth details and TLS and compressor parameters
17+
# MONGODB_URI_WITH_MULTIPLE_MONGOSES MONGODB_URI with auth details and TLS and compressor parameters
18+
# SERVERLESS Flag for the tests, since there's no other way to determine if running serverless
19+
20+
############################################
21+
# Main Program #
22+
############################################
23+
24+
if [[ "$AUTH" != "auth" ]]; then
25+
echo "Serverless tests require AUTH to be enabled"
26+
exit 1
27+
fi
28+
29+
if [ -z "$COMPRESSOR" ]; then
30+
echo "Serverless tests require COMPRESSOR to be configured"
31+
exit 1
32+
fi
33+
34+
if [ -z "$FRAMEWORK" ]; then
35+
echo "Serverless tests require FRAMEWORK to be configured"
36+
exit 1
37+
fi
38+
39+
if [[ "$SSL" != "ssl" ]]; then
40+
echo "Serverless tests require SSL to be enabled"
41+
exit 1
42+
fi
43+
44+
if [ "$OS" = "Windows_NT" ]; then
45+
for var in TMP TEMP NUGET_PACKAGES NUGET_HTTP_CACHE_PATH APPDATA; do
46+
setx $var z:\\data\\tmp
47+
export $var=z:\\data\\tmp
48+
done
49+
else
50+
for var in TMP TEMP NUGET_PACKAGES NUGET_HTTP_CACHE_PATH APPDATA; do
51+
export $var=/data/tmp;
52+
done
53+
fi
54+
55+
MONGODB_URI_SINGLE_HOST=${MONGODB_URI%%,*}
56+
export MONGODB_URI_WITH_MULTIPLE_MONGOSES="mongodb://${SERVERLESS_ATLAS_USER}:${SERVERLESS_ATLAS_PASSWORD}@${MONGODB_URI:10}/?tls=true&authSource=admin&compressors=$COMPRESSOR"
57+
export MONGODB_URI="mongodb://${SERVERLESS_ATLAS_USER}:${SERVERLESS_ATLAS_PASSWORD}@${MONGODB_URI_SINGLE_HOST:10}/?tls=true&authSource=admin&compressors=$COMPRESSOR"
58+
export SERVERLESS="true"
59+
60+
if [ "Windows_NT" = "$OS" ]; then
61+
powershell.exe .\\build.ps1 --target "TestServerless${FRAMEWORK}"
62+
else
63+
./build.sh --target="TestServerless${FRAMEWORK}"
64+
fi

src/MongoDB.Driver.Core/ServerErrorCode.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ internal enum ServerErrorCode
4646
StaleEpoch = 150,
4747
StaleShardVersion = 63,
4848
Unauthorized = 13,
49+
UnauthorizedServerless = 8000,
4950
UnknownReplWriteConcern = 79,
5051
UnsatisfiableWriteConcern = 100,
5152
WriteConcernFailed = 64

tests/MongoDB.Driver.Core.TestHelpers/CoreTestConfiguration.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public static class CoreTestConfiguration
4646
private static Lazy<BuildInfoResult> _buildInfo = new Lazy<BuildInfoResult>(RunBuildInfo, isThreadSafe: true);
4747
private static MessageEncoderSettings __messageEncoderSettings = new MessageEncoderSettings();
4848
private static Lazy<ServerApi> __serverApi = new Lazy<ServerApi>(GetServerApi, isThreadSafe: true);
49+
private static Lazy<bool> __serverless = new Lazy<bool>(GetServerless, isThreadSafe: true);
4950
private static TraceSource __traceSource;
5051

5152
// static properties
@@ -84,6 +85,11 @@ public static ServerApi ServerApi
8485
get { return __serverApi.Value; }
8586
}
8687

88+
public static bool Serverless
89+
{
90+
get { return __serverless.Value; }
91+
}
92+
8793
public static SemanticVersion ServerVersion
8894
{
8995
get
@@ -299,6 +305,13 @@ private static ServerApi GetServerApi()
299305
return new ServerApi(ServerApiVersion.V1);
300306
}
301307

308+
private static bool GetServerless()
309+
{
310+
var serverless = Environment.GetEnvironmentVariable("SERVERLESS");
311+
312+
return serverless?.ToLower() == "true";
313+
}
314+
302315
public static DatabaseNamespace GetDatabaseNamespaceForTestClass(Type testClassType)
303316
{
304317
var databaseName = TruncateDatabaseNameIfTooLong(__databaseNamespace.Value.DatabaseName + "-" + testClassType.Name);

0 commit comments

Comments
 (0)