@@ -357,7 +357,7 @@ func TestAggregations(t *testing.T) {
357
357
358
358
tracer := caretta .NewTracerWithObjs (& MockResolver {}, m , nil )
359
359
pastLinks := make (map [caretta.NetworkLink ]uint64 )
360
- pastConnections := [] caretta.ConnectionLink {}
360
+ pastConnections := make ( map [ caretta.TcpConnection ] uint64 )
361
361
var currentLinks map [caretta.NetworkLink ]uint64
362
362
for _ , connection := range test .connections {
363
363
m .Update (connection .connId , connection .throughput )
@@ -388,7 +388,7 @@ func TestDeletion_ActiveConnection_NotDeleted(t *testing.T) {
388
388
tracer := caretta .NewTracerWithObjs (& MockResolver {}, m , nil )
389
389
390
390
pastLinks := make (map [caretta.NetworkLink ]uint64 )
391
- pastConnections := [] caretta.ConnectionLink {}
391
+ pastConnections := make ( map [ caretta.TcpConnection ] uint64 )
392
392
393
393
// Act
394
394
m .Update (conn1 , throughput1 )
@@ -423,7 +423,7 @@ func TestDeletion_InactiveConnection_AddedToPastLinksAndRemovedFromMap(t *testin
423
423
tracer := caretta .NewTracerWithObjs (& MockResolver {}, m , nil )
424
424
425
425
pastLinks := make (map [caretta.NetworkLink ]uint64 )
426
- pastConnections := [] caretta.ConnectionLink {}
426
+ pastConnections := make ( map [ caretta.TcpConnection ] uint64 )
427
427
428
428
pastLinks , _ , _ , _ = tracer .TracesPollingIteration (pastLinks , pastConnections )
429
429
@@ -462,7 +462,7 @@ func TestDeletion_InactiveConnection_NewConnectionAfterDeletionUpdatesCorrectly(
462
462
tracer := caretta .NewTracerWithObjs (& MockResolver {}, m , nil )
463
463
464
464
pastLinks := make (map [caretta.NetworkLink ]uint64 )
465
- pastConnections := [] caretta.ConnectionLink {}
465
+ pastConnections := make ( map [ caretta.TcpConnection ] uint64 )
466
466
467
467
// update the throughput so the connection is inactive
468
468
throughput2 := inactiveThroughput
@@ -497,15 +497,19 @@ func TestConnectionState_Open(t *testing.T) {
497
497
tracer := caretta .NewTracerWithObjs (& MockResolver {}, m , nil )
498
498
499
499
pastLinks := make (map [caretta.NetworkLink ]uint64 )
500
- pastConnections := [] caretta.ConnectionLink {}
500
+ pastConnections := make ( map [ caretta.TcpConnection ] uint64 )
501
501
502
502
// Act
503
503
m .Update (conn1 , throughput1 )
504
504
_ , _ , _ , currentConnections := tracer .TracesPollingIteration (pastLinks , pastConnections )
505
505
506
506
// Assert
507
507
assert .Equal (1 , len (currentConnections ))
508
- assert .Equal ("open" , currentConnections [0 ].State )
508
+ // Get the first element of the map
509
+ for tcp := range currentConnections {
510
+ assert .Equal (uint32 (caretta .TcpConnectionOpenState ), tcp .State )
511
+ break
512
+ }
509
513
}
510
514
511
515
func TestConnectionState_Close (t * testing.T ) {
@@ -525,15 +529,18 @@ func TestConnectionState_Close(t *testing.T) {
525
529
tracer := caretta .NewTracerWithObjs (& MockResolver {}, m , nil )
526
530
527
531
pastLinks := make (map [caretta.NetworkLink ]uint64 )
528
- pastConnections := [] caretta.ConnectionLink {}
532
+ pastConnections := make ( map [ caretta.TcpConnection ] uint64 )
529
533
530
534
// Act
531
535
m .Update (conn1 , throughput1 )
532
536
_ , _ , _ , currentConnections := tracer .TracesPollingIteration (pastLinks , pastConnections )
533
537
534
538
// Assert
535
539
assert .Equal (1 , len (currentConnections ))
536
- assert .Equal ("close" , currentConnections [0 ].State )
540
+ for tcp := range currentConnections {
541
+ assert .Equal (uint32 (caretta .TcpConnectionClosedState ), tcp .State )
542
+ break
543
+ }
537
544
}
538
545
539
546
func TestConnectionState_Accept (t * testing.T ) {
@@ -553,15 +560,18 @@ func TestConnectionState_Accept(t *testing.T) {
553
560
tracer := caretta .NewTracerWithObjs (& MockResolver {}, m , nil )
554
561
555
562
pastLinks := make (map [caretta.NetworkLink ]uint64 )
556
- pastConnections := [] caretta.ConnectionLink {}
563
+ pastConnections := make ( map [ caretta.TcpConnection ] uint64 )
557
564
558
565
// Act
559
566
m .Update (conn1 , throughput1 )
560
567
_ , _ , _ , currentConnections := tracer .TracesPollingIteration (pastLinks , pastConnections )
561
568
562
569
// Assert
563
570
assert .Equal (1 , len (currentConnections ))
564
- assert .Equal ("accept" , currentConnections [0 ].State )
571
+ for tcp := range currentConnections {
572
+ assert .Equal (uint32 (caretta .TcpConnectionAcceptState ), tcp .State )
573
+ break
574
+ }
565
575
}
566
576
567
577
func TestConnectionState_UnknownRole (t * testing.T ) {
@@ -581,7 +591,7 @@ func TestConnectionState_UnknownRole(t *testing.T) {
581
591
tracer := caretta .NewTracerWithObjs (& MockResolver {}, m , nil )
582
592
583
593
pastLinks := make (map [caretta.NetworkLink ]uint64 )
584
- pastConnections := [] caretta.ConnectionLink {}
594
+ pastConnections := make ( map [ caretta.TcpConnection ] uint64 )
585
595
586
596
// Act
587
597
m .Update (conn1 , throughput1 )
@@ -590,60 +600,3 @@ func TestConnectionState_UnknownRole(t *testing.T) {
590
600
// Assert
591
601
assert .Equal (0 , len (currentConnections ))
592
602
}
593
-
594
- func TestConnectionRemoved_AfterClosed (t * testing.T ) {
595
- assert := assert .New (t )
596
-
597
- // Arrange mock map, initial connection
598
- m := NewMockConnectionsMap ()
599
-
600
- conn1 := caretta.ConnectionIdentifier {
601
- Id : 1 ,
602
- Pid : 1 ,
603
- Tuple : serverTuple ,
604
- Role : caretta .ServerConnectionRole ,
605
- }
606
- throughput1 := activeThroughput
607
-
608
- tracer := caretta .NewTracerWithObjs (& MockResolver {}, m , nil )
609
-
610
- pastLinks := make (map [caretta.NetworkLink ]uint64 )
611
- pastConnections := []caretta.ConnectionLink {}
612
-
613
- // Act
614
- m .Update (conn1 , throughput1 )
615
- _ , _ , pastConnections , currentConnections := tracer .TracesPollingIteration (pastLinks , pastConnections )
616
-
617
- // Assert
618
- assert .Equal (1 , len (currentConnections ))
619
- assert .Equal (0 , len (pastConnections ))
620
-
621
- // Act
622
- throughput2 := inactiveThroughput
623
- m .Update (conn1 , throughput2 )
624
- _ , _ , pastConnections , currentConnections = tracer .TracesPollingIteration (pastLinks , pastConnections )
625
-
626
- // Assert
627
- assert .Equal (1 , len (currentConnections ))
628
- assert .Equal (1 , len (pastConnections ))
629
-
630
- // Act
631
- throughput3 := inactiveThroughput
632
- m .Update (conn1 , throughput3 )
633
- _ , _ , pastConnections , currentConnections = tracer .TracesPollingIteration (pastLinks , pastConnections )
634
-
635
- // Assert
636
- assert .Equal (0 , len (currentConnections ))
637
- assert .Equal (0 , len (pastConnections ))
638
-
639
- // Attempt to re-add the connection
640
- throughput4 := activeThroughput
641
-
642
- // Act
643
- m .Update (conn1 , throughput4 )
644
- _ , _ , pastConnections , currentConnections = tracer .TracesPollingIteration (pastLinks , pastConnections )
645
-
646
- // Assert
647
- assert .Equal (1 , len (currentConnections ))
648
- assert .Equal (0 , len (pastConnections ))
649
- }
0 commit comments