Ejemplo n.º 1
0
        public void SyncConfiguration_LoggerFactory_Test(LogLevel logLevel)
        {
            SyncTestHelpers.RequiresRos();

            AsyncContext.Run(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 GetSession(realm).WaitForUploadAsync();
                }

                var log = logBuilder.ToString();

                Assert.That(log, Does.Contain($"[{logLevel}]"));
                Assert.That(log, Does.Not.Contain($"[{(logLevel - 1)}]"));
            });
        }
Ejemplo n.º 2
0
        public void Session_ProgressObservable_IntegrationTests(ProgressMode mode)
        {
            SyncTestHelpers.RequiresRos();

            const int ObjectSize      = 1000000;
            const int ObjectsToRecord = 2;

            AsyncContext.Run(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)
                        {
                            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 + 1) * ObjectSize));
                    }
                    else
                    {
                        Assert.That(totalTransferred, Is.GreaterThanOrEqualTo((ObjectsToRecord + 1) * ObjectSize));
                    }

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