-
Notifications
You must be signed in to change notification settings - Fork 275
Description
Description
Amplify.DataStore.observe() can miss events if other DataStore methods are called immediately before it. for example, if DataStore.save() is called immediately before DataStore.observe(), the observe stream will miss the save event.
Here is an example test case that will fail.
testWidgets('should emit an event for each item saved',
(WidgetTester tester) async {
var itemStream = Amplify.DataStore.observe(Blog.classType)
.map((event) => event.item.name);
expectLater(
itemStream,
emitsInOrder(['blog 1', 'blog 2', 'blog 3']),
);
// The test will pass with the delay below added. Without the delay,
// the first event will not be emitted from the stream.
// await Future.delayed(Duration(seconds: 2));
await Amplify.DataStore.save(Blog(name: 'blog 1'));
await Amplify.DataStore.save(Blog(name: 'blog 2'));
await Amplify.DataStore.save(Blog(name: 'blog 3'));
});Since observeQuery is built on top of observe, this impact observeQuery as well.
Categories
- Analytics
- API (REST)
- API (GraphQL)
- Auth
- Authenticator
- DataStore
- Storage
Steps to Reproduce
See example in description.
Screenshots
No response
Platforms
- iOS
- Android
Android Device/Emulator API Level
No response
Environment
N/A - Multiple flutter versions (2.8.1 through 3.0.0)Dependencies
N/ADevice
iPhone 12 (seems to be present on Android as well)
OS
iOS 15.1 (seems to be present on Android as well)
CLI Version
N/A
Additional Context
This seems to be causes by a race condition in DataStore. All datastore methods (save/delete) are supposed to wait for the observe stream to be set up prior to executing. This does not seem to be happening. This race condition may be slightly worse in flutter 3, although more testing needs to be done to confirm this.