Skip to content

Commit

Permalink
Use baasaas on CI (#1441)
Browse files Browse the repository at this point in the history
* Use baasaas on CI

* Remove dependency on realm in the baas client

* Regenerate models

* Cleanup containers after test runs

* Fix CI

* Try setting the baas url correctly

* Fix order of test setup

* ..

* Add some missing flutter tests

* Try to fix flutter tests

* Rework indexed test to use values from the second half of the table.

* Use api key auth

* Post-merge fixes

* Use endpoints, wire-up differentiator tag

* Guard against incomplete containers

* Fix cleanup workflow; fix env variable names

* Don't log isolate warnings when the isolate is created by dart test

* Pass correct differentiator to android tests

* Always run cleanup

* Rework cleanup command

* Use reporter

* Don't fail test run on test errors

* Fail on error

* Remove failing test

* Update lib/src/cli/atlas_apps/options.dart

Co-authored-by: Kasper Overgård Nielsen <[email protected]>

* Support maps (#1406)

* Update generator to support maps

* Generator updates

* Better error message for wrong key type

* Remove the default value lists

* Add tests for non-empty default collection initializers

* Wire up some of the implementation

* Wire up most of the test infrastructure

* Add notification tests

* Fix generator test expects

* Fix tests

* Add changelog, clean up the generator a little

* Revert some unneeded changes

* Fix expectations

---------

Co-authored-by: Nikola Irinchev <[email protected]>

* Merge main, regenerate cli

---------

Co-authored-by: Kasper Overgård Nielsen <[email protected]>
  • Loading branch information
nirinchev and nielsenko authored Jan 3, 2024
1 parent 7fa4600 commit 9b947ff
Show file tree
Hide file tree
Showing 23 changed files with 866 additions and 853 deletions.
539 changes: 204 additions & 335 deletions .github/workflows/ci.yml

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions .github/workflows/cleanup-clusters.yml

This file was deleted.

49 changes: 0 additions & 49 deletions .github/workflows/create-cluster.yml

This file was deleted.

40 changes: 14 additions & 26 deletions .github/workflows/dart-desktop-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,21 @@ on:
description: Architecture to execute on.
required: false
type: string
app:
description: App name prefix.
required: true
type: string
cluster:
description: Cluster name to deploy.
differentiator:
description: Differentiator for the BaaS container.
required: true
type: string

env:
BAAS_URL: ${{ secrets.REALM_QA_URL }}
BAAS_API_KEY: ${{ secrets.ATLAS_QA_PUBLIC_API_KEY }}
BAAS_PRIVATE_API_KEY: ${{ secrets.ATLAS_QA_PRIVATE_API_KEY }}
BAAS_PROJECT_ID: ${{ secrets.ATLAS_QA_PROJECT_ID}}
REALM_CI: true
BAAS_BAASAAS_API_KEY: ${{ secrets.BAASAAS_API_KEY}}
BAAS_DIFFERENTIATOR: ${{ inputs.differentiator }}

jobs:
dart-tests:
runs-on: ${{ inputs.runner }}
name: Dart tests on ${{inputs.os }} ${{ inputs.architecture }}
timeout-minutes: 45
env:
BAAS_CLUSTER: ${{ inputs.cluster }}
BAAS_DIFFERENTIATOR: ${{ inputs.app }}${{ github.run_id }}${{ github.run_attempt }}

steps:
- name: Checkout
Expand Down Expand Up @@ -68,20 +59,17 @@ jobs:
run: ulimit -n 10240
if: ${{ contains(inputs.os, 'macos') }}

# This will be a no-op under normal circumstances since the cluster would have been deployed
# in deploy-cluster. It is needed in case we want to re-run the job after the cluster has been reaped.
- name: Create cluster
uses: realm/ci-actions/mdb-realm/deploy@338bf3e7575015a28faec8b67614385d122aece7
with:
realmUrl: ${{ env.BAAS_URL }}
atlasUrl: ${{ secrets.ATLAS_QA_URL }}
projectId: ${{ env.BAAS_PROJECT_ID }}
apiKey: ${{ env.BAAS_API_KEY }}
privateApiKey: ${{ env.BAAS_PRIVATE_API_KEY }}
clusterName: ${{ env.BAAS_CLUSTER }}

- name: Run tests
run: ${{ inputs.architecture == 'arm' && 'arch -arm64 ' || '' }}dart test -r expanded --coverage ./coverage/ -j 1 --test-randomize-ordering-seed random
run: ${{ inputs.architecture == 'arm' && 'arch -arm64 ' || '' }}dart test -r expanded --coverage ./coverage/ -j 1 --test-randomize-ordering-seed random --file-reporter="json:test-results.json" || true

- name: Publish Test Report
uses: dorny/[email protected]
if: success() || failure()
with:
name: Test Results Dart ${{ inputs.os }} ${{ inputs.architecture }}
path: test-results.json
reporter: dart-json
only-summary: true

# we're pruning generated files, the cli folder, as well as realm_bindings.dart from our coverage reports
- name: Generate realm_dart coverage report
Expand Down
35 changes: 35 additions & 0 deletions .github/workflows/deploy-baas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Deploy BaaS and apps

on:
workflow_call:
inputs:
differentiator:
description: Differentiator for the BaaS container.
required: true
type: string

env:
REALM_CI: true

jobs:
deploy-baas:
runs-on: ubuntu-latest
name: Deploy BaaS
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
with:
submodules: false

- name : Setup Dart SDK
uses: dart-lang/setup-dart@main
with:
sdk: stable
architecture: 'x64'

- name: Install dependencies
run: dart pub get

- name: Deploy cluster and apps
run: dart run realm_dart deploy-apps --baasaas-api-key ${{ secrets.BAASAAS_API_KEY }} --differentiator ${{ inputs.differentiator }}
29 changes: 5 additions & 24 deletions .github/workflows/flutter-desktop-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,12 @@ on:
description: Architecture to execute on.
required: false
type: string
app:
description: App name prefix
required: true
type: string
cluster:
description: Cluster name to deploy.
differentiator:
description: Differentiator for the BaaS container.
required: true
type: string

env:
BAAS_URL: ${{ secrets.REALM_QA_URL }}
BAAS_API_KEY: ${{ secrets.ATLAS_QA_PUBLIC_API_KEY }}
BAAS_PRIVATE_API_KEY: ${{ secrets.ATLAS_QA_PRIVATE_API_KEY }}
BAAS_PROJECT_ID: ${{ secrets.ATLAS_QA_PROJECT_ID}}
REALM_CI: true

jobs:
Expand All @@ -37,8 +29,9 @@ jobs:
name: Flutter tests on ${{inputs.os }}-${{ inputs.architecture }}
timeout-minutes: 45
env:
BAAS_CLUSTER: ${{ inputs.cluster }}
BAAS_DIFFERENTIATOR: ${{ inputs.app }}${{ github.run_id }}${{ github.run_attempt }}
BAAS_BAASAAS_API_KEY: ${{ secrets.BAASAAS_API_KEY}}
BAAS_DIFFERENTIATOR: ${{ inputs.differentiator }}

steps:

- name: Checkout
Expand Down Expand Up @@ -78,18 +71,6 @@ jobs:
run: ulimit -n 10240
if: ${{ contains(inputs.os, 'macos') }}

# This will be a no-op under normal circumstances since the cluster would have been deployed
# in deploy-cluster. It is needed in case we want to re-run the job after the cluster has been reaped.
- name: Create cluster
uses: realm/ci-actions/mdb-realm/deploy@338bf3e7575015a28faec8b67614385d122aece7
with:
realmUrl: ${{ env.BAAS_URL }}
atlasUrl: ${{ secrets.ATLAS_QA_URL }}
projectId: ${{ env.BAAS_PROJECT_ID }}
apiKey: ${{ env.BAAS_API_KEY }}
privateApiKey: ${{ env.BAAS_PRIVATE_API_KEY }}
clusterName: ${{ env.BAAS_CLUSTER }}

- name: Run tests
run: ${{ inputs.os == 'linux' && 'xvfb-run' || '' }} flutter drive -d ${{ inputs.os }} --target=test_driver/app.dart --suppress-analytics --dart-entrypoint-args="" --debug # -a="Some test name"
working-directory: ./flutter/realm_flutter/tests
58 changes: 0 additions & 58 deletions .github/workflows/shared-apps.yml

This file was deleted.

35 changes: 35 additions & 0 deletions .github/workflows/terminate-baas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Terminate BaaS

on:
workflow_call:
inputs:
differentiator:
description: Differentiator for the BaaS container.
required: true
type: string

env:
REALM_CI: true

jobs:
terminate-baas:
runs-on: ubuntu-latest
name: Terminate BaaS
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
with:
submodules: false

- name : Setup Dart SDK
uses: dart-lang/setup-dart@main
with:
sdk: stable
architecture: 'x64'

- name: Install dependencies
run: dart pub get

- name: Terminate baas
run: dart run realm_dart delete-apps --baasaas-api-key ${{ secrets.BAASAAS_API_KEY }} --differentiator ${{ inputs.differentiator }}
3 changes: 1 addition & 2 deletions flutter/realm_flutter/tests/test_driver/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import 'package:test/test.dart';
import 'const.dart';

void main(List<String> args) {
print("Current PID $pid");

group('Realm tests', () {
FlutterDriver? driver;

Expand All @@ -28,6 +26,7 @@ void main(List<String> args) {
testCommandWithArgs += getArgFromEnvVariable("BAAS_PRIVATE_API_KEY");
testCommandWithArgs += getArgFromEnvVariable("BAAS_PROJECT_ID");
testCommandWithArgs += getArgFromEnvVariable("BAAS_DIFFERENTIATOR");
testCommandWithArgs += getArgFromEnvVariable("BAAS_BAASAAS_API_KEY");

String result = await driver!.requestData(testCommandWithArgs, timeout: const Duration(minutes: 30));
if (result.isNotEmpty) {
Expand Down
8 changes: 6 additions & 2 deletions flutter/realm_flutter/tests/test_driver/realm_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import 'package:test_api/src/backend/invoker.dart';
import 'package:test_api/src/backend/state.dart' as test_api;

import '../test/app_test.dart' as app_test;
import '../test/asymmetric_test.dart' as asymmetric_test;
import '../test/backlinks_test.dart' as backlinks_test;
import '../test/client_reset_test.dart' as client_reset_test;
import '../test/configuration_test.dart' as configuration_test;
import '../test/credentials_test.dart' as credentials_test;
import '../test/decimal128_test.dart' as decimal128_test;
import '../test/dynamic_realm_test.dart' as dynamic_realm_test;
import '../test/embedded_test.dart' as embedded_test;
import '../test/geospatial_test.dart' as geospatial_test;
import '../test/indexed_test.dart' as indexed_test;
import '../test/list_test.dart' as list_test;
import '../test/migration_test.dart' as migration_test;
Expand All @@ -34,16 +36,19 @@ Future<String> main(List<String> args) async {
final List<String> failedTests = [];

await app_test.main(args);
await asymmetric_test.main(args);
await backlinks_test.main(args);
await client_reset_test.main(args);
await configuration_test.main(args);
await credentials_test.main(args);
await decimal128_test.main(args);
await dynamic_realm_test.main(args);
await embedded_test.main(args);
indexed_test.main(args);
await geospatial_test.main(args);
await indexed_test.main(args);
await list_test.main(args);
await migration_test.main(args);
await realm_logger_test.main(args);
await realm_object_test.main(args);
await realm_set_test.main(args);
await realm_test.main(args);
Expand All @@ -52,7 +57,6 @@ Future<String> main(List<String> args) async {
await session_test.main(args);
await subscription_test.main(args);
await user_test.main(args);
await realm_logger_test.main(args);

tearDown(() {
if (Invoker.current?.liveTest.state.result == test_api.Result.error || Invoker.current?.liveTest.state.result == test_api.Result.failure) {
Expand Down
6 changes: 5 additions & 1 deletion lib/src/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,11 @@ class App implements Finalizable {
/// Create an app with a particular [AppConfiguration]. This constructor should only be used on the main isolate and,
/// ideally, only once as soon as the app starts.
App(AppConfiguration configuration) : _handle = _createApp(configuration) {
if (Isolate.current.debugName != 'main') {
// This is not foolproof, but could point people to errors they may have in their app. Realm apps are cached natively, so calling App(config)
// on a background isolate will not recreate the app. Instead, users should construct the app on the main isolate and then call getById on the
// background isolates. This check will log a warning if the isolate name is != 'main' and doesn't start with 'test/' since dart test will
// construct a new isolate per file and we don't want to log excessively in unit test projects.
if (Isolate.current.debugName != 'main' && Isolate.current.debugName?.startsWith('test/') == false) {
Realm.logger.log(RealmLogLevel.warn,
"App constructor called on Isolate ${Isolate.current.debugName} which doesn't appear to be the main isolate. If you need an app instance on a background isolate use App.getById after constructing the App on the main isolate.");
}
Expand Down
Loading

0 comments on commit 9b947ff

Please sign in to comment.