Skip to content

Commit 0606510

Browse files
committed
CXX-500 Only start mongo-orchestration from Scons when running examples
1 parent 38257f7 commit 0606510

File tree

3 files changed

+84
-69
lines changed

3 files changed

+84
-69
lines changed

SConstruct

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1837,7 +1837,6 @@ Export("darwin windows solaris linux freebsd nix")
18371837
Export("debugBuild optBuild")
18381838
Export("use_clang")
18391839

1840-
env.SConscript('src/SConscript.client', variant_dir='$VARIANT_DIR', duplicate=False)
18411840
env.SConscript('src/SConscript', variant_dir='$VARIANT_DIR', duplicate=False)
18421841

18431842
# --- Coverage ---

src/SConscript

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
#
33
# This is the principle SConscript file, invoked by the SConstruct. Its job is
44
# to delegate to any and all per-module SConscript files.
5-
65
Import('env')
76

8-
env.SConscript([
9-
'third_party/SConscript',
10-
'mongo/SConscript',
11-
])
7+
env.SConscript('third_party/SConscript')
8+
env.SConscript('SConscript.client')
9+
env.SConscript('mongo/SConscript')

src/SConscript.client

Lines changed: 81 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
# This SConscript describes build and install rules for the Mongo C++ driver and associated exmaple
44
# programs.
5-
import os
5+
import buildscripts.git
66
import httplib
7-
import urllib
87
import json
8+
import os
99
import re
1010
import time
11-
import buildscripts.git
11+
import urllib
1212

1313
Import('env has_option get_option')
1414
Import('nix linux darwin windows')
@@ -545,74 +545,92 @@ clientEnv.Alias('build-examples', clientTestPrograms)
545545

546546
clientTestProgramInstalls = staticClientProgramInstalls + sharedClientProgramInstalls
547547

548-
# TODO: Make this more Scons-like with an action target that causes
549-
# a server to come into being and then have each test depend on it.
550-
orchestration_uri = "%s:%s" % (clientEnv.GetOption("mongo-orchestration-host"),
551-
clientEnv.GetOption("mongo-orchestration-port"))
552-
json_headers = { "Content-Type": "application/json" }
553-
554-
params = json.dumps({
555-
"id": "standalone",
556-
"name": "mongod",
557-
"preset": clientEnv.GetOption("mongo-orchestration-preset")
558-
})
559-
560-
# Check if a standalone mongod is already up, resetting if it is
561-
MO_MAX_RETRIES = 10
562-
for attempt in range(1, MO_MAX_RETRIES+1):
563-
564-
if attempt > 1:
565-
# don't sleep before first attempt
566-
time.sleep(1)
567-
568-
try:
569-
conn = httplib.HTTPConnection(orchestration_uri, timeout=30)
570-
conn.request("GET", "/servers/standalone", headers=json_headers)
571-
response = conn.getresponse()
572-
message = response.read()
573-
574-
except IOError:
575-
print("Cannot connect to Mongo Orchestration at %s on attempt %d. %d attempts remaining..."
576-
% (orchestration_uri, attempt, MO_MAX_RETRIES - (attempt)))
577-
continue
548+
mongoDBUri = str()
549+
def getMongoDBUri():
550+
return mongoDBUri
551+
clientEnv['getMongoDBUri'] = getMongoDBUri
578552

579-
if (response.status == 404):
580-
print("No standalone started, starting one now...")
581-
post_conn = httplib.HTTPConnection(orchestration_uri, timeout=30)
582-
post_conn.request("POST", "/servers", params, json_headers)
583-
continue
584-
elif (response.status/100 != 2):
585-
print("Mongo Orchestration had an error with code %s" % response.status)
586-
if message:
587-
print("\tmessage from MO: %s", message)
588-
continue
553+
def setupMongoOrchestration(target, source, env):
554+
555+
orchestration_uri = "%s:%s" % (env.GetOption("mongo-orchestration-host"),
556+
env.GetOption("mongo-orchestration-port"))
557+
json_headers = { "Content-Type": "application/json" }
558+
559+
params = json.dumps({
560+
"id": "standalone",
561+
"name": "mongod",
562+
"preset": env.GetOption("mongo-orchestration-preset")
563+
})
564+
565+
# Check if a standalone mongod is already up, resetting if it is
566+
MO_MAX_RETRIES = 10
567+
for attempt in range(1, MO_MAX_RETRIES+1):
589568

