@@ -68,69 +68,59 @@ void main() {
68
68
cleanUpRealm (realm, app);
69
69
});
70
70
71
- Future <void > _addSubscriptions (Realm realm, String searchByPrefix) async {
71
+ Future <void > addSubscriptions (Realm realm, String searchByPrefix) async {
72
72
final query = realm.query <Tricycle >(r'name BEGINSWITH $0' , ["a" ]);
73
73
if (realm.subscriptions.find (query) == null ) {
74
74
realm.subscriptions.update ((mutableSubscriptions) => mutableSubscriptions.add (query));
75
75
}
76
76
await realm.subscriptions.waitForSynchronization ();
77
77
}
78
78
79
- Future <Configuration > _subscribeForAtlasAddedData (App app, {String ? queryDifferentiator, int itemsCount = 100 }) async {
80
- final productNamePrefix = queryDifferentiator ?? generateRandomString ( 10 ) ;
79
+ Future <Configuration > subscribeForAtlasAddedData (App app, {int itemsCount = 100 }) async {
80
+ final productNamePrefix = "a" ;
81
81
final user1 = await app.logIn (Credentials .anonymous (reuseCredentials: false ));
82
82
final config1 = Configuration .flexibleSync (user1, [Tricycle .schema]);
83
83
final realm1 = Realm (config1);
84
- await _addSubscriptions (realm1, productNamePrefix);
84
+ await addSubscriptions (realm1, productNamePrefix);
85
85
realm1.close ();
86
+
87
+ final user2 = await app.logIn (Credentials .anonymous (reuseCredentials: false ));
88
+ final config2 = Configuration .flexibleSync (user2, [Tricycle .schema]);
89
+ final realm2 = Realm (config2);
90
+
91
+ await addSubscriptions (realm2, productNamePrefix);
92
+
93
+ final trikes = realm2.all <Tricycle >();
94
+ realm2.write (() {
95
+ realm2.deleteMany (trikes);
96
+ realm2.add (Tricycle (1001 , "a1001" ));
97
+ realm2.add (Tricycle (2002 , "a2002" ));
98
+ realm2.add (Tricycle (3003 , "a3003" ));
99
+ });
100
+
101
+ await realm2.syncSession.waitForUpload ();
102
+ await realm2.syncSession.waitForDownload ();
103
+ realm2.close ();
86
104
return config1;
87
105
}
88
106
89
107
test ("Track upload progress" , () async {
90
- final config = await _subscribeForAtlasAddedData (app);
91
-
92
- int printCount = 0 ;
108
+ final config = await subscribeForAtlasAddedData (app);
109
+ // :snippet-start: async-open-track-progress
93
110
double progressEstimate = - 1 ;
94
-
95
- final syncedRealm = await Realm .open (config, onProgressCallback: (syncProgress) {
96
- printCount++ ;
111
+ final realm = await Realm .open (config, onProgressCallback: (syncProgress) {
97
112
progressEstimate = syncProgress.progressEstimate;
113
+ print ('Sync progress: ${progressEstimate * 100 }% complete.' );
114
+ if (progressEstimate == 1.0 ) {
115
+ //transfer is complete
116
+ }
98
117
});
99
-
100
- await syncedRealm.syncSession.waitForUpload ();
101
- await syncedRealm.syncSession.waitForDownload ();
102
- expect (syncedRealm.isClosed, false );
103
- expect (printCount, 1 );
118
+ // :snippet-end:
119
+ expect (realm.isClosed, false );
104
120
expect (progressEstimate, 1.0 );
121
+ cleanUpRealm (realm, app);
105
122
});
106
-
107
123
108
- test ('Track download progress' , () async {
109
- print ("start" );
110
- final credentials = Credentials .anonymous ();
111
- final currentUser = await app.logIn (credentials);
112
- double progress = - 1 ;
113
- final config = Configuration .flexibleSync (currentUser, [Tricycle .schema]);
114
- // :snippet-start: async-open-track-progress
115
- print (progress);
116
-
117
- final realm = await Realm .open (config, onProgressCallback: (syncProgress) {
118
- progress = syncProgress.progressEstimate;
119
- print ("here" );
120
- // Percent complete == progress * 100
121
- print (progress);
122
- if (syncProgress.progressEstimate == 1.0 ) {
123
- // Transfer is complete
124
- }
125
- });
126
- await realm.syncSession.waitForUpload ();
127
- await realm.syncSession.waitForDownload ();
128
-
129
- // :snippet-end:
130
- /*expect(realm.isClosed, false);
131
- expect(progress, greaterThanOrEqualTo(0));
132
- cleanUpRealm(realm, app);*/
133
- });
134
124
test ('Cancel download in progress' , () async {
135
125
final credentials = Credentials .anonymous ();
136
126
final currentUser = await app.logIn (credentials);
0 commit comments