Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Already has RdId assertion #470

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ abstract class RdPropertyBase<T>(val valueSerializer: ISerializer<T>) : RdReacti
return@advise

if (!optimizeNested && shouldIdentify) {
// We need to terminate the current lifetime to unbind the existing value before assigning a new value, especially in cases where we are reassigning it.
bindDefinition.get()?.terminate()

v.identifyPolymorphic(proto.identity, proto.identity.next(rdid))

val prevDefinition = bindDefinition.getAndSet(tryPreBindValue(lifetime, v, false))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,31 @@ class RdCollectionsTest : RdFrameworkTestBase() {
assertTrue(serverAsyncSet!!.contains(123))
}

@Test
fun reassignBindableValue() {
serverWire.autoFlush = false
clientWire.autoFlush = false

val serverTopLevelProperty = RdProperty<RdProperty<RdSet<Int>?>?>(null)
val clientTopLevelProperty = RdProperty<RdProperty<RdSet<Int>?>?>(null)

serverProtocol.bindStatic(serverTopLevelProperty, 1)
clientProtocol.bindStatic(clientTopLevelProperty, 1)

val clientNested1 = RdProperty<RdSet<Int>?>(null)
val clientNested2 = RdProperty<RdSet<Int>?>(null)
val clientSet = RdSet<Int>()
clientNested1.value = clientSet
clientNested2.value = clientSet

setSchedulerActive(SchedulerKind.Client) {
clientTopLevelProperty.value = clientNested1
pumpAllProtocols(true)
clientTopLevelProperty.value = clientNested2
pumpAllProtocols(true)
}
}


enum class SchedulerKind {
Client,
Expand Down
4 changes: 4 additions & 0 deletions rd-net/RdFramework/Impl/RdProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using JetBrains.Rd.Util;
using JetBrains.Serialization;
using JetBrains.Annotations;
using JetBrains.Util.Internal;

namespace JetBrains.Rd.Impl
{
Expand Down Expand Up @@ -144,6 +145,9 @@ protected override void Init(Lifetime lifetime, IProtocol proto, SerializationCt

if (!OptimizeNested && shouldIdentify)
{
// We need to terminate the current lifetime to unbind the existing value before assigning a new value, especially in cases where we are reassigning it.
Memory.VolatileRead(ref myBindDefinition)?.Terminate();

v.IdentifyPolymorphic(proto.Identities, proto.Identities.Next(RdId));

var prevDefinition = Interlocked.Exchange(ref myBindDefinition, TryPreBindValue(lifetime, v, false));
Expand Down
30 changes: 30 additions & 0 deletions rd-net/Test.RdFramework/RdCollectionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,36 @@ public void ChangeCollectionsTest()
Assert.AreEqual(BindState.NotBound,serverSet.BindState);
}

[Test]
public void ReassignBindableValue()
{
ClientWire.AutoTransmitMode = false;
ServerWire.AutoTransmitMode = false;

var serverTopLevelProperty = BindToServer(LifetimeDefinition.Lifetime,
NewRdProperty<RdProperty<RdSet<int>>>(), ourKey);
serverTopLevelProperty.ValueCanBeNull = true;
var clientTopLevelProperty = BindToClient(LifetimeDefinition.Lifetime,
NewRdProperty<RdProperty<RdSet<int>>>(), ourKey);
clientTopLevelProperty.ValueCanBeNull = true;

var clientNested1 = NewRdProperty<RdSet<int>>();
var clientNested2 = NewRdProperty<RdSet<int>>();
var clientSet = NewRdSet<int>();
clientNested1.Value = clientSet;

clientNested2.Value = clientSet;

SetSchedulerActive(SchedulerKind.Client, () =>
{
clientTopLevelProperty.Value = clientNested1;
PumpAllProtocols(true);
clientTopLevelProperty.Value = clientNested2;
PumpAllProtocols(true);
});

}

[Test]
public void PropertyTest()
{
Expand Down
Loading