590-
# Grab the port from the response -- use it in the tests
591-
decoded_response = json.loads(message)
592-
mongodb_uri = decoded_response['mongodb_uri']
569+
if attempt > 1:
570+
# don't sleep before first attempt
571+
time.sleep(1)
593572

594-
for clientTest in clientTestProgramInstalls:
573+
try:
574+
conn = httplib.HTTPConnection(orchestration_uri, timeout=30)
575+
conn.request("GET", "/servers/standalone", headers=json_headers)
576+
response = conn.getresponse()
577+
message = response.read()
595578

596-
# On windows, the installs also install PDB files, which we end up picking up.
597-
# Obviously, we can't run those, so filter them out. Lets hope nobody creates
598-
# a new client test with pdb in the name.
599-
if clientTest.abspath.endswith('.pdb'):
579+
except IOError:
580+
print("Cannot connect to Mongo Orchestration at %s on attempt %d. %d attempts remaining..."
581+
% (orchestration_uri, attempt, MO_MAX_RETRIES - (attempt)))
600582
continue
601583

602-
# the rsExample test needs a replica set to talk to. The old smokeClient never tested it
603-
# The old smoke subsystem did test authTest, not sure why it isn't working now.
604-
if 'rsExample' in clientTest.abspath:
584+
if (response.status == 404):
585+
print("No standalone started, starting one now...")
586+
post_conn = httplib.HTTPConnection(orchestration_uri, timeout=30)
587+
post_conn.request("POST", "/servers", params, json_headers)
588+
continue
589+
elif (response.status/100 != 2):
590+
print("Mongo Orchestration had an error with code %s" % response.status)
591+
if message:
592+
print("\tmessage from MO: %s", message)
605593
continue
606594

607-
clientEnv.AlwaysBuild(
608-
clientEnv.Alias(
609-
'examples',
610-
[clientTest],
611-
"%s %s" % (clientTest.abspath, mongodb_uri)
612-
)
613-
)
595+
# Grab the port from the response -- use it in the tests
596+
decoded_response = json.loads(message)
597+
598+
global mongoDBUri
599+
mongoDBUri = decoded_response['mongodb_uri']
600+
601+
# The last attempt succeeded so we don't need to keep trying
602+
break
603+
604+
clientEnv.Alias('setup-mongo-orchestration',
605+
clientEnv.Command(
606+
target="#setup-mongo-orchestration",
607+
source=[],
608+
action=clientEnv.Action(
609+
setupMongoOrchestration,
610+
cmdstr="Configuring MongoOrchestration for Examples")
611+
))
612+
613+
for clientTest in clientTestProgramInstalls:
614+
615+
# On windows, the installs also install PDB files, which we end up picking up.
616+
# Obviously, we can't run those, so filter them out. Lets hope nobody creates
617+
# a new client test with pdb in the name.
618+
if clientTest.abspath.endswith('.pdb'):
619+
continue
620+
621+
# the rsExample test needs a replica set to talk to. The old smokeClient never tested it
622+
# The old smoke subsystem did test authTest, not sure why it isn't working now.
623+
if 'rsExample' in clientTest.abspath:
624+
continue
625+
626+
command = clientEnv.Command(
627+
target="${SOURCE}-run",
628+
source=[clientTest],
629+
action="$SOURCE ${getMongoDBUri()}")
614630

615-
# The last attempt succeeded so we don't need to keep trying
616-
break
631+
clientEnv.SideEffect("#example-running", command)
632+
clientEnv.AlwaysBuild(command)
633+
clientEnv.Depends(command, 'setup-mongo-orchestration')
634+
clientEnv.Alias('examples', command)
617635

618636
clientEnv.Alias('install-examples', clientTestProgramInstalls)

0 commit comments

Comments
 (0)