Skip to content

Commit

Permalink
Fix Already has RdId assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
Iliya-usov committed Jan 30, 2024
1 parent 6c53ed0 commit 870e3bc
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
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

0 comments on commit 870e3bc

Please sign in to comment.