Skip to content

Commit

Permalink
Merge branch 'main' into ni/android-error
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev authored Jul 21, 2023
2 parents 4e13543 + fbbb556 commit 727b46c
Show file tree
Hide file tree
Showing 30 changed files with 416 additions and 223 deletions.
12 changes: 6 additions & 6 deletions .github/actions/benchmark-uploader/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .github/templates/test-code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
echo "${{ github.workspace }}/tools" >> $GITHUB_PATH
- #@ template.replace(dotnetPublish("Tests/Realm.Tests", "net7.0", "linux-x64", { "RealmTestsStandaloneExe": "true" }))
- name: Run the tests
run: #@ "./tools/coverlet ${{ steps.dotnet-publish.outputs.executable-path }} -t ${{ steps.dotnet-publish.outputs.executable-path }}/Realm.Tests -a '--result=TestResults.Linux.xml --labels=After" + baasTestArgs("code-coverage") + "' -f lcov -o ./report.lcov --exclude '[Realm.Tests]*' --exclude '[Realm.Fody]*'"
run: #@ "./tools/coverlet ${{ steps.dotnet-publish.outputs.executable-path }} -t ${{ steps.dotnet-publish.outputs.executable-path }}/Realm.Tests -a '--result=TestResults.Linux.xml --labels=After" + baasTestArgs("code-coverage") + "' -f lcov -o ./report.lcov --exclude '[Realm.Tests]*' --exclude '[Realm.Fody]*' --exclude '[Realm.PlatformHelpers]*'"
- name: Publish Coverage
id: publish-coveralls
uses: #@ actionCoveralls
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ jobs:
run: echo 'executable-path=./Tests/Realm.Tests/bin/Release/net7.0/linux-x64' >> $GITHUB_OUTPUT
shell: bash
- name: Run the tests
run: ./tools/coverlet ${{ steps.dotnet-publish.outputs.executable-path }} -t ${{ steps.dotnet-publish.outputs.executable-path }}/Realm.Tests -a '--result=TestResults.Linux.xml --labels=After --baasurl=${{ inputs.realmUrl }} --baascluster=${{ inputs.clusterName }} --baasapikey=${{ secrets.AtlasPublicKey}} --baasprivateapikey=${{ secrets.AtlasPrivateKey}} --baasprojectid=${{ secrets.AtlasProjectId }} --baasdifferentiator=code-coverage' -f lcov -o ./report.lcov --exclude '[Realm.Tests]*' --exclude '[Realm.Fody]*'
run: ./tools/coverlet ${{ steps.dotnet-publish.outputs.executable-path }} -t ${{ steps.dotnet-publish.outputs.executable-path }}/Realm.Tests -a '--result=TestResults.Linux.xml --labels=After --baasurl=${{ inputs.realmUrl }} --baascluster=${{ inputs.clusterName }} --baasapikey=${{ secrets.AtlasPublicKey}} --baasprivateapikey=${{ secrets.AtlasPrivateKey}} --baasprojectid=${{ secrets.AtlasProjectId }} --baasdifferentiator=code-coverage' -f lcov -o ./report.lcov --exclude '[Realm.Tests]*' --exclude '[Realm.Fody]*' --exclude '[Realm.PlatformHelpers]*'
- name: Publish Coverage
id: publish-coveralls
uses: coverallsapp/github-action@ca2a9dd5a20b12fa9aa428e0a6418a60a38bab22
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
## vNext (TBD)

