mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-05-10 17:49:49 -04:00
96d52c1a7b
## Description of Changes Companion to [Rename `Address` to `ConnectionId`](https://github.com/clockworklabs/SpacetimeDB/pull/2220). See that PR's description for more. Like all the SDKs, this PR does not change the SDK's behavior; the SDK still generates a connection ID locally and passes it through the HTTP API. This is not exposed to users, and can be changed in a follow-up. Also, use `/usr/bin/env bash` instead of `/bin/bash` in tools, for portability reasons. ## API - [x] This is an API breaking change to the SDK `Address` is renamed to `ConnectionId`. ## Requires SpacetimeDB PRs - https://github.com/clockworklabs/SpacetimeDB/pull/2220 - ## Testsuite *If you would like to run the your SDK changes in this PR against a specific SpacetimeDB branch, specify that here. This can be a branch name or a link to a PR.* SpacetimeDB branch name: phoebe/rename-address-to-connection-id ## Testing - [x] Pretty much just automated testing. - [x] @kazimuth will need to update and run Blackholio. --------- Co-authored-by: James Gilles <jameshgilles@gmail.com>
82 lines
2.4 KiB
C#
82 lines
2.4 KiB
C#
namespace SpacetimeDB.Tests;
|
|
|
|
using System.Runtime.CompilerServices;
|
|
using Argon;
|
|
using SpacetimeDB.Types;
|
|
|
|
static class VerifyInit
|
|
{
|
|
// A converter that scrubs identity to a stable string.
|
|
class IdentityConverter : WriteOnlyJsonConverter<Identity>
|
|
{
|
|
private static readonly List<Identity> seenIdentities = [];
|
|
|
|
public override void Write(VerifyJsonWriter writer, Identity value)
|
|
{
|
|
var index = seenIdentities.IndexOf(value);
|
|
if (index == -1)
|
|
{
|
|
index = seenIdentities.Count;
|
|
seenIdentities.Add(value);
|
|
}
|
|
|
|
writer.WriteValue($"Identity_{index + 1}");
|
|
}
|
|
}
|
|
|
|
class ConnectionIdConverter : WriteOnlyJsonConverter<ConnectionId>
|
|
{
|
|
public override void Write(VerifyJsonWriter writer, ConnectionId value)
|
|
{
|
|
// ConnectionIdes are GUIDs, which Verify scrubs automatically.
|
|
writer.WriteValue(value.ToString());
|
|
}
|
|
}
|
|
|
|
class NetworkRequestTrackerConverter : WriteOnlyJsonConverter<NetworkRequestTracker>
|
|
{
|
|
public override void Write(VerifyJsonWriter writer, NetworkRequestTracker value)
|
|
{
|
|
writer.WriteStartObject();
|
|
|
|
var sampleCount = value.GetSampleCount();
|
|
if (sampleCount > 0)
|
|
{
|
|
writer.WriteMember(value, sampleCount, nameof(sampleCount));
|
|
}
|
|
|
|
var requestsAwaitingResponse = value.GetRequestsAwaitingResponse();
|
|
if (requestsAwaitingResponse > 0)
|
|
{
|
|
writer.WriteMember(
|
|
value,
|
|
requestsAwaitingResponse,
|
|
nameof(requestsAwaitingResponse)
|
|
);
|
|
}
|
|
|
|
// We don't use the stats, since they are nondeterministic.
|
|
|
|
writer.WriteEndObject();
|
|
}
|
|
}
|
|
|
|
[ModuleInitializer]
|
|
public static void Init()
|
|
{
|
|
Environment.SetEnvironmentVariable("DiffEngine_TargetOnLeft", "true");
|
|
|
|
VerifierSettings.AddExtraSettings(settings =>
|
|
{
|
|
settings.Converters.AddRange(
|
|
[
|
|
new IdentityConverter(),
|
|
new ConnectionIdConverter(),
|
|
new NetworkRequestTrackerConverter()
|
|
]
|
|
);
|
|
settings.TypeNameHandling = TypeNameHandling.Auto;
|
|
});
|
|
}
|
|
}
|