Skip to content

Commit c359e60

Browse files
authored
Update to latest BAAS test server. (#7601)
1 parent 7db3401 commit c359e60

File tree

4 files changed

+65
-17
lines changed

4 files changed

+65
-17
lines changed

Jenkinsfile

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,17 @@ try {
121121

122122
// Prepare Docker containers used by Instrumentation tests
123123
// TODO: How much of this logic can be moved to start_server.sh for shared logic with local testing.
124-
125-
def tempDir = runCommand('mktemp -d -t app_config.XXXXXXXXXX')
126-
sh "tools/sync_test_server/app_config_generator.sh ${tempDir} tools/sync_test_server/app_template testapp1 testapp2"
127-
128-
sh "docker network create ${dockerNetworkId}"
129-
mongoDbRealmContainer = mdbRealmImage.run("--network ${dockerNetworkId} -v$tempDir:/apps")
130-
mongoDbRealmCommandServerContainer = commandServerEnv.run("--network container:${mongoDbRealmContainer.id} -v$tempDir:/apps")
131-
sh "timeout 60 sh -c \"while [[ ! -f $tempDir/testapp1/app_id || ! -f $tempDir/testapp2/app_id ]]; do echo 'Waiting for server to start'; sleep 1; done\""
124+
withCredentials([
125+
[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'realm-kotlin-baas-aws-credentials', accessKeyVariable: 'BAAS_AWS_ACCESS_KEY_ID', secretKeyVariable: 'BAAS_AWS_SECRET_ACCESS_KEY']
126+
]) {
127+
def tempDir = runCommand('mktemp -d -t app_config.XXXXXXXXXX')
128+
sh "tools/sync_test_server/app_config_generator.sh ${tempDir} tools/sync_test_server/app_template testapp1 testapp2"
129+
130+
sh "docker network create ${dockerNetworkId}"
131+
mongoDbRealmContainer = mdbRealmImage.run("--network ${dockerNetworkId} -v$tempDir:/apps -e AWS_ACCESS_KEY_ID='$BAAS_AWS_ACCESS_KEY_ID' -e AWS_SECRET_ACCESS_KEY='$BAAS_AWS_SECRET_ACCESS_KEY'")
132+
mongoDbRealmCommandServerContainer = commandServerEnv.run("--network container:${mongoDbRealmContainer.id} -v$tempDir:/apps")
133+
sh "timeout 60 sh -c \"while [[ ! -f $tempDir/testapp1/app_id || ! -f $tempDir/testapp2/app_id ]]; do echo 'Waiting for server to start'; sleep 1; done\""
134+
}
132135
}
133136

134137
// There is a chance that real devices are attached to the host, so if the emulator is

dependencies.list

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ REALM_CORE=11.6.0
44

55
# Version of MongoDB Realm used by integration tests
66
# See https://github.com/realm/ci/packages/147854 for available versions
7-
MONGODB_REALM_SERVER=2021-04-22
7+
MONGODB_REALM_SERVER=2021-11-28
88

99
# Common Android settings across projects
1010
GRADLE_BUILD_TOOLS=7.1.0-beta03

realm/realm-library/src/androidTestObjectServer/kotlin/io/realm/admin/ServerAdmin.kt

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.realm.admin
22

3+
import android.os.SystemClock
34
import io.realm.log.LogLevel
45
import io.realm.log.RealmLog
56
import io.realm.mongodb.App
@@ -100,28 +101,55 @@ class ServerAdmin(private val app: App) {
100101
*/
101102
fun setAutomaticConfirmation(enabled: Boolean) {
102103
val providerId: String = getLocalUserPassProviderId()
104+
val url = "$baseUrl/groups/$groupId/apps/$appId/auth_providers/$providerId"
103105
var request = Request.Builder()
104-
.url("$baseUrl/groups/$groupId/apps/$appId/auth_providers/$providerId")
106+
.url(url)
105107
.get()
106108
val authProviderConfig = JSONObject(executeRequest(request, true))
107109
authProviderConfig.getJSONObject("config").apply {
108110
put("autoConfirm", enabled)
109-
put("emailConfirmationUrl", "http://realm.io/confirm-user")
110111
}
111112
// Change autoConfirm and update the provider
112113
request = Request.Builder()
113-
.url("$baseUrl/groups/$groupId/apps/$appId/auth_providers/$providerId")
114+
.url(url)
114115
.patch(RequestBody.create(json, authProviderConfig.toString()))
115-
executeRequest(request)
116+
executeRequest(request, true)
117+
118+
request = Request.Builder()
119+
.url(url)
120+
.get()
121+
val config = JSONObject(executeRequest(request, true))
122+
RealmLog.error("SetAutomaticConfirmation($enabled): ${config.toString(4)}")
123+
waitForDeployment()
124+
}
125+
126+
private fun waitForDeployment() {
127+
// TODO Attempt to work-around, what looks like a race condition on the server deploying
128+
// changes to the server. Even though the /deployments endpoint report success, it seems
129+
// like the change hasn't propagated fully. This usually surfaces as registerUser errors
130+
// where it tries to use the customFunc instead of automatically registering.
131+
val url = "$baseUrl/groups/$groupId/apps/$appId/deployments"
132+
var request = Request.Builder()
133+
.url(url)
134+
.get()
135+
val deployments = JSONArray(executeRequest(request, true))
136+
val dep = deployments[0] as JSONObject
137+
if (dep.getString("status") != "successful") {
138+
RealmLog.error("Failed to deploy: ${dep.toString(4)}")
139+
}
140+
141+
// Work-around for /deployments reporting success, but /register still failing.
142+
SystemClock.sleep(5000)
116143
}
117144

118145
/**
119146
* Toggle whether or not custom confirmation functions are enabled.
120147
*/
121148
fun setCustomConfirmation(enabled: Boolean) {
122149
val providerId: String = getLocalUserPassProviderId()
150+
val url = "$baseUrl/groups/$groupId/apps/$appId/auth_providers/$providerId"
123151
var request = Request.Builder()
124-
.url("$baseUrl/groups/$groupId/apps/$appId/auth_providers/$providerId")
152+
.url(url)
125153
.get()
126154
val authProviderConfig = JSONObject(executeRequest(request, true))
127155

@@ -131,9 +159,16 @@ class ServerAdmin(private val app: App) {
131159
}
132160
// Change autoConfirm and update the provider
133161
request = Request.Builder()
134-
.url("$baseUrl/groups/$groupId/apps/$appId/auth_providers/$providerId")
162+
.url(url)
135163
.patch(RequestBody.create(json, authProviderConfig.toString()))
136-
executeRequest(request)
164+
executeRequest(request, true)
165+
166+
request = Request.Builder()
167+
.url(url)
168+
.get()
169+
val config = JSONObject(executeRequest(request, true))
170+
RealmLog.error("setCustomConfirmation($enabled): ${config.toString(4)}")
171+
waitForDeployment()
137172
}
138173

139174
val JSON = MediaType.parse("application/json; charset=utf-8")
@@ -240,4 +275,5 @@ class ServerAdmin(private val app: App) {
240275
val result = JSONObject(executeRequest(builder))
241276
return result.getString("key")
242277
}
278+
243279
}

tools/sync_test_server/start_server.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@ $SCRIPTPATH/app_config_generator.sh $APP_CONFIG_DIR $SCRIPTPATH/app_template tes
4343
# Run Stitch and Stitch CLI Docker images
4444
docker network create mongodb-realm-network
4545
docker build $DOCKERFILE_DIR -t mongodb-realm-command-server || { echo "Failed to build Docker image." ; exit 1 ; }
46-
ID=$(docker run --rm -i -t -d -v$APP_CONFIG_DIR:/apps --network mongodb-realm-network -p9090:9090 -p8888:8888 -p26000:26000 --name mongodb-realm docker.pkg.github.com/realm/ci/mongodb-realm-test-server:$MONGODB_REALM_VERSION)
46+
ID=$(docker run --rm -i -t -d -v$APP_CONFIG_DIR:/apps \
47+
--network mongodb-realm-network \
48+
-p9090:9090 \
49+
-p8888:8888 \
50+
-p26000:26000 \
51+
--name mongodb-realm \
52+
-e AWS_ACCESS_KEY_ID="${BAAS_AWS_ACCESS_KEY_ID}" \
53+
-e AWS_SECRET_ACCESS_KEY="${BAAS_AWS_SECRET_ACCESS_KEY}" \
54+
docker.pkg.github.com/realm/ci/mongodb-realm-test-server:$MONGODB_REALM_VERSION \
55+
)
4756
docker run --rm -i -t -d --network container:$ID -v$APP_CONFIG_DIR:/apps --name mongodb-realm-command-server mongodb-realm-command-server
4857

4958
echo "Template apps are generated in/served from $APP_CONFIG_DIR"

0 commit comments

Comments
 (0)