### Breaking Changes
* `AppConfiguration.LocalAppName` and `AppConfiguration.LocalAppVersion` have been deprecated and will be removed in a future version. They have never had an effect as the values supplied by the SDK was never sent to the server. (PR [#3387](https://github.com/realm/realm-dotnet/pull/3387))

### Enhancements
* None
* Added `App.BaseFilePath`, `App.BaseUri`, and `App.Id` properties that return the values supplied in `AppConfiguration`. (PR [#3385](https://github.com/realm/realm-dotnet/pull/3385))
* Added `AppConfiguration.UseAppCache` property that controls whether the `App` instance returned from `App.Create` should be cached or not. The general recommendation is to not set it (i.e. leave the default value of `true`), but it can be useful when writing unit tests. (Issue [#3382](https://github.com/realm/realm-dotnet/issues/3382)).

### Fixed
* Fixed a Unity Editor crash when the domain is reloaded while a `Realm.GetInstanceAsync` operation is in progress. (Issue [#3344](https://github.com/realm/realm-dotnet/issues/3344))
* Fixed the implementation `App.Equals` and `App.GetHashCode` to return correct results, particularly when the `App` instance is cached. (PR [#3385](https://github.com/realm/realm-dotnet/pull/3385))
* Fixed an issue where building for Android on Unity would fail with "Could not analyze the user's assembly. Object reference not set to an instance of an object". (Issue [#3380](https://github.com/realm/realm-dotnet/issues/3380))

### Compatibility
Expand Down
2 changes: 1 addition & 1 deletion Realm/Realm/Configurations/PartitionSyncConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private PartitionSyncConfiguration(User user, RealmValue partition, string? path
internal override IDisposable? OnBeforeRealmOpen(AsyncOpenTaskHandle handle)
{
var onProgress = OnProgress;
if (onProgress == null)
if (onProgress is null)
{
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion Realm/Realm/Configurations/SyncConfigurationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ internal virtual Native.SyncConfiguration CreateNativeSyncConfiguration()
{
SyncUserHandle = User.Handle,
session_stop_policy = SessionStopPolicy,
schema_mode = _schema == null ? SchemaMode.AdditiveDiscovered : SchemaMode.AdditiveExplicit,
schema_mode = _schema is null ? SchemaMode.AdditiveDiscovered : SchemaMode.AdditiveExplicit,
client_resync_mode = ClientResetHandler.ClientResetMode,
cancel_waits_on_nonfatal_error = CancelAsyncOperationsOnNonFatalErrors,
};
Expand Down
2 changes: 1 addition & 1 deletion Realm/Realm/DatabaseTypes/RealmValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ public Guid AsGuid()
private RealmInteger<T> AsRealmInteger<T>(T value)
where T : struct, IComparable<T>, IFormattable, IConvertible, IEquatable<T>
{
if (_objectHandle == null)
if (_objectHandle is null)
{
return new(value);
}
Expand Down
43 changes: 43 additions & 0 deletions Realm/Realm/Handles/AppHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ public static extern IntPtr get_user_for_testing(
[DllImport(InteropConfig.DLL_NAME, EntryPoint = "shared_app_clear_cached_apps", CallingConvention = CallingConvention.Cdecl)]
public static extern void clear_cached_apps(out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "shared_app_get_base_file_path", CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr get_base_file_path(AppHandle app, IntPtr buffer, IntPtr buffer_length, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "shared_app_get_base_uri", CallingConvention = CallingConvention.Cdecl)]
public static extern StringValue get_base_uri(AppHandle app, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "shared_app_get_id", CallingConvention = CallingConvention.Cdecl)]
public static extern StringValue get_id(AppHandle app, out NativeException ex);

[DllImport(InteropConfig.DLL_NAME, EntryPoint = "shared_app_is_same_instance", CallingConvention = CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.U1)]
public static extern bool is_same_instance(AppHandle lhs, AppHandle rhs, out NativeException ex);

public static class EmailPassword
{
[DllImport(InteropConfig.DLL_NAME, EntryPoint = "shared_app_email_register_user", CallingConvention = CallingConvention.Cdecl)]
Expand Down Expand Up @@ -349,6 +362,36 @@ public SyncUserHandle GetUserForTesting(string id, string refreshToken, string a
return new SyncUserHandle(result);
}

public string GetBaseFilePath()
{
return MarshalHelpers.GetString((IntPtr buffer, IntPtr length, out bool isNull, out NativeException ex) =>
{
isNull = false;
return NativeMethods.get_base_file_path(this, buffer, length, out ex);
})!;
}

public Uri GetBaseUri()
{
var value = NativeMethods.get_base_uri(this, out var ex);
ex.ThrowIfNecessary();
return new Uri(value!);
}

public string GetId()
{
var value = NativeMethods.get_id(this, out var ex);
ex.ThrowIfNecessary();
return value!;
}

public bool IsSameInstance(AppHandle other)
{
var result = NativeMethods.is_same_instance(this, other, out var ex);
ex.ThrowIfNecessary();
return result;
}

protected override void Unbind() => NativeMethods.destroy(handle);

[MonoPInvokeCallback(typeof(NativeMethods.UserCallback))]
Expand Down
29 changes: 28 additions & 1 deletion Realm/Realm/Handles/AsyncOpenTaskHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Concurrent;
using System.Runtime.InteropServices;

namespace Realms
{
internal class AsyncOpenTaskHandle : StandaloneHandle
{
private static ConcurrentDictionary<AsyncOpenTaskHandle, bool> _handles = new();

private static class NativeMethods
{
[DllImport(InteropConfig.DLL_NAME, EntryPoint = "realm_asyncopentask_destroy", CallingConvention = CallingConvention.Cdecl)]
Expand All @@ -40,6 +43,7 @@ private static class NativeMethods

public AsyncOpenTaskHandle(IntPtr handle) : base(handle)
{
_handles.TryAdd(this, true);
}

public void Cancel()
Expand All @@ -48,7 +52,30 @@ public void Cancel()
ex.ThrowIfNecessary();
}

protected override void Unbind() => NativeMethods.destroy(handle);
protected override void Unbind()
{
_handles.TryRemove(this, out _);

NativeMethods.destroy(handle);
}

/// <summary>
/// Cancels all in-flight async open tasks. This should only be used when the domain is being torn down.
/// The case this handles is:
/// 1. GetInstanceAsync.
/// 2. Domain Reload wipes all coordinator caches.
/// 3. AsyncOpen completes, calls back into managed (because s_can_call_managed is true again).
/// 4. Undefined behavior as the state from before the domain reload is no longer valid.
/// </summary>
/// <remarks>This fixes the issue reported in https://github.com/realm/realm-dotnet/issues/3344.</remarks>
public static void CancelInFlightTasks()
{
var keys = _handles.Keys;
foreach (var value in keys)
{
value.Cancel();
}
}

public ulong RegisterProgressNotifier(GCHandle managedHandle)
{
Expand Down
6 changes: 3 additions & 3 deletions Realm/Realm/Handles/SessionHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ private static IntPtr NotifyBeforeClientReset(IntPtr beforeFrozen, IntPtr manage
}
catch (Exception ex)
{
var handlerType = syncConfig == null ? "ClientResetHandler" : syncConfig.ClientResetHandler.GetType().Name;
var handlerType = syncConfig is null ? "ClientResetHandler" : syncConfig.ClientResetHandler.GetType().Name;
Logger.Default.Log(LogLevel.Error, $"An error has occurred while executing {handlerType}.OnBeforeReset during a client reset: {ex}");

var exHandle = GCHandle.Alloc(ex);
Expand Down Expand Up @@ -380,7 +380,7 @@ private static IntPtr NotifyAfterClientReset(IntPtr beforeFrozen, IntPtr after,
}
catch (Exception ex)
{
var handlerType = syncConfig == null ? "ClientResetHandler" : syncConfig.ClientResetHandler.GetType().Name;
var handlerType = syncConfig is null ? "ClientResetHandler" : syncConfig.ClientResetHandler.GetType().Name;
Logger.Default.Log(LogLevel.Error, $"An error has occurred while executing {handlerType}.OnAfterReset during a client reset: {ex}");

var exHandle = GCHandle.Alloc(ex);
Expand Down Expand Up @@ -429,7 +429,7 @@ private static void HandleSessionPropertyChangedCallback(IntPtr managedSessionHa
_ => throw new NotSupportedException($"Unexpected notifiable property value: {property}")
};
var session = (Session)GCHandle.FromIntPtr(managedSessionHandle).Target!;
if (session == null)
if (session is null)
{
// We're taking a weak handle to the session, so it's possible that it's been collected
return;
Expand Down
4 changes: 2 additions & 2 deletions Realm/Realm/Handles/SyncUserHandle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ public async Task<ApiKey> CreateApiKeyAsync(AppHandle app, string name)

var result = await tcs.Task;

Debug.Assert(result == null || result.Length <= 1, "The result of the fetch operation should be either null, or an array of 0 or 1 elements.");
Debug.Assert(result is null || result.Length <= 1, "The result of the fetch operation should be either null, or an array of 0 or 1 elements.");

return result == null || result.Length == 0 ? null : result.Single();
return result is null || result.Length == 0 ? null : result.Single();
}
finally
{
Expand Down
58 changes: 0 additions & 58 deletions Realm/Realm/Helpers/LinqHelper.cs

This file was deleted.

51 changes: 0 additions & 51 deletions Realm/Realm/Helpers/Observer.cs

This file was deleted.

29 changes: 3 additions & 26 deletions Realm/Realm/Native/AppConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,32 +63,6 @@ internal string BaseUrl
}
}

[MarshalAs(UnmanagedType.LPWStr)]
private string? local_app_name;
private IntPtr local_app_name_len;

internal string? LocalAppName
{
set
{
local_app_name = value;
local_app_name_len = value.IntPtrLength();
}
}

[MarshalAs(UnmanagedType.LPWStr)]
private string? local_app_version;
private IntPtr local_app_version_len;

internal string? LocalAppVersion
{
set
{
local_app_version = value;
local_app_version_len = value.IntPtrLength();
}
}

internal UInt64 default_request_timeout_ms;

private MetadataPersistenceMode metadata_persistence;
Expand Down Expand Up @@ -116,5 +90,8 @@ internal MetadataPersistenceMode? MetadataPersistence
internal UInt64 sync_pong_keep_alive_timeout_ms;

internal UInt64 sync_fast_reconnect_limit;

[MarshalAs(UnmanagedType.U1)]
internal bool use_cache;
}
}
Loading

0 comments on commit 727b46c

Please sign in to comment.