Update TestNodeHierarchy to include a fuller FTN setup for testing. Update testing.

This commit is contained in:
2024-11-25 13:46:16 +11:00
parent 810e620526
commit 9c828d65e6
9 changed files with 548 additions and 373 deletions

View File

@@ -109,7 +109,7 @@ class PacketTest extends TestCase
$f = $this->mail_file('mail/018A-1702393055-78754407.pkt');
foreach ($f as $packet) {
$pkt = Packet::process($packet,$x=$f->itemName(),$f->itemSize(),$this->do);
$pkt = Packet::process($packet,$x=$f->itemName(),$f->itemSize());
$this->assertInstanceOf(Packet\FSC39::class,$pkt);
$this->assertEquals('ABCDEFGH',$pkt->password);
@@ -136,7 +136,7 @@ class PacketTest extends TestCase
$f = $this->mail_file('mail/018A-1701955391-71c7a400.pkt');
foreach ($f as $packet) {
$pkt = Packet::process($packet,$x=$f->itemName(),$f->itemSize(),$this->do);
$pkt = Packet::process($packet,$x=$f->itemName(),$f->itemSize());
$this->assertInstanceOf(Packet\FSC39::class,$pkt);
$this->assertEquals('ABCDEFGH',$pkt->password);
@@ -163,7 +163,7 @@ class PacketTest extends TestCase
$f = $this->mail_file('mail/0B39-1701919239-65713a06.pkt');
foreach ($f as $packet) {
$pkt = Packet::process($packet,$x=$f->itemName(),$f->itemSize(),$this->do);
$pkt = Packet::process($packet,$x=$f->itemName(),$f->itemSize());
$this->assertInstanceOf(Packet\FSC48::class,$pkt);
$this->assertEquals('ABCDEFG#',$pkt->password);
@@ -246,7 +246,7 @@ class PacketTest extends TestCase
// This packet has an incorrect zone in the Origin
$f = $this->mail_file('mail/test_msgid_origin.pkt');
foreach ($f as $packet) {
$pkt = Packet::process($packet,$f->itemName(),$f->itemSize(),$this->do);
$pkt = Packet::process($packet,$f->itemName(),$f->itemSize());
$this->assertInstanceOf(Packet\FSC39::class,$pkt);
$this->assertEquals(1,$pkt->count());
@@ -278,7 +278,7 @@ class PacketTest extends TestCase
// This packet has a SOH<char>SOH sequence
$f = $this->mail_file('mail/test_binary_content-2.pkt');
foreach ($f as $packet) {
$pkt = Packet::process($packet,$f->itemName(),$f->itemSize(),$this->do);
$pkt = Packet::process($packet,$f->itemName(),$f->itemSize());
$this->assertEquals(1,$pkt->count());

View File

@@ -5,6 +5,7 @@ namespace Tests\Feature;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
use App\Models\{Address,Domain,Setup,System};
@@ -53,12 +54,17 @@ class RoutingTest extends TestCase
{
use DatabaseTransactions;
public const ZONE_ADDRS = 4061;
public const REGION_ADDRS = 811;
public const NET_ADDRS = 161;
public const HUB_ADDRS = 31;
public const NODE_ADDRS = 6;
private function zone(): Collection
{
//$this->seed(TestNodeHierarchy::class);
$do = Domain::where('name','a')->sole();
$zo = $do->zones->where('zone_id',100)->pop();
return $zo->addresses;
}
@@ -70,19 +76,31 @@ class RoutingTest extends TestCase
private function session_rc(): void
{
$ao = Address::findFTN('100:1/0@a');
$ao = Address::findFTN('101:1/0@a');
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
}
private function session_nc(): void
{
$ao = Address::findFTN('100:10/0@a');
$ao = Address::findFTN('101:10/0@a');
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
}
private function session_hub(): void
{
$ao = Address::findFTN('100:10/20@a');
$ao = Address::findFTN('101:10/100@a');
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
}
private function session_node(): void
{
$ao = Address::findFTN('101:10/101@a');
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
}
private function session_point(): void
{
$ao = Address::findFTN('101:10/101.1@a');
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
}
@@ -90,14 +108,14 @@ class RoutingTest extends TestCase
public function test_my_addresses()
{
$ftns = our_address();
$this->assertEquals(1,$ftns->count());
$this->assertEquals(6,$ftns->count());
}
// Get a list of active addresses in a Zone
public function test_zc_addresses()
public function test_zone_addresses()
{
$nodes = $this->zone();
$this->assertEquals(936,$nodes->count());
$this->assertEquals(self::ZONE_ADDRS,$nodes->count());
}
// Get a ZC with no session details, and make sure it has no parent nor children
@@ -107,230 +125,302 @@ class RoutingTest extends TestCase
$ao = Address::findFTN('101:0/0@a');
$this->assertEquals($ao->role_id,Address::NODE_ZC);
$this->assertCount(0,$ao->downstream());
$this->assertCount(0,$ao->downlinks());
$this->assertNull($ao->uplink());
}
// If we have a ZC, make sure we are routing to all it's children
public function test_zc_session_children()
{
$this->session_zc();
$ao = Address::findFTN('101:0/0@a');
$this->assertCount(935,$ao->downstream());
}
// An RC's parent should be the ZC, when we have session details with parent
public function test_zc_rc_node_parent()
{
// This is a ZC
$this->assertEquals($ao->role_name,'ZC');
$this->assertEquals(Address::NODE_ZC,$ao->role_id);
// Children
$this->assertCount(self::ZONE_ADDRS-1,$ao->children());
$this->assertCount(0,$ao->downlinks());
$this->session_zc();
$ao->refresh();
$ao = Address::findFTN('101:1/0@a');
$this->assertEquals($ao->role_id,Address::NODE_RC);
$this->assertEquals('101:0/0.0@a',$ao->uplink()->ftn);
// Children
$this->assertCount(self::ZONE_ADDRS,$ao->downlinks());
}
// ZC uplink should be null, and the parent should be itself
public function test_zc_parent()
{
$ao = Address::findFTN('101:0/0@a');
// This uplink should also be null
$this->assertNull($ao->uplink()?->ftn);
$this->session_zc();
$ao->refresh();
// This parent should also be null
$this->assertNull($ao->parent()?->ftn);
// This uplink should be itself
$this->assertEquals($ao->ftn,$ao->uplink()?->ftn);
}
// Get a list of active addresses in a Region
public function test_rc_session_children()
{
$this->session_rc();
$ao = Address::findFTN('101:1/0@a');
$ao = Address::findFTN('100:1/0@a');
$this->assertCount(185,$ao->downstream());
// This is a RC
$this->assertEquals($ao->role_name,'RC');
$this->assertEquals(Address::NODE_RC,$ao->role_id);
// Children
$this->assertCount(self::REGION_ADDRS-1,$ao->children());
$this->assertCount(0,$ao->downlinks());
$this->session_rc();
$ao->refresh();
// This is a ZC
$this->assertCount(self::REGION_ADDRS,$ao->downlinks());
}
// An RCs node still collects mail from the RC
public function test_rc_node_rc()
{
$this->session_rc();
// An RCs node should still be the RC
$ao = Address::findFTN('100:1/100@a');
$this->assertEquals($ao->role_id,Address::NODE_NN);
$this->assertEquals('100:1/0.0@a',$ao->uplink()->ftn);
}
// An NC collects mail for its children
public function test_rc_nc_node_rc()
{
$this->session_rc();
// A NCs parent should still be the RC
$ao = Address::findFTN('100:10/0@a');
$this->assertEquals($ao->role_id,Address::NODE_NC);
$this->assertEquals('100:1/0.0@a',$ao->uplink()->ftn);
}
// A Hub still collects mail from NC
public function test_rc_hub_node_nc()
{
$this->session_rc();
// A Hubs parent should still be the NC
$ao = Address::findFTN('100:10/20.0@a');
$this->assertEquals($ao->role_id,Address::NODE_HC);
$this->assertEquals('100:1/0.0@a',$ao->uplink()->ftn);
}
// A Hub's node still collects mail from Hub
public function test_rc_hub_node_hub()
{
$this->session_rc();
// A Hubs node should still be the Hub
$ao = Address::findFTN('100:10/22.0@a');
$this->assertEquals($ao->role_id,Address::NODE_NN);
$this->assertEquals('100:1/0.0@a',$ao->uplink()->ftn);
}
// An RCs parent is us even if we have session details for another RC
public function test_rc_parent()
{
$this->session_rc();
$ao = Address::findFTN('101:1/0@a');
$o = Address::findFTN('101:0/0@a');
$ao = Address::findFTN('100:2/0@a');
// This uplink should also be null
$this->assertNull($ao->uplink()?->ftn);
}
// If we also have session details for an NC, then there are less RC nodes
public function test_rc_nc_session_children()
{
$this->session_rc();
$this->session_nc();
$ao->refresh();
$ao = Address::findFTN('100:1/0@a');
$this->assertCount(185-36,$ao->downstream());
// This parent should also be null
$this->assertEquals($o->ftn,$ao->parent()?->ftn);
// This uplink should be itself
$this->assertEquals($ao->ftn,$ao->uplink()?->ftn);
}
// If we also have session details for an Hub, then there are less RC nodes
public function test_rc_hub_session_children()
public function test_zc_rc_nodes()
{
$this->session_zc();
$this->session_rc();
$ao = Address::findFTN('100:10/20@a');
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('101:0/0@a');
$this->assertCount(self::ZONE_ADDRS-self::REGION_ADDRS,$ao->downlinks());
$ao = Address::findFTN('100:1/0@a');
$this->assertCount(185,$ao->downstream());
$ao = Address::findFTN('100:10/22@a');
$this->assertEquals('100:10/20.0@a',$ao->uplink()->ftn);
$ao = Address::findFTN('101:1/0@a');
$this->assertCount(self::REGION_ADDRS,$ao->downlinks());
}
// If we also have session details for an Hub, then there are less RC nodes
public function test_rc_hub_session_child()
{
$this->session_hub();
$ao = Address::findFTN('100:10/22@a');
$this->assertEquals('100:10/20.0@a',$ao->uplink()->ftn);
}
// When we have an RC with session details, we route to all its children
public function test_nc_session_children()
{
$this->session_nc();
$ao = Address::findFTN('101:10/0@a');
$ao = Address::findFTN('100:10/0@a');
$this->assertCount(35,$ao->downstream());
// This is a NC
$this->assertEquals($ao->role_name,'NC');
$this->assertEquals(Address::NODE_NC,$ao->role_id);
// Children
$this->assertCount(self::NET_ADDRS-1,$ao->children());
$this->assertCount(0,$ao->downlinks());
$this->session_nc();
$ao->refresh();
// This is a NC
$this->assertCount(self::NET_ADDRS,$ao->downlinks());
}
public function test_complex_rc_nc_hc()
public function test_nc_parent()
{
$this->session_rc();
$this->session_nc();
$this->session_hub();
$ao = Address::findFTN('101:10/0@a');
$o = Address::findFTN('101:1/0@a');
$ao = Address::findFTN('100:1/100.0@a');
$this->assertCount(0,$ao->downstream());
$this->assertEquals('100:1/0.0@a',$ao->uplink()->ftn);
// RC
$ao = Address::findFTN('100:1/0.0@a');
$this->assertCount(186-1-30-6,$ao->downstream());
$ao = Address::findFTN('100:11/0.0@a');
$this->assertEquals('100:1/0.0@a',$ao->uplink()->ftn);
// NC
$ao = Address::findFTN('100:10/0.0@a');
$this->assertCount(36-1-6,$ao->downstream());
$ao = Address::findFTN('100:10/10.0@a');
$this->assertEquals('100:10/0.0@a',$ao->uplink()->ftn);
// HC
$ao = Address::findFTN('100:10/20.0@a');
$this->assertCount(6-1,$ao->downstream());
$ao = Address::findFTN('100:10/22.0@a');
$this->assertEquals('100:10/20.0@a',$ao->uplink()->ftn);
}
public function test_complex_rc_nc_hc_us()
{
Cache::forget('so');
$setup = Setup::findOrFail(config('app.id'));
$ao = Address::findFTN('100:10/0.0@a');
$setup->system_id = $ao->system_id;
$setup->save();
$this->assertEquals('100:10/0.0@a',our_address($ao)?->ftn);
$this->session_rc();
//$this->session_nc();
$this->session_hub();
$ao = Address::findFTN('100:11/0.0');
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('100:1/100.0@a');
$this->assertCount(0,$ao->downstream());
$this->assertEquals('100:1/0.0@a',$ao->uplink()?->ftn);
// RC
$ao = Address::findFTN('100:1/0.0@a');
$this->assertCount(186-36-36-1,$ao->downstream());
$ao = Address::findFTN('100:11/0.0@a');
$this->assertEquals('100:11/0.0@a',$ao->uplink()->ftn);
// NC
$ao = Address::findFTN('100:10/0.0@a');
$this->assertCount(36-6-1,$ao->downstream());
$ao = Address::findFTN('100:10/10.0@a');
// This uplink should also be null
$this->assertNull($ao->uplink()?->ftn);
// HC
$ao = Address::findFTN('100:10/20.0@a');
$this->assertCount(6-1,$ao->downstream());
$this->session_nc();
$ao->refresh();
$ao = Address::findFTN('100:10/22.0@a');
$this->assertEquals('100:10/20.0@a',$ao->uplink()->ftn);
Cache::forget('so');
// This parent should also be null
$this->assertEquals($o->ftn,$ao->parent()?->ftn);
// This uplink should be itself
$this->assertEquals($ao->ftn,$ao->uplink()?->ftn);
}
// A points parent is the node, if we have traffic for a point and we have session details for the node
public function test_point_session_node()
public function test_zc_rc_nc_nodes()
{
//$this->session_hub();
$this->session_zc();
$this->session_rc();
$this->session_nc();
$so = new System;
$so->name = 'Point System';
$so->sysop = 'Point Sysop';
$so->location = 'Melbourne, AU';
$so->active = TRUE;
$so->save();
$ao = Address::findFTN('101:0/0@a');
$this->assertCount(self::ZONE_ADDRS-self::REGION_ADDRS,$ao->downlinks());
// Create a child
$ao = Address::createFTN('100:10/21.2@a',$so);
$ao = Address::findFTN('101:1/0@a');
$this->assertCount(self::REGION_ADDRS-self::NET_ADDRS,$ao->downlinks());
$ao = Address::findFTN('100:10/21.0@a');
$ao->system->sessions()->attach([$ao->zone_id=>['sespass'=>'ABCD']]);
$ao = Address::findFTN('101:10/0@a');
$this->assertCount(self::NET_ADDRS,$ao->downlinks());
}
$ao = Address::findFTN('100:10/21.2@a');
$this->assertEquals('100:10/21.0@a',$ao->uplink()?->ftn);
public function test_hub_session_children()
{
$ao = Address::findFTN('101:10/100@a');
$ao = Address::findFTN('100:10/21@a');
$this->assertCount(1,$ao->downstream());
// This is a HUB
$this->assertEquals($ao->role_name,'HUB');
$this->assertEquals(Address::NODE_HC,$ao->role_id);
// Children
$this->assertCount(self::HUB_ADDRS-1,$ao->children());
$this->assertCount(0,$ao->downlinks());
$this->session_hub();
$ao->refresh()->unsetRelations();
// This is a NC
$this->assertCount(self::HUB_ADDRS,$ao->downlinks());
}
public function test_hub_parent()
{
$ao = Address::findFTN('101:10/100@a');
$o = Address::findFTN('101:10/0@a');
// This uplink should also be null
$this->assertNull($ao->uplink()?->ftn);
$this->session_hub();
$ao->refresh();
// This parent should also be null
$this->assertEquals($o->ftn,$ao->parent()?->ftn);
// This uplink should be itself
$this->assertEquals($ao->ftn,$ao->uplink()?->ftn);
}
public function test_zc_rc_nc_hub_nodes()
{
$this->session_zc();
$this->session_rc();
$this->session_nc();
$this->session_hub();
$ao = Address::findFTN('101:0/0@a');
$this->assertCount(self::ZONE_ADDRS-self::REGION_ADDRS,$ao->downlinks());
$ao = Address::findFTN('101:1/0@a');
$this->assertCount(self::REGION_ADDRS-self::NET_ADDRS,$ao->downlinks());
$ao = Address::findFTN('101:10/0@a');
$this->assertCount(self::NET_ADDRS-self::HUB_ADDRS,$ao->downlinks());
$ao = Address::findFTN('101:10/100@a');
$this->assertCount(self::HUB_ADDRS,$ao->downlinks());
}
public function test_node_session_children()
{
$ao = Address::findFTN('101:10/101@a');
// This is a NC
$this->assertEquals($ao->role_name,'NODE');
$this->assertEquals(Address::NODE_NN,$ao->role_id);
// Children
$this->assertCount(self::NODE_ADDRS-1,$ao->children());
$this->assertCount(0,$ao->downlinks());
$this->session_node();
$ao->refresh();
// This is a NC
$this->assertCount(self::NODE_ADDRS,$ao->downlinks());
}
public function test_node_parent()
{
$ao = Address::findFTN('101:10/101@a');
$o = Address::findFTN('101:10/100@a');
// This uplink should also be null
$this->assertNull($ao->uplink()?->ftn);
$this->session_node();
$ao->refresh();
// This parent should also be null
$this->assertEquals($o->ftn,$ao->parent()?->ftn);
// This uplink should be itself
$this->assertEquals($ao->ftn,$ao->uplink()?->ftn);
}
public function test_zc_rc_nc_hub_node_nodes()
{
$this->session_zc();
$this->session_rc();
$this->session_nc();
$this->session_hub();
$this->session_node();
$ao = Address::findFTN('101:0/0@a');
$this->assertCount(self::ZONE_ADDRS-self::REGION_ADDRS,$ao->downlinks());
$ao = Address::findFTN('101:1/0@a');
$this->assertCount(self::REGION_ADDRS-self::NET_ADDRS,$ao->downlinks());
$ao = Address::findFTN('101:10/0@a');
$this->assertCount(self::NET_ADDRS-self::HUB_ADDRS,$ao->downlinks());
$ao = Address::findFTN('101:10/100@a');
$this->assertCount(self::HUB_ADDRS-self::NODE_ADDRS,$ao->downlinks());
$ao = Address::findFTN('101:10/101@a');
$this->assertCount(self::NODE_ADDRS,$ao->downlinks());
}
public function test_point_session_children()
{
$ao = Address::findFTN('101:10/101.1@a');
// This is a NC
$this->assertEquals($ao->role_name,'POINT');
$this->assertEquals(Address::NODE_POINT,$ao->role_id);
// Children
$this->assertCount(0,$ao->children());
$this->assertCount(0,$ao->downlinks());
$this->session_point();
$ao->refresh();
// This is a NC
$this->assertCount(1,$ao->downlinks());
}
public function test_point_parent()
{
$ao = Address::findFTN('101:10/101.1@a');
$o = Address::findFTN('101:10/101@a');
// This uplink should also be null
$this->assertNull($ao->uplink()?->ftn);
$this->session_point();
$ao->refresh();
// This parent should also be null
$this->assertEquals($o->ftn,$ao->parent()?->ftn);
// This uplink should be itself
$this->assertEquals($ao->ftn,$ao->uplink()?->ftn);
}
}

View File

@@ -131,7 +131,7 @@ class TicProcessingTest extends TestCase
$file->refresh();
$this->assertEquals('100:1/0',$file->fftn->ftn3d);
$this->assertEquals('100:10/11',$file->origin->ftn3d);
$this->assertCount(12,$file->seenby);
$this->assertCount(7,$file->seenby);
$this->assertCount(4,$file->path);
}
}