예제 #1
0
        public void SyncConfiguration_LoggerFactory_Test(LogLevel logLevel)
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var logBuilder = new StringBuilder();

                SyncConfigurationBase.CustomLogger = (message, level) =>
                {
                    logBuilder.AppendLine($"[{level}] {message}");
                };
                SyncConfigurationBase.LogLevel = logLevel;

                var config = await SyncTestHelpers.GetIntegrationConfigAsync(Guid.NewGuid().ToString());
                using (var realm = await GetRealmAsync(config))
                {
                    realm.Write(() =>
                    {
                        realm.Add(new Person());
                    });

                    await SyncTestHelpers.WaitForUploadAsync(realm);
                }

                var log = logBuilder.ToString();

                Assert.That(log, Does.Contain($"[{logLevel}]"));
                Assert.That(log, Does.Not.Contain($"[{(logLevel - 1)}]"));
            });
        }
예제 #2
0
        public void GetInstanceAsync_Cancel_ShouldCancelWait()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var config = await SyncTestHelpers.GetIntegrationConfigAsync("foo");
                await PopulateData(config);
                // Update config to make sure we're not opening the same Realm file.
                config = new FullSyncConfiguration(config.ServerUri, config.User, config.DatabasePath + "1");

                using (var cts = new CancellationTokenSource())
                {
                    var _ = Task.Run(async() =>
                    {
                        await Task.Delay(1);
                        cts.Cancel();
                    });

                    try
                    {
                        var realm = await Realm.GetInstanceAsync(config, cts.Token);
                        CleanupOnTearDown(realm);
                        Assert.Fail("Expected task to be cancelled.");
                    }
                    catch (Exception ex)
                    {
                        Assert.That(ex, Is.InstanceOf <TaskCanceledException>());
                    }
                }
            });
        }
예제 #3
0
        public void GetInstanceAsync_ReportsProgress()
        {
            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var config = await SyncTestHelpers.GetIntegrationConfigAsync("foo");
                await PopulateData(config);

                var callbacksInvoked = 0;

                var lastProgress = default(SyncProgress);
                config           = new FullSyncConfiguration(config.ServerUri, config.User, config.DatabasePath + "1")
                {
                    OnProgress = (progress) =>
                    {
                        callbacksInvoked++;
                        lastProgress = progress;
                    }
                };

                using (var realm = await GetRealmAsync(config))
                {
                    Assert.That(realm.All <HugeSyncObject>().Count(), Is.EqualTo(NumberOfObjects));
                    Assert.That(callbacksInvoked, Is.GreaterThan(0));
                    Assert.That(lastProgress.TransferableBytes, Is.EqualTo(lastProgress.TransferredBytes));
                }
            });
        }
예제 #4
0
        public void Session_ProgressObservable_IntegrationTests(ProgressMode mode)
        {
            const int ObjectSize      = 1000000;
            const int ObjectsToRecord = 2;

            SyncTestHelpers.RunRosTestAsync(async() =>
            {
                var config           = await SyncTestHelpers.GetIntegrationConfigAsync("progress");
                var realm            = GetRealm(config);
                var completionTCS    = new TaskCompletionSource <ulong>();
                var callbacksInvoked = 0;

                var session = GetSession(realm);

                var observable = session.GetProgressObservable(ProgressDirection.Upload, mode);

                for (var i = 0; i < ObjectsToRecord; i++)
                {
                    realm.Write(() =>
                    {
                        realm.Add(new HugeSyncObject(ObjectSize));
                    });
                }
                var token = observable.Subscribe(p =>
                {
                    try
                    {
                        callbacksInvoked++;

                        if (p.TransferredBytes > p.TransferableBytes)
                        {
                            // TODO: this seems to be a regression in Sync.
                            // throw new Exception($"Expected: {p.TransferredBytes} <= {p.TransferableBytes}");
                        }

                        if (mode == ProgressMode.ForCurrentlyOutstandingWork)
                        {
                            if (p.TransferableBytes <= ObjectSize ||
                                p.TransferableBytes >= (ObjectsToRecord + 1) * ObjectSize)
                            {
                                throw new Exception($"Expected: {p.TransferredBytes} to be in the ({ObjectSize}, {(ObjectsToRecord + 1) * ObjectSize}) range.");
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        completionTCS.TrySetException(e);
                    }

                    if (p.TransferredBytes >= p.TransferableBytes)
                    {
                        completionTCS.TrySetResult(p.TransferredBytes);
                    }
                });

                using (token)
                {
                    realm.Write(() =>
                    {
                        realm.Add(new HugeSyncObject(ObjectSize));
                    });

                    var totalTransferred = await completionTCS.Task;

                    if (mode == ProgressMode.ForCurrentlyOutstandingWork)
                    {
                        Assert.That(totalTransferred, Is.GreaterThanOrEqualTo(ObjectSize));

                        // We add ObjectsToRecord + 1 items, but the last item is added after subscribing
                        // so in the fixed mode, we should not get updates for it.
                        Assert.That(totalTransferred, Is.LessThan((ObjectsToRecord + 5) * ObjectSize));
                    }
                    else
                    {
                        Assert.That(totalTransferred, Is.GreaterThanOrEqualTo((ObjectsToRecord + 1) * ObjectSize));
                    }

                    Assert.That(callbacksInvoked, Is.GreaterThan(1));
                }
            });
        }