Skip to content

Commit 8a874c4

Browse files
authored
Upgrade ROS Integration Test Server to 2.0.0-rc.5 (#5385)
1 parent af7e0cc commit 8a874c4

File tree

9 files changed

+46
-41
lines changed

9 files changed

+46
-41
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
* Assigning a managed object's own list to itself would accidentally clear it (#5395).
1313
* Don't try to acquire `ApplicationContext` if not available in `Realm.init(Context)` (#5389).
14+
* Removing and re-adding a changelistener from inside a changelistener sometimes caused notifications to be missed (#5411).
1415

1516
## Internal
1617

dependencies.list

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ REALM_SYNC_SHA256=2d3661cdb94d6509b4a43d6daab17c9223fbb1e6608e317205bd61b4ef1b95
55

66
# Object Server Release used by Integration tests. Installed using NPM.
77
# Use `npm view realm-object-server versions` to get a list of available versions.
8-
REALM_OBJECT_SERVER_DE_VERSION=2.0.0-rc.4
8+
REALM_OBJECT_SERVER_DE_VERSION=2.0.0-rc.5
9+

realm/realm-library/src/objectServer/java/io/realm/PermissionManager.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.net.URISyntaxException;
2424
import java.net.URL;
2525
import java.util.ArrayList;
26+
import java.util.Arrays;
2627
import java.util.Deque;
2728
import java.util.HashMap;
2829
import java.util.LinkedHashMap;
@@ -198,6 +199,7 @@ user, getRealmUrl(RealmType.PERMISSION_REALM, user.getAuthenticationUrl()))
198199
.errorHandler(new SyncSession.ErrorHandler() {
199200
@Override
200201
public void onError(SyncSession session, ObjectServerError error) {
202+
RealmLog.error("Error in __permission:\n" + error.toString());
201203
synchronized (errorLock) {
202204
permissionRealmError = error;
203205
}
@@ -588,9 +590,11 @@ public void run() {
588590
loadingPermissions.addChangeListener(new RealmChangeListener <RealmResults<Permission>>() {
589591
@Override
590592
public void onChange(RealmResults <Permission> loadedPermissions) {
591-
// FIXME Wait until both the __permission and __management Realm are available
592-
if (loadedPermissions.size() > 0) {
593+
RealmLog.error(String.format("1stCallback: Size: %s, Permissions: %s", loadedPermissions.size(), Arrays.toString(loadedPermissions.toArray())));
594+
// Don't report ready until both __permission and __management Realm are there
595+
if (loadedPermissions.size() > 1) {
593596
loadingPermissions.removeChangeListener(this);
597+
loadingPermissions = null;
594598
if (checkAndReportInvalidState()) { return; }
595599
if (userPermissions == null) {
596600
userPermissions = loadedPermissions;

realm/realm-library/src/syncIntegrationTest/java/io/realm/PermissionManagerTests.java

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ public void onError(ObjectServerError error) {
106106

107107
@Test
108108
@RunTestInLooperThread(emulateMainThread = true)
109-
@Ignore("See https://github.com/realm/ros/issues/437")
110109
public void getPermissions_updatedWithNewRealms() {
111-
PermissionManager pm = user.getPermissionManager();
110+
final PermissionManager pm = user.getPermissionManager();
112111
looperThread.closeAfterTest(pm);
113112
pm.getPermissions(new PermissionManager.PermissionsCallback() {
114113
@Override
@@ -132,6 +131,7 @@ public void onError(SyncSession session, ObjectServerError error) {
132131
permissions.addChangeListener(new RealmChangeListener<RealmResults<Permission>>() {
133132
@Override
134133
public void onChange(RealmResults<Permission> permissions) {
134+
RealmLog.error(String.format("2ndCallback: Size: %s, Permissions: %s", permissions.size(), Arrays.toString(permissions.toArray())));
135135
Permission p = permissions.where().endsWith("path", "tests2").findFirst();
136136
if (p != null) {
137137
assertTrue(p.mayRead());
@@ -152,8 +152,8 @@ public void onError(ObjectServerError error) {
152152

153153
@Test
154154
@RunTestInLooperThread(emulateMainThread = true)
155-
@Ignore("See https://github.com/realm/ros/issues/437")
156155
public void getPermissions_updatedWithNewRealms_stressTest() {
156+
final int TEST_SIZE = 10;
157157
final PermissionManager pm = user.getPermissionManager();
158158
looperThread.closeAfterTest(pm);
159159
pm.getPermissions(new PermissionManager.PermissionsCallback() {
@@ -162,8 +162,8 @@ public void onSuccess(RealmResults<Permission> permissions) {
162162
assertTrue(permissions.isLoaded());
163163
assertInitialPermissions(permissions);
164164

165-
for (int i = 0; i < 10; i++) {
166-
SyncConfiguration configNew = new SyncConfiguration.Builder(user, "realm://127.0.0.1:9080/~/test" + i).build();
165+
for (int i = 0; i < TEST_SIZE; i++) {
166+
SyncConfiguration configNew = new SyncConfiguration.Builder(user, "realm://" + Constants.HOST + "/~/test" + i).build();
167167
Realm newRealm = Realm.getInstance(configNew);
168168
looperThread.closeAfterTest(newRealm);
169169
}
@@ -173,8 +173,8 @@ public void onSuccess(RealmResults<Permission> permissions) {
173173
permissions.addChangeListener(new RealmChangeListener<RealmResults<Permission>>() {
174174
@Override
175175
public void onChange(RealmResults<Permission> permissions) {
176-
RealmLog.error(Arrays.toString(permissions.toArray())); // FIXME Debug output for CI. Remove before release.
177-
Permission p = permissions.where().endsWith("path", "test9").findFirst();
176+
RealmLog.error(String.format("Size: %s, Permissions: %s", permissions.size(), Arrays.toString(permissions.toArray())));
177+
Permission p = permissions.where().endsWith("path", "test" + (TEST_SIZE - 1)).findFirst();
178178
if (p != null) {
179179
assertTrue(p.mayRead());
180180
assertTrue(p.mayWrite());
@@ -243,7 +243,7 @@ public void onError(ObjectServerError error) {
243243

244244
@Test
245245
@RunTestInLooperThread(emulateMainThread = true)
246-
@Ignore("See https://github.com/realm/ros/issues/432")
246+
@Ignore("Wait for default permission Realm support")
247247
public void getPermissions_addTaskAfterClientReset() {
248248
final PermissionManager pm = user.getPermissionManager();
249249
looperThread.closeAfterTest(pm);
@@ -428,7 +428,7 @@ public void onError(ObjectServerError error) {
428428

429429
@Test
430430
@RunTestInLooperThread(emulateMainThread = true)
431-
@Ignore("See https://github.com/realm/ros/issues/432")
431+
@Ignore("See https://github.com/realm/ros/issues/520")
432432
public void getDefaultPermissions_returnLoadedResults() {
433433
PermissionManager pm = user.getPermissionManager();
434434
looperThread.closeAfterTest(pm);
@@ -449,7 +449,7 @@ public void onError(ObjectServerError error) {
449449

450450
@Test
451451
@RunTestInLooperThread(emulateMainThread = true)
452-
@Ignore("See https://github.com/realm/ros/issues/432")
452+
@Ignore("See https://github.com/realm/ros/issues/520")
453453
public void getDefaultPermissions_noLongerValidWhenPermissionManagerIsClosed() {
454454
final PermissionManager pm = user.getPermissionManager();
455455
pm.getDefaultPermissions(new PermissionManager.PermissionsCallback() {
@@ -481,6 +481,7 @@ public void getDefaultPermissions_updatedWithNewRealms() {
481481

482482
@Test
483483
@RunTestInLooperThread(emulateMainThread = true)
484+
@Ignore("See https://github.com/realm/ros/issues/520")
484485
public void getDefaultPermissions_closed() throws IOException {
485486
PermissionManager pm = user.getPermissionManager();
486487
pm.close();
@@ -716,7 +717,6 @@ public void onError(ObjectServerError error) {
716717

717718
@Test
718719
@RunTestInLooperThread(emulateMainThread = true)
719-
@Ignore("See https://github.com/realm/ros/issues/426")
720720
public void applyPermissions_withUsername() {
721721
String user1Username = TestHelper.getRandomEmail();
722722
String user2Username = TestHelper.getRandomEmail();
@@ -831,7 +831,6 @@ public void onError(ObjectServerError error) {
831831

832832
@Test
833833
@RunTestInLooperThread(emulateMainThread = true)
834-
@Ignore("See https://github.com/realm/ros/issues/430")
835834
public void makeOffer_noManageAccessThrows() {
836835
// User 2 creates a Realm
837836
SyncUser user2 = UserFactory.createUniqueUser();
@@ -1208,19 +1207,7 @@ public void onChange(Progress progress) {
12081207
* states and fail if neither of these can be verified.
12091208
*/
12101209
private void assertInitialPermissions(RealmResults<Permission> permissions) {
1211-
// For a new user, the PermissionManager should contain 1 entry for the __permission Realm, but we are
1212-
// creating the __management Realm at the same time, so this might be here as well.
1213-
permissions = permissions.sort("path");
1214-
if (permissions.size() == 1) {
1215-
// FIXME It is very unpredictable which Permission is returned. This needs to be fixed.
1216-
Permission permission = permissions.first();
1217-
assertTrue(permission.getPath().endsWith("__permission") || permission.getPath().endsWith("__management"));
1218-
} else if (permissions.size() == 2) {
1219-
assertTrue("Failed: " + permissions.get(0).toString(), permissions.get(0).getPath().endsWith("__management"));
1220-
assertTrue("Failed: " + permissions.get(1).toString(), permissions.get(1).getPath().endsWith("__permission"));
1221-
} else {
1222-
fail("Permission Realm contains unknown permissions: " + Arrays.toString(permissions.toArray()));
1223-
}
1210+
assertEquals("Could not find __permissions Realm", 1, permissions.where().endsWith("path", "__permission").count());
1211+
assertEquals("Could not find __management Realm", 1, permissions.where().endsWith("path", "__management").count());
12241212
}
1225-
12261213
}

realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/AuthTests.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,6 @@ public void singleUserCanBeLoggedInAndOutRepeatedly() {
497497
}
498498

499499
@Test
500-
@Ignore("See https://github.com/realm/ros/issues/360")
501500
public void revokedRefreshTokenIsNotSameAfterLogin() throws InterruptedException {
502501
final CountDownLatch userLoggedInAgain = new CountDownLatch(1);
503502
final String uniqueName = UUID.randomUUID().toString();
@@ -536,7 +535,6 @@ public void loggedOut(SyncUser user) {
536535
// WARNING: this test can fail if there's a difference between the server's and device's clock, causing the
537536
// refresh access token to be too far in time.
538537
@Test(timeout = 30000)
539-
@Ignore("Resolve https://github.com/realm/ros/issues/277")
540538
public void preemptiveTokenRefresh() throws NoSuchFieldException, IllegalAccessException, InterruptedException {
541539
SyncUser user = UserFactory.createUniqueUser(Constants.AUTH_URL);
542540

realm/realm-library/src/syncIntegrationTest/java/io/realm/objectserver/utils/Constants.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818

1919
public class Constants {
2020

21-
public static final String USER_REALM = "realm://127.0.0.1:9080/~/tests";
22-
public static final String USER_REALM_2 = "realm://127.0.0.1:9080/~/tests2";
23-
public static final String USER_REALM_SECURE = "realms://127.0.0.1:9443/~/tests";
24-
public static final String SYNC_SERVER_URL = "realm://127.0.0.1:9080/~/tests";
25-
public static final String SYNC_SERVER_URL_2 = "realm://127.0.0.1/~/tests2";
21+
public static String HOST = "127.0.0.1";
22+
public static final String USER_REALM = "realm://" + HOST + ":9080/~/tests";
23+
public static final String USER_REALM_2 = "realm://" + HOST + ":9080/~/tests2";
24+
public static final String USER_REALM_SECURE = "realms://" + HOST + ":9443/~/tests";
25+
public static final String SYNC_SERVER_URL = "realm://" + HOST + ":9080/~/tests";
26+
public static final String SYNC_SERVER_URL_2 = "realm://" + HOST + "/~/tests2";
2627

27-
public static final String AUTH_SERVER_URL = "http://127.0.0.1:9080/";
28+
public static final String AUTH_SERVER_URL = "http://" + HOST + ":9080/";
2829
public static final String AUTH_URL = AUTH_SERVER_URL + "auth";
29-
30-
public static final long TEST_TIMEOUT_SECS = 300;
3130
}

tools/sync_test_server/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ARG ROS_DE_VERSION
66
RUN npm install -g realm-object-server@$ROS_DE_VERSION -S
77

88
# Install test server dependencies
9-
RUN npm install winston temp httpdispatcher@1.0.0
9+
RUN npm install winston temp httpdispatcher@1.0.0 fs-extra
1010

1111
COPY keys/public.pem keys/private.pem keys/127_0_0_1-server.key.pem keys/127_0_0_1-chain.crt.pem configuration.yml /
1212
COPY ros-testing-server.js /usr/bin/

tools/sync_test_server/ros-testing-server.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const spawn = require('child_process').spawn;
66
const exec = require('child_process').exec;
77
var http = require('http');
88
var dispatcher = require('httpdispatcher');
9+
var fs = require('fs-extra');
910

1011
// Automatically track and cleanup files at exit
1112
temp.track();
@@ -63,9 +64,23 @@ function startRealmObjectServer(onSuccess, onError) {
6364
var env = Object.create( process.env );
6465
winston.info(env.NODE_ENV);
6566
env.NODE_ENV = 'development';
67+
68+
// Manually cleanup Global Notifier State
69+
// See https://github.com/realm/ros/issues/437#issuecomment-335380095
70+
var globalNotifierDir = path + '/realm-object-server';
71+
winston.info('Cleaning state in: ' + globalNotifierDir);
72+
fs.removeSync(globalNotifierDir)
73+
if (fs.existsSync(globalNotifierDir)) {
74+
onError("Could not delete the global notifier directory: " + globalNotifierDir);
75+
return;
76+
}
77+
fs.mkdirsSync(path + '/realm-object-server/io.realm.object-server-utility/metadata/')
78+
79+
// Start ROS
6680
syncServerChildProcess = spawn('ros',
6781
['start',
6882
'--data', path,
83+
// '--loglevel', 'detail', // Enable when debugging
6984
'--access-token-ttl', '20' //WARNING : Changing this value may impact the timeout of the refresh token test (AuthTests#preemptiveTokenRefresh)
7085
],
7186
{ env: env, cwd: path});

0 commit comments

Comments
 (0)