Skip to content

Commit 666bb25

Browse files
authored
RCORE-1928 Use baasaas for baas integration tests in CI (#7423)
1 parent e4b64e8 commit 666bb25

File tree

13 files changed

+497
-164
lines changed

13 files changed

+497
-164
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
-----------
1717

1818
### Internals
19-
* None.
19+
* The CMake option `REALM_MONGODB_ENDPOINT` for running the object-store-tests against baas has been deprecated in favor of an environment variable of the same name ([PR #7423](https://github.com/realm/realm-core/pull/7423)).
20+
* The object-store-tests test suite can now launch baas containers on its own by specifying a `BAASAAS_API_KEY` in the environment ([PR #7423](https://github.com/realm/realm-core/pull/7423)).
2021

2122
----------------------------------------------
2223

dependencies.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ VERSION: 14.2.0
33
OPENSSL_VERSION: 3.2.0
44
ZLIB_VERSION: 1.2.13
55
# https://github.com/10gen/baas/commits
6-
# dd016 is 2024 Feb 22
7-
BAAS_VERSION: dd01629d83b86292af9c59ebe2a28673c2e559cf
6+
# acb71d0 is 2024 Mar 12
7+
BAAS_VERSION: acb71d0183b33eb304bb496390567efcfb8a6e60

evergreen/config.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ functions:
7878
if [ -z "${disable_tests_against_baas|}" ]; then
7979
scheme="http"
8080
set_cmake_var baas_vars REALM_ENABLE_AUTH_TESTS BOOL On
81-
set_cmake_var baas_vars REALM_MONGODB_ENDPOINT STRING "$scheme://localhost:9090"
8281
if [ -n "${baas_admin_port|}" ]; then
8382
set_cmake_var baas_vars REALM_ADMIN_ENDPOINT STRING "$scheme://localhost:${baas_admin_port}"
8483
fi
@@ -156,7 +155,7 @@ functions:
156155
if [ -n "${curl_base|}" ]; then
157156
set_cmake_var curl_vars CURL_LIBRARY PATH "$(./evergreen/abspath.sh ${curl_base}/lib/libcurl.dll.a)"
158157
set_cmake_var curl_vars CURL_INCLUDE_DIR PATH "$(./evergreen/abspath.sh ${curl_base}/include)"
159-
set_cmake_var baas_vars REALM_CURL_CACERTS PATH "$(./evergreen/abspath.sh "${curl_base}/bin/cacert.pem")"
158+
set_cmake_var baas_vars REALM_CURL_CACERTS PATH "$(./evergreen/abspath.sh "${curl_base}/bin/curl-ca-bundle.crt")"
160159
fi
161160
162161
set_cmake_var realm_vars REALM_NO_TESTS BOOL ${no_tests|Off}
@@ -208,10 +207,17 @@ functions:
208207
file: './realm-core/benchmark_results/results.latest.json'
209208

210209
"run tests":
210+
- command: expansions.update
211+
params:
212+
file: realm-core/dependencies.yml
211213
- command: shell.exec
212214
params:
213215
working_dir: realm-core
214216
shell: bash
217+
env:
218+
BAASAAS_API_KEY: "${baasaas_api_key}"
219+
BAASAAS_REF_SPEC: "${BAAS_VERSION}"
220+
BAASAAS_START_MODE: "githash"
215221
script: |-
216222
set -o errexit
217223
set -o verbose
@@ -244,6 +250,12 @@ functions:
244250
245251
TEST_FLAGS="--no-tests=error $TEST_FLAGS ${test_flags|}"
246252
253+
if [[ -n "${disable_tests_against_baas|}" ]]; then
254+
unset BAASAAS_API_KEY
255+
unset BAASAAS_REF_SPEC
256+
unset BAASAAS_START_MODE
257+
fi
258+
247259
if [[ -n "${llvm_symbolizer}" ]]; then
248260
export ASAN_SYMBOLIZER_PATH="$(./evergreen/abspath.sh ${llvm_symbolizer})"
249261
fi
@@ -977,18 +989,17 @@ tasks:
977989
test_label: objstore-local
978990
test_executable_name: "realm-object-store-tests"
979991
verbose_test_output: true
992+
disable_tests_against_baas: true
980993
- func: "check branch state"
981994

982995
# These are baas object store tests that run against baas running on a remote host
983996
- name: baas-integration-tests
984997
tags: [ "test_suite", "for_pull_requests", "requires_baas" ]
985998
exec_timeout_secs: 3600
986999
commands:
987-
- func: "launch remote baas"
9881000
- func: "compile"
9891001
vars:
9901002
target_to_build: ObjectStoreTests
991-
- func: "wait for remote baas to start"
9921003
- func: "run tests"
9931004
vars:
9941005
test_label: objstore-baas

how-to-build.md

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -145,39 +145,41 @@ These are the available variables:
145145
testing process as soon as a check fails or an unexpected exception is thrown
146146
in a test.
147147

148-
## Running [app] tests against a local MongoDB BAAS
149-
150-
Due to MongoDB security policies, running baas requires company issued AWS account credentials.
151-
These are for MongoDB employees only, if you do not have these, reach out to #realm-core.
152-
Once you have them, they need to be set in the shell environment.
153-
154-
First, log in to aws using their command line tool. On mac this requries `brew install awscli`.
155-
Then login using `aws configure` and input your access key and secret acess key. The other
156-
configuration options can be left as none. This creates a correctly formatted file locally at
157-
`~/.aws/credentials` which we will use later.
158-
159-
If you do not want to install the aws command line tools, you can also create the aws file
160-
manually in the correct location (`~/.aws/credentials`) with the following contents:
148+
## Running [app] tests against a local BAAS instance
161149

150+
If you already have a baas instance running, you can specify that directly via the
151+
`BAAS_BASE_URL` environment variable. You can run baas in a local docker container using
152+
instructions from [the wiki](https://wiki.corp.mongodb.com/display/10GEN/%28Device+Sync%29+Using+Docker+to+run+a+BAAS+server+instance).
162153
```
163-
AWS_ACCESS_KEY_ID = <your-key-id>
164-
AWS_SECRET_ACCESS_KEY = <your-secret-key>
154+
export BAAS_BASE_URL=http://localhost:9090
155+
mkdir build.sync.ninja
156+
cmake -B build.sync.ninja -G Ninja -DREALM_ENABLE_AUTH_TESTS=1
157+
cmake --build build.sync.ninja --target realm-object-store-tests
158+
./build.sync.ninja/test/object-store/realm-object-store-tests -d=1
165159
```
166160

167-
We use a script to fetch the dependencies for and run baas locally. Use the `-b sha` to use a particular version from https://github.com/10gen/baas/
168-
The script uses the configuration from https://github.com/10gen/baas/blob/master/etc/configs/test_rcore_config.json
161+
## Running [app] tests against an on-demand BAASAAS container
169162

163+
Due to MongoDB security policies, running baas requires company issued credentials.
164+
These are for MongoDB employees only, if you do not have these, reach out to
165+
#appx-device-sync-internal. Once you have a baasaas API key, it needs to be set
166+
in the shell environment.
170167
```
171-
./evergreen/install_baas.sh -w baas
172-
```
173-
174-
To run the [app] tests against the local baas, you need to configure a build with some cmake options to tell the tests where to point to.
175-
```
168+
export BAASAAS_API_KEY=<your API key here>
176169
mkdir build.sync.ninja
177-
cmake -B build.sync.ninja -G Ninja -DREALM_ENABLE_AUTH_TESTS=1 -DREALM_MONGODB_ENDPOINT=http://localhost:9090
170+
cmake -B build.sync.ninja -G Ninja -DREALM_ENABLE_AUTH_TESTS=1
178171
cmake --build build.sync.ninja --target realm-object-store-tests
179172
./build.sync.ninja/test/object-store/realm-object-store-tests -d=1
180173
```
174+
You can tell the object-store tests to use a specific version of baas with the
175+
`BAASAAS_START_MODE` environment variable, which can either be `githash`, `patchid`,
176+
or `branch`. If you specify a start mode, you need to tell it which githash or
177+
branch name to start with via the `BAASAAS_REF_SPEC` environment variable. Omitting
178+
these will use the latest available commit from the main branch of baas.
179+
180+
If you've started a baasaas container already via the baasaas CLI, you can tell
181+
the object-store tests to use that with the `BAASAAS_INSTANCE_ID` environment variable.
182+
181183

182184
### Developing inside a container
183185

test/object-store/CMakeLists.txt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ endif()
9292
target_link_libraries(ObjectStoreTestLib Catch2::Catch2 ObjectStore RealmFFIStatic TestUtil)
9393
enable_stdfilesystem(ObjectStoreTestLib)
9494

95+
if(REALM_CURL_CACERTS)
96+
target_compile_definitions(ObjectStoreTestLib PRIVATE
97+
REALM_CURL_CACERTS="${REALM_CURL_CACERTS}"
98+
)
99+
endif()
100+
95101
add_executable(ObjectStoreTests main.cpp ${RESOURCES})
96102
set_target_properties(ObjectStoreTests PROPERTIES OUTPUT_NAME realm-object-store-tests)
97103
target_link_libraries(ObjectStoreTests ObjectStoreTestLib TestUtil)
@@ -131,16 +137,17 @@ if(REALM_ENABLE_SYNC)
131137
target_link_libraries(ObjectStoreTestLib SyncServer)
132138
option(REALM_ENABLE_AUTH_TESTS "" OFF)
133139
if(REALM_ENABLE_AUTH_TESTS)
134-
if(NOT REALM_MONGODB_ENDPOINT)
135-
message(FATAL_ERROR "REALM_MONGODB_ENDPOINT must be set when specifying REALM_ENABLE_AUTH_TESTS.")
136-
endif()
137-
138-
message(STATUS "Auth tests enabled: ${REALM_MONGODB_ENDPOINT}")
139140
target_compile_definitions(ObjectStoreTestLib PRIVATE
140141
REALM_ENABLE_AUTH_TESTS=1
141-
REALM_MONGODB_ENDPOINT="${REALM_MONGODB_ENDPOINT}"
142142
)
143143

144+
if(REALM_MONGODB_ENDPOINT)
145+
message(STATUS "Auth tests enabled: ${REALM_MONGODB_ENDPOINT}")
146+
target_compile_definitions(ObjectStoreTestLib PRIVATE
147+
REALM_MONGODB_ENDPOINT="${REALM_MONGODB_ENDPOINT}"
148+
)
149+
endif()
150+
144151
if(REALM_ADMIN_ENDPOINT)
145152
message(STATUS "BAAS admin endpoint: ${REALM_ADMIN_ENDPOINT}")
146153
target_compile_definitions(ObjectStoreTests PRIVATE

test/object-store/sync/app.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3924,7 +3924,6 @@ TEST_CASE("app: base_url", "[sync][app][base_url]") {
39243924
std::unique_ptr<realm::AppSession> app_session;
39253925
auto redir_transport = std::make_shared<BaseUrlTransport>();
39263926
AutoVerifiedEmailCredentials creds;
3927-
util::LogCategory::realm.set_default_level_threshold(realm::util::Logger::Level::TEST_LOGGING_LEVEL);
39283927
auto logger = util::Logger::get_default_logger();
39293928

39303929
App::Config app_config = {"fake-app-id"};

test/object-store/test_runner.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <util/test_path.hpp>
2121

2222
#include <realm/util/features.h>
23+
#include <realm/util/logger.hpp>
2324
#include <realm/util/to_string.hpp>
2425

2526
#if TEST_SCHEDULER_UV
@@ -38,6 +39,76 @@
3839
#include <iostream>
3940
#include <limits.h>
4041

42+
#ifndef TEST_ENABLE_LOGGING
43+
#define TEST_ENABLE_LOGGING 0 // change to 1 to enable trace-level logging
44+
#endif
45+
46+
#ifndef TEST_LOGGING_LEVEL
47+
#if TEST_ENABLE_LOGGING
48+
#define TEST_LOGGING_LEVEL all
49+
#else
50+
#define TEST_LOGGING_LEVEL off
51+
#endif // TEST_ENABLE_LOGGING
52+
#endif // TEST_LOGGING_LEVEL
53+
54+
#define TEST_LOGGING_LEVEL_STORAGE off
55+
#define TEST_LOGGING_LEVEL_SERVER off
56+
/*
57+
#define TEST_LOGGING_LEVEL_SYNC off
58+
#define TEST_LOGGING_LEVEL_RESET trace
59+
#define TEST_LOGGING_LEVEL_APP off
60+
*/
61+
62+
static std::vector<std::pair<std::string_view, realm::util::Logger::Level>> default_log_levels = {
63+
{"Realm", realm::util::Logger::Level::TEST_LOGGING_LEVEL},
64+
#ifdef TEST_LOGGING_LEVEL_STORAGE
65+
{"Realm.Storage", realm::util::Logger::Level::TEST_LOGGING_LEVEL_STORAGE},
66+
#endif
67+
#ifdef TEST_LOGGING_LEVEL_TRANSACTION
68+
{"Realm.Storage.Transaction", realm::util::Logger::Level::TEST_LOGGING_LEVEL_TRANSACTION},
69+
#endif
70+
#ifdef TEST_LOGGING_LEVEL_QUERY
71+
{"Realm.Storage.Query", realm::util::Logger::Level::TEST_LOGGING_LEVEL_QUERY},
72+
#endif
73+
#ifdef TEST_LOGGING_LEVEL_OBJECT
74+
{"Realm.Storage.Object", realm::util::Logger::Level::TEST_LOGGING_LEVEL_OBJECT},
75+
#endif
76+
#ifdef TEST_LOGGING_LEVEL_NOTIFICATION
77+
{"Realm.Storage.Notification", realm::util::Logger::Level::TEST_LOGGING_LEVEL_NOTIFICATION},
78+
#endif
79+
#ifdef TEST_LOGGING_LEVEL_SYNC
80+
{"Realm.Sync", realm::util::Logger::Level::TEST_LOGGING_LEVEL_SYNC},
81+
#endif
82+
#ifdef TEST_LOGGING_LEVEL_CLIENT
83+
{"Realm.Sync.Client", realm::util::Logger::Level::TEST_LOGGING_LEVEL_CLIENT},
84+
#endif
85+
#ifdef TEST_LOGGING_LEVEL_SESSION
86+
{"Realm.Sync.Client.Session", realm::util::Logger::Level::TEST_LOGGING_LEVEL_SESSION},
87+
#endif
88+
#ifdef TEST_LOGGING_LEVEL_CHANGESET
89+
{"Realm.Sync.Client.Changeset", realm::util::Logger::Level::TEST_LOGGING_LEVEL_CHANGESET},
90+
#endif
91+
#ifdef TEST_LOGGING_LEVEL_NETWORK
92+
{"Realm.Sync.Client.Network", realm::util::Logger::Level::TEST_LOGGING_LEVEL_NETWORK},
93+
#endif
94+
#ifdef TEST_LOGGING_LEVEL_RESET
95+
{"Realm.Sync.Client.Reset", realm::util::Logger::Level::TEST_LOGGING_LEVEL_RESET},
96+
#endif
97+
#ifdef TEST_LOGGING_LEVEL_SERVER
98+
{"Realm.Sync.Server", realm::util::Logger::Level::TEST_LOGGING_LEVEL_SERVER},
99+
#endif
100+
#ifdef TEST_LOGGING_LEVEL_APP
101+
{"Realm.App", realm::util::Logger::Level::TEST_LOGGING_LEVEL_APP},
102+
#endif
103+
};
104+
105+
static void set_default_level_thresholds()
106+
{
107+
for (auto [cat, level] : default_log_levels) {
108+
realm::util::LogCategory::get_category(cat).set_default_level_threshold(level);
109+
}
110+
}
111+
41112

42113
int run_object_store_tests(int argc, const char** argv);
43114

@@ -91,6 +162,8 @@ int run_object_store_tests(int argc, const char** argv)
91162
});
92163
#endif
93164

165+
set_default_level_thresholds();
166+
94167
Catch::Session session;
95168
session.useConfigData(config);
96169
int result = session.run(argc, argv);

0 commit comments

Comments
 (0)