Skip to content

Conversation

jsflax
Copy link
Contributor

@jsflax jsflax commented Feb 8, 2019

No description provided.

@jsflax jsflax requested review from adamchel and tkaye407 February 11, 2019 22:05
Copy link
Contributor

@adamchel adamchel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid start, mainly had some naming feedback to bring the interface to parity with JavaScript, and logic changes in CoreStitchAuth. I think some of this may have been written before we decided to have onActiveUserChanged be called everywhere the active user changes, including login and logout.

);
// reinitialize the DataSynchronizer entirely.
// any auth event will trigger this.
this.dataSynchronizer.reinitialize(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[minor] once you fix CoreStitchAuth to trigger onActiveUserChanged event in all the places where a logout and login can happen, you should only do this reinitialization on the ACTIVE_USER_CHANGED case, and have default be a no-op. Otherwise, the reinitialize will get triggered multiple times on a single login or logout.

);
// reinitialize the DataSynchronizer entirely.
// any auth event will trigger this.
this.dataSynchronizer.reinitialize(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] if there is no active user after the active user has changed, shouldn't we call a different method that just stops the data synchronizer rather than reinitializes it? I see right now that the data synchronizer just ends up being bound to an "unbound" data directory. I guess that's fine but wouldn't it be cleaner if the data synchronizer just didn't run at all when logged out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't run anyway. This won't be an issue until we get to sync cadence. In the interim, this is fine.

import java.util.concurrent.TimeUnit

@RunWith(AndroidJUnit4::class)
class StitchAppClientIntTests : BaseStitchAndroidIntTest() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[task] I think you should probably test more cases auth listener cases.

check out the JS PR, I added a new file of StitchAuthListenerIntTests, and for each method of the listener, I have a test method that simulates the different ways that event can be triggered, and ensures that the event method is called a certain number of times.

it sounds like a lot but it should be pretty simple to write, and it's a lot cleaner than trying to mix in with existing integration tests

@Override
public void onUserLoggedIn(final StitchAuth auth,
final StitchUser loggedInUser) {
onRebindEvent(new AuthEvent.UserLoggedIn<>(loggedInUser));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you be rebinding on all of these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is up to the service to determine what to do with the information given.

@jsflax
Copy link
Contributor Author

jsflax commented Feb 12, 2019

@adamchel PTAL

Copy link
Contributor

@adamchel adamchel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple nits, and you should also add tests to the server SDK, but LGTM otherwise!

@coveralls
Copy link

coveralls commented Feb 13, 2019

Coverage Status

Coverage decreased (-1.5%) to 65.969% when pulling d6dad19 on jsflax:STITCH-2510 into 94c5ed6 on mongodb:master.

Copy link
Contributor

@adamchel adamchel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! Much needed cleanup that will make this code a lot more stable.

Had a few minor questions/concerns but nothing that should block the merge. Would appreciate some answers or the chance to discuss before we merge. Might just require some future work.

doneOnce = true;
line = "";
} catch (IOException e) {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] why not throw an exception? if we're keeping this, update the comment for this method to explain when this may be null, and add a @Nullable annotation

while (runnerThread.isAlive()) {
runnerThread.interrupt();
try {
System.out.println("killing runner");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] was this for debugging? delete if so. if this would be useful for users, make this an actual log item

}

final String userId = appInfo.getAuthMonitor().isLoggedIn()
final String userId = appInfo.getAuthMonitor().tryIsLoggedIn()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] does this need to be a tryIsLoggedIn? I'm concerned that this would cause a real user to end up having their data be in an "unbound" data directory

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current state of our codebase, it would not be possible for this to happen. However, maybe I'll make a note here for "in the future".

ctx.isLoggedIn = true
assertFalse(namespaceChangeStreamListener.openStream())
verify(nsConfigMock, times(1)).synchronizedDocumentIds
verify(nsConfigMock, times(3)).synchronizedDocumentIds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] what changed to make this happen? this isn't a performance hit right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... it is a slight performance hit. I moved getSynchronizedDocumentIds to the top of openStream to pre-read them before taking the lock. But that may not be necessary anymore.

@Override
public boolean isLoggedIn() {
return getAuth().isLoggedIn();
public boolean isLoggedIn() throws InterruptedException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] If a user ever calls isLoggedIn() method on a StitchAppClient, is there a case where that can throw? should we mark the method as throws in the interface and explain when it could happen?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, all of this is internal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah you're right, there's no isLoggedIn on the app client itself

}
} catch (InterruptedException e) {
System.err.println("Stream authentication was interrupted.");
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] are we sure we want to return this? why not just throw the exception? This seems like a null pointer exception waiting to happen somewhere upstream. What happens if the user calls watch and the stream got interrupted? I think it would be better for an error to happen rather than getting a null result.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, that would have to happen on the users accord. We should probably throw an exception.

throw new StitchClientException(StitchClientErrorCode.MUST_AUTHENTICATE_FIRST);
}
} catch (InterruptedException e) {
System.err.println("Stream authentication was interrupted.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this a log statement or get rid of the print

@jsflax jsflax merged commit ddd55d7 into mongodb:master Feb 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants