From e8fd09aad81575d99cb87270073e467369efa9c9 Mon Sep 17 00:00:00 2001 From: Fate-JH Date: Sun, 19 Jan 2020 21:32:14 -0500 Subject: [PATCH] Test fix (#332) * fix AvatarService tests * updated README section in regards to PSCrypto * better wording, imho * modifying the construction of Building entities so to properly register them with the zone GUID system * fixed tests --- README.md | 5 ++-- .../serverobject/structures/Building.scala | 25 ++++++++++------- .../net/psforever/objects/zones/Zone.scala | 7 ++++- .../test/scala/objects/ResourceSiloTest.scala | 4 +++ .../src/main/scala/WorldSessionActor.scala | 4 +-- .../actor/service/AvatarServiceTest.scala | 28 ------------------- 6 files changed, 29 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index c6e9d28a..f0ac800a 100644 --- a/README.md +++ b/README.md @@ -54,10 +54,9 @@ This will clone the repository and SBT will compile and run the login server ([m With a SBT console you can run tests (and you should) using `sbt test`. ### Downloading PSCrypto -**The server requires binary builds of PSCrypto in order to run.** [Download the latest release](https://github.com/psforever/PSCrypto/releases/download/v1.1/pscrypto-lib-1.1.zip) and extract the the approprate dll for your operating system to the top level of your source directory (the root directory, not /pslogin/src/main/scala). SBT, IDEA, and Java will automatically find the required libraries when running the server. -If you are not comfortable with compiled binaries, you can [build the libraries yourself](https://github.com/psforever/PSCrypto). +**The server requires binary builds of PSCrypto in order to run.** [Download the latest release](https://github.com/psforever/PSCrypto/releases/download/v1.1/pscrypto-lib-1.1.zip) and extract the the approprate dll for your operating system. If you are not comfortable with compiled binaries, you can [build the libraries yourself](https://github.com/psforever/PSCrypto). -If you have any issues with PSCrypto being detected when trying to run the server try adding `-Djava.library.path=` (no path necessary) to your preferred IDE's build configuration, for example with IDEA: Run -> Edit Configuration -> VM Options +SBT, IDEA, and Java will automatically find the required libraries when running the server. The build expects to find the library in a subdirectory of the root directory called /pscrypto-lib/. Historically, we have recommended placing it directly into the root directory and that has worked as well. If you still have issues with PSCrypto being detected, try adding `-Djava.library.path=` (no path necessary) to your preferred IDE's build configuration with the library in the root directory. For example, with IDEA: Run -> Edit Configuration -> (select the configuration) -> Uncheck "Use SBT shell" -> VM Parameters ## Setting up the Database The Login and World servers require PostgreSQL for persistence. diff --git a/common/src/main/scala/net/psforever/objects/serverobject/structures/Building.scala b/common/src/main/scala/net/psforever/objects/serverobject/structures/Building.scala index a9ed1704..e7c75084 100644 --- a/common/src/main/scala/net/psforever/objects/serverobject/structures/Building.scala +++ b/common/src/main/scala/net/psforever/objects/serverobject/structures/Building.scala @@ -13,13 +13,12 @@ import net.psforever.objects.serverobject.terminals.CaptureTerminal import net.psforever.objects.serverobject.tube.SpawnTube import net.psforever.objects.zones.Zone import net.psforever.packet.game._ -import net.psforever.types.{PlanetSideEmpire, PlanetSideGUID, Vector3} +import net.psforever.types.{PlanetSideEmpire, Vector3} import scalax.collection.{Graph, GraphEdge} import services.Service import services.local.{LocalAction, LocalServiceMessage} class Building(private val name: String, - private val building_guid : Int, private val map_id : Int, private val zone : Zone, private val buildingType : StructureType.Value, @@ -34,7 +33,12 @@ class Building(private val name: String, private var forceDomeActive : Boolean = false super.Zone_=(zone) - GUID = PlanetSideGUID(building_guid) + /** + * An overloaded constructor used for phasing out the need to define the building_guid parameter + */ + def this(name: String, building_guid : Int, map_id : Int, zone : Zone, buildingType : StructureType.Value, buildingDefinition : ObjectDefinition) = { + this(name, map_id, zone, buildingType, buildingDefinition) + } override def toString = name @@ -45,7 +49,7 @@ class Building(private val name: String, def IsCapitol : Boolean = capitols.contains(name) def IsSubCapitol : Boolean = { Neighbours match { - case Some(buildings: Set[Building]) => !buildings.filter(x => capitols.contains(x.name)).isEmpty + case Some(buildings: Set[Building]) => buildings.exists(x => capitols.contains(x.name)) case None => false } } @@ -270,18 +274,19 @@ class Building(private val name: String, } object Building { - final val NoBuilding : Building = new Building(name = "", building_guid = 0, map_id = 0, Zone.Nowhere, StructureType.Platform, GlobalDefinitions.building) { + final val NoBuilding : Building = new Building(name = "", map_id = 0, Zone.Nowhere, StructureType.Platform, GlobalDefinitions.building) { override def Faction_=(faction : PlanetSideEmpire.Value) : PlanetSideEmpire.Value = PlanetSideEmpire.NEUTRAL override def Amenities_=(obj : Amenity) : List[Amenity] = Nil + GUID = net.psforever.types.PlanetSideGUID(0) } def apply(name : String, guid : Int, map_id : Int, zone : Zone, buildingType : StructureType.Value) : Building = { - new Building(name, guid, map_id, zone, buildingType, GlobalDefinitions.building) + new Building(name, map_id, zone, buildingType, GlobalDefinitions.building) } def Structure(buildingType : StructureType.Value, location : Vector3, definition: ObjectDefinition)(name : String, guid : Int, map_id : Int, zone : Zone, context : ActorContext) : Building = { import akka.actor.Props - val obj = new Building(name, guid, map_id, zone, buildingType, definition) + val obj = new Building(name, map_id, zone, buildingType, definition) obj.Position = location obj.Actor = context.actorOf(Props(classOf[BuildingControl], obj), s"$map_id-$buildingType-building") obj @@ -290,7 +295,7 @@ object Building { def Structure(buildingType : StructureType.Value, location : Vector3)(name : String, guid : Int, map_id : Int, zone : Zone, context : ActorContext) : Building = { import akka.actor.Props - val obj = new Building(name, guid, map_id, zone, buildingType, GlobalDefinitions.building) + val obj = new Building(name, map_id, zone, buildingType, GlobalDefinitions.building) obj.Position = location obj.Actor = context.actorOf(Props(classOf[BuildingControl], obj), s"$map_id-$buildingType-building") obj @@ -298,14 +303,14 @@ object Building { def Structure(buildingType : StructureType.Value)(name : String, guid: Int, map_id : Int, zone : Zone, context : ActorContext) : Building = { import akka.actor.Props - val obj = new Building(name, guid, map_id, zone, buildingType, GlobalDefinitions.building) + val obj = new Building(name, map_id, zone, buildingType, GlobalDefinitions.building) obj.Actor = context.actorOf(Props(classOf[BuildingControl], obj), s"$map_id-$buildingType-building") obj } def Structure(buildingType : StructureType.Value, buildingDefinition : ObjectDefinition, location : Vector3)(name: String, guid: Int, id : Int, zone : Zone, context : ActorContext) : Building = { import akka.actor.Props - val obj = new Building(name, guid, id, zone, buildingType, buildingDefinition) + val obj = new Building(name, id, zone, buildingType, buildingDefinition) obj.Position = location obj.Actor = context.actorOf(Props(classOf[BuildingControl], obj), s"$id-$buildingType-building") obj diff --git a/common/src/main/scala/net/psforever/objects/zones/Zone.scala b/common/src/main/scala/net/psforever/objects/zones/Zone.scala index 29a58299..17642ec3 100644 --- a/common/src/main/scala/net/psforever/objects/zones/Zone.scala +++ b/common/src/main/scala/net/psforever/objects/zones/Zone.scala @@ -399,7 +399,12 @@ class Zone(private val zoneId : String, zoneMap : ZoneMap, zoneNumber : Int) { private def MakeBuildings(implicit context : ActorContext) : PairMap[Int, Building] = { val buildingList = Map.LocalBuildings - buildings = buildingList.map({case((name, building_guid, map_id), constructor) => building_guid -> constructor.Build(name, building_guid, map_id, this) }) + buildings = buildingList.map({ + case((name, building_guid, map_id), constructor) => + val building = constructor.Build(name, building_guid, map_id, this) + guid.register(building, building_guid) + building_guid -> building + }) buildings } diff --git a/common/src/test/scala/objects/ResourceSiloTest.scala b/common/src/test/scala/objects/ResourceSiloTest.scala index d8871aab..d1d7afdc 100644 --- a/common/src/test/scala/objects/ResourceSiloTest.scala +++ b/common/src/test/scala/objects/ResourceSiloTest.scala @@ -108,6 +108,7 @@ class ResourceSiloControlNtuWarningTest extends ActorTest { obj.Actor ! "startup" val zone = new Zone("nowhere", new ZoneMap("nowhere-map"), 0) obj.Owner = new Building("Building", building_guid = 6, map_id = 0, zone, StructureType.Building, GlobalDefinitions.building) + obj.Owner.GUID = PlanetSideGUID(6) val zoneEvents = TestProbe("zone-events") "Resource silo" should { @@ -139,6 +140,7 @@ class ResourceSiloControlUpdate1Test extends ActorTest { obj.Actor ! "startup" val zone = new Zone("nowhere", new ZoneMap("nowhere-map"), 0) val bldg = new Building("Building", building_guid = 6, map_id = 0, zone, StructureType.Building, GlobalDefinitions.building) + bldg.GUID = PlanetSideGUID(6) obj.Owner = bldg val zoneEvents = TestProbe("zone-events") val buildingEvents = TestProbe("building-events") @@ -204,6 +206,7 @@ class ResourceSiloControlUpdate2Test extends ActorTest { obj.Actor ! "startup" val zone = new Zone("nowhere", new ZoneMap("nowhere-map"), 0) val bldg = new Building("Building", building_guid = 6, map_id = 0, zone, StructureType.Building, GlobalDefinitions.building) + bldg.GUID = PlanetSideGUID(6) obj.Owner = bldg val zoneEvents = TestProbe("zone-events") val buildingEvents = TestProbe("building-events") @@ -261,6 +264,7 @@ class ResourceSiloControlNoUpdateTest extends ActorTest { obj.Actor ! "startup" val zone = new Zone("nowhere", new ZoneMap("nowhere-map"), 0) val bldg = new Building("Building", building_guid = 6, map_id = 0, zone, StructureType.Building, GlobalDefinitions.building) + bldg.GUID = PlanetSideGUID(6) obj.Owner = bldg val zoneEvents = TestProbe("zone-events") val buildingEvents = TestProbe("building-events") diff --git a/pslogin/src/main/scala/WorldSessionActor.scala b/pslogin/src/main/scala/WorldSessionActor.scala index 8b303f3a..7f8e0cb6 100644 --- a/pslogin/src/main/scala/WorldSessionActor.scala +++ b/pslogin/src/main/scala/WorldSessionActor.scala @@ -339,8 +339,8 @@ class WorldSessionActor extends Actor case out @ Some(obj) if obj.HasGUID => out case None if id.nonEmpty => - //delete stale entity reference from client - sendResponse(ObjectDeleteMessage(id.get, 0)) + //delete stale entity reference from client (deferred until later) + //sendResponse(ObjectDeleteMessage(id.get, 0)) None case _ => None diff --git a/pslogin/src/test/scala/actor/service/AvatarServiceTest.scala b/pslogin/src/test/scala/actor/service/AvatarServiceTest.scala index b381f625..42f5ae6d 100644 --- a/pslogin/src/test/scala/actor/service/AvatarServiceTest.scala +++ b/pslogin/src/test/scala/actor/service/AvatarServiceTest.scala @@ -5,7 +5,6 @@ import akka.actor.Props import akka.routing.RandomPool import actor.base.ActorTest import net.psforever.objects._ -import net.psforever.objects.ballistics.ResolvedProjectile import net.psforever.objects.guid.{GUIDTask, TaskResolver} import net.psforever.objects.zones.{Zone, ZoneActor, ZoneMap} import net.psforever.packet.game.objectcreate.{DroppedItemData, ObjectClass, ObjectCreateMessageParent, PlacementData} @@ -370,33 +369,6 @@ class ChangeFireStateStopTest extends ActorTest { } } -class DamageTest extends ActorTest { - val test_func_ref : Any=>ResolvedProjectile = { - def test_func(o : Any) : ResolvedProjectile = { null } - test_func - } - val player = Player(Avatar("TestCharacter", PlanetSideEmpire.VS, CharacterGender.Female, 1, CharacterVoice.Voice1)) - - "AvatarService" should { - "pass Damage" in { - ServiceManager.boot(system) - val service = system.actorOf(Props(classOf[AvatarService], Zone.Nowhere), AvatarServiceTest.TestName) - service ! Service.Join("test") - service ! AvatarServiceMessage("test", AvatarAction.Damage(PlanetSideGUID(10), player, test_func_ref)) - val msg = receiveOne(1 seconds) - assert(msg.isInstanceOf[AvatarServiceResponse]) - assert(msg.asInstanceOf[AvatarServiceResponse].toChannel == "/test/Avatar") - assert(msg.asInstanceOf[AvatarServiceResponse].avatar_guid == PlanetSideGUID(10)) - assert(msg.asInstanceOf[AvatarServiceResponse].replyMessage - .isInstanceOf[AvatarResponse.DamageResolution]) - assert(msg.asInstanceOf[AvatarServiceResponse].replyMessage - .asInstanceOf[AvatarResponse.DamageResolution].target == player) - assert(msg.asInstanceOf[AvatarServiceResponse].replyMessage - .asInstanceOf[AvatarResponse.DamageResolution].resolution_function == test_func_ref) - } - } -} - class WeaponDryFireTest extends ActorTest { "AvatarService" should { "pass WeaponDryFire" in {