Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use qbs v2 and reenable schema migration tests #1762

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 40 additions & 17 deletions packages/realm_dart/lib/src/cli/atlas_apps/baas_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ class BaasClient {

static final String defaultAppName = AppName.flexible.name;

final String _adminApiUrl;
String get _adminApiUrl => '$baseUrl/api/admin/v3.0';
String get _privateApiUrl => '$baseUrl/api/private/v1.0';

final String? _clusterName;
final Map<String, String> _headers;
final String _appSuffix;
Expand All @@ -170,8 +172,7 @@ class BaasClient {
late String publicRSAKey = '';

BaasClient._(this.baseUrl, String differentiator, [this._clusterName])
: _adminApiUrl = '$baseUrl/api/admin/v3.0',
_headers = <String, String>{'Accept': 'application/json'},
: _headers = <String, String>{'Accept': 'application/json'},
_appSuffix = '-${shortenDifferentiator(differentiator)}${_clusterName == null ? '' : '-$_clusterName'}';

/// A client that imports apps in a MongoDB Atlas docker image. See https://github.com/realm/ci/tree/master/realm/docker/mongodb-realm
Expand Down Expand Up @@ -333,18 +334,25 @@ class BaasClient {
try {
final response = await _get('groups/$_groupId/apps/$appId/sync/progress');

final progressInfo = response['progress'] as Map<String, dynamic>;
for (final key in progressInfo.keys) {
final error = progressInfo[key]['error'] as String?;
if (error != null) {
print(error);
return false;
}
final acceptingClients = response['accepting_clients'] as bool? ?? false;
if (acceptingClients) {
return true;
}

final progressInfo = response['progress'] as Map<String, dynamic>?;
if (progressInfo != null) {
for (final key in (progressInfo?.keys ?? <String>{})) {
final error = progressInfo[key]['error'] as String?;
if (error != null) {
print(error);
return false;
}

final namespaceComplete = progressInfo[key]['complete'] as bool;
final namespaceComplete = progressInfo[key]['complete'] as bool;

if (!namespaceComplete) {
return false;
if (!namespaceComplete) {
return false;
}
}
}

Expand Down Expand Up @@ -538,6 +546,10 @@ class BaasClient {
}''');
}

print('Enable qbsv2 for ${app.name}');
nielsenko marked this conversation as resolved.
Show resolved Hide resolved

await _setFeatureFlag(app, 'allow_qbs_v2');

print('Creating database db_$uniqueName');

final mongoServiceId = await _createMongoDBService(
Expand Down Expand Up @@ -631,6 +643,17 @@ class BaasClient {
return result['key'] as String;
}

Future<void> _setFeatureFlag(BaasApp app, String feature, {bool enabled = true}) async {
final action = enabled ? 'enable' : 'disable';
await _post(
'groups/$_groupId/apps/$app/features',
'''{
"action": "$action",
"feature_flags": [ "$feature" ]
}''',
apiRootPath: _privateApiUrl);
}

Future<void> _authenticate(String provider, String credentials) async {
dynamic response = await _post('auth/providers/$provider/login', credentials);

Expand Down Expand Up @@ -766,12 +789,12 @@ class BaasClient {
return additionalHeaders;
}

Uri _getUri(String relativePath) {
return Uri.parse('$_adminApiUrl/$relativePath');
Uri _getUri(String relativePath, {String? apiRootPath}) {
return Uri.parse('${apiRootPath ?? _adminApiUrl}/$relativePath');
}

Future<dynamic> _post(String relativePath, String payload) async {
var response = await http.post(_getUri(relativePath), headers: _getHeaders({'Content-Type': 'application/json'}), body: payload);
Future<dynamic> _post(String relativePath, String payload, {String? apiRootPath}) async {
var response = await http.post(_getUri(relativePath, apiRootPath: apiRootPath), headers: _getHeaders({'Content-Type': 'application/json'}), body: payload);
return _decodeResponse(response, payload);
}

Expand Down
5 changes: 5 additions & 0 deletions packages/realm_dart/lib/src/subscription.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ abstract interface class SubscriptionSet with Iterable<Subscription> {

Future<SubscriptionSetState> _waitForStateChange(SubscriptionSetState state, [CancellationToken? cancellationToken]) async {
final result = await _handle.waitForStateChange(state, cancellationToken);
if (_handle.released) {
// We can get here if the Realm was closed before the wait has completed
throw CancelledException(cancellationReason: 'The Realm owning the subscription set was closed.');
}

_handle.refresh();
return result;
}
Expand Down
7 changes: 3 additions & 4 deletions packages/realm_dart/test/sync_migration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'dart:typed_data';

import 'package:realm_dart/realm.dart';
import 'package:realm_dart/src/configuration.dart';
import 'package:test/test.dart' hide test, throws;

import 'test.dart';

Expand Down Expand Up @@ -159,7 +158,7 @@ void main() {
expect(objv2.stringValue, isNull);
expect(objv2.uuidValue, isNull);
expect(objv2.binaryValue, isNull);
}, appName: AppName.staticSchema, skip: true);
}, appName: AppName.staticSchema);

baasTest('Can remove field', (appConfig) async {
final differentiator = ObjectId();
Expand Down Expand Up @@ -237,7 +236,7 @@ void main() {
expect(objv2.stringValue, isNull);
expect(objv2.uuidValue, isNull);
expect(objv2.binaryValue, isNull);
}, appName: AppName.staticSchema, skip:true);
}, appName: AppName.staticSchema);

baasTest('Realm can be migrated skipping versions (0->2)', (appConfig) async {
final differentiator = ObjectId();
Expand All @@ -262,5 +261,5 @@ void main() {
expect(objv2.stringValue, isNull);
expect(objv2.uuidValue, isNull);
expect(objv2.binaryValue, isNull);
}, appName: AppName.staticSchema, skip: true);
}, appName: AppName.staticSchema);
}
Loading