update test

This commit is contained in:
mischa 2024-09-30 13:32:38 +02:00
parent 2d2c59e8a1
commit a06d639219

View File

@ -359,27 +359,31 @@ public void SerializeServer_OwnerMode_ClientToServer()
Assert.That(observersWriterUnreliableDelta.Position, Is.EqualTo(0)); Assert.That(observersWriterUnreliableDelta.Position, Is.EqualTo(0));
} }
// TODO this started failing after we moved SyncVarTest1NetworkBehaviour
// into it's own asmdef.
// server should still broadcast ClientToServer components to everyone // server should still broadcast ClientToServer components to everyone
// except the owner. // except the owner.
[Test] [Test]
public void SerializeServer_ObserversMode_ClientToServer() public void SerializeServer_ObserversMode_ClientToServer()
{ {
CreateNetworked(out GameObject _, out NetworkIdentity identity, CreateNetworked(out GameObject _, out NetworkIdentity identity,
out SyncVarTest1NetworkBehaviour comp); out SyncVarTest1NetworkBehaviour comp1,
out SyncVarTest2NetworkBehaviour comp2);
// one Reliable, one Unreliable component
comp1.syncMethod = SyncMethod.Reliable;
comp2.syncMethod = SyncMethod.Unreliable;
// pretend to be owned // pretend to be owned
identity.isOwned = true; identity.isOwned = true;
comp.syncMode = SyncMode.Observers; comp1.syncMode = comp2.syncMode = SyncMode.Observers;
comp.syncInterval = 0; comp1.syncInterval = comp2.syncInterval = 0;
// set to CLIENT with some unique values // set to CLIENT with some unique values
// and set connection to server to pretend we are the owner. // and set connection to server to pretend we are the owner.
comp.syncDirection = SyncDirection.ClientToServer; comp1.syncDirection = comp2.syncDirection = SyncDirection.ClientToServer;
comp.SetValue(11); // modify with helper function to avoid #3525 comp1.SetValue(11); // modify with helper function to avoid #3525
comp2.SetValue("22"); // modify with helper function to avoid #3525
// initial: should write something for owner and observers // initial: should still write for owner AND observers
identity.SerializeServer_Spawn(ownerWriterReliable, observersWriterReliable); identity.SerializeServer_Spawn(ownerWriterReliable, observersWriterReliable);
Debug.Log("initial ownerWriter: " + ownerWriterReliable); Debug.Log("initial ownerWriter: " + ownerWriterReliable);
Debug.Log("initial observerWriter: " + observersWriterReliable); Debug.Log("initial observerWriter: " + observersWriterReliable);
@ -387,7 +391,8 @@ public void SerializeServer_ObserversMode_ClientToServer()
Assert.That(observersWriterReliable.Position, Is.GreaterThan(0)); Assert.That(observersWriterReliable.Position, Is.GreaterThan(0));
// delta: should only write for observers // delta: should only write for observers
comp.SetValue(22); // modify with helper function to avoid #3525 comp1.SetValue(33); // modify with helper function to avoid #3525
comp2.SetValue("44"); // modify with helper function to avoid #3525
ownerWriterReliable.Position = 0; ownerWriterReliable.Position = 0;
observersWriterReliable.Position = 0; observersWriterReliable.Position = 0;
identity.SerializeServer_Broadcast( identity.SerializeServer_Broadcast(
@ -397,8 +402,15 @@ public void SerializeServer_ObserversMode_ClientToServer()
false); false);
Debug.Log("delta ownerWriter: " + ownerWriterReliable); Debug.Log("delta ownerWriter: " + ownerWriterReliable);
Debug.Log("delta observersWriter: " + observersWriterReliable); Debug.Log("delta observersWriter: " + observersWriterReliable);
Assert.That(ownerWriterReliable.Position, Is.EqualTo(0)); Assert.That(ownerWriterReliable.Position, Is.EqualTo(0));
Assert.That(observersWriterReliable.Position, Is.GreaterThan(0)); Assert.That(observersWriterReliable.Position, Is.GreaterThan(0));
Assert.That(ownerWriterUnreliableBaseline.Position, Is.EqualTo(0));
Assert.That(observersWriterUnreliableBaseline.Position, Is.GreaterThan(0));
Assert.That(ownerWriterUnreliableDelta.Position, Is.EqualTo(0));
Assert.That(observersWriterUnreliableDelta.Position, Is.GreaterThan(0));
} }
} }
} }