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

Trigger collection listeners when commit #4368

Merged
merged 2 commits into from
Mar 27, 2017
Merged

Conversation

beeender
Copy link
Contributor

  • The listeners on RealmList/RealmResults will be tiggered immediately
    when the transaction committed on the same thread if the collections
    are changed or the async query should return.
  • Listeners on the RealmObject will have same behaviour after Add detailed notification for RealmObject #4331
    merged.

This is to solve the problem for predictive UI animations and local
transactions.
Fix #4245

- The listeners on RealmList/RealmResults will be tiggered immediately
  when the transaction committed on the same thread if the collections
  are changed or the async query should return.
- Listeners on the RealmObject will have same behaviour after #4331
  merged.

This is to solve the problem for predictive UI animations and local
transactions.
Fix #4245
Copy link
Contributor

@cmelchior cmelchior left a comment

Choose a reason for hiding this comment

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

Yay 🎉 . I only have a minor issue with the test cases.


collection.removeAllChangeListeners();

// This one is added after removal, so it should be triggered.
collection.addChangeListener(new RealmChangeListener<RealmList<Dog>>() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to add this in a test named removeAllChangeListeners() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because of i don't want to rely on the behavior "listeners triggered when commit" in this test. By adding another listener after all listeners removed, it can ensure that removeAllChangeListeners works, and the listener added after will be triggered. Which means the same test should work even when "listeners are triggered in the next event loop."

break;
}
}
});
addRow(sharedRealm);
assertEquals(collection.size(), 5);
transactionCommitted.set(true);
looperThread.testComplete();
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to change the flow of this test. Before it was depending on the notification arriving through the looper, now it is triggered synchronously.

Wouldn't it be better to make a new test case listenerTriggeredOnCommit() or something that tests that the change listener is triggered both on beginTransaction() and commitTransaction() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See the diff of the comments at the beginning of the test, the original test is to test the commitTransaction will trigger the listener in the next event loop. But now, the behavior to be tested is changed.

@cmelchior cmelchior added this to the 3.1 milestone Mar 23, 2017
break;
}
}
});
addRow(sharedRealm);
assertEquals(collection.size(), 5);
transactionCommitted.set(true);
looperThread.testComplete();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should check if that the listener is called twice.
I don't think this updated test fails in case of not being called when committed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right! fixed!

Copy link
Contributor

@zaki50 zaki50 left a comment

Choose a reason for hiding this comment

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

👍 with minor question.

looperThread.testComplete();
break;
default:
fail();
Copy link
Contributor

Choose a reason for hiding this comment

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

What will happen when reached to here after looperThread.testComplete(); is called?
But yes, it's difficult to check that the listener is not called after looperThread.testComplete(); is executed.
It's just a question from my curiosity.

Copy link
Contributor Author

@beeender beeender Mar 27, 2017

Choose a reason for hiding this comment

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

If it reaches here after testComplete called, the test will still fail with assertion.

@Zhuinden
Copy link
Contributor

This reminds me of the commit/notification behavior in 0.88.3

